【问题标题】:How to use installed version of chrome in Playwright?如何在 Playwright 中使用已安装的 chrome 版本?
【发布时间】:2020-09-28 14:04:49
【问题描述】:

我想用铬代替铬。我可以通过提供可执行路径在 puppeteer 中实现相同的目标。在 playwright 中它不起作用,因为浏览器类型参数仅支持 'chromium, webkit, firefox'

const { chromium } = require('playwright');
(async () => {
    const browser = await chromium.launch({
        headless: false,
        executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
    });
    const context = await browser.newContext();
    const page = await context.newPage();
    await page.goto('http://whatsmyuseragent.org/');
    await page.screenshot({ path: `example-${browserType}.png` });
})();

【问题讨论】:

  • 虽然这段代码是正确的,但 Playwright 依赖于 Chromium 上游的新变化,因此我建议使用 Chrome Canary 而不是 Chrome stable。你可以从这里获得 Canary:google.com/chrome/canary 让我知道这是否有效!
  • 有效!问题是它应该始终是要安装在本地机器上的最新版本的 chrome/与 Playwright chromium 匹配的版本
  • +1 表示问题。我对如何使用特定版本的 chrome 进行测试有同样的问题,即79/80。

标签: javascript node.js webautomation playwright


【解决方案1】:

您需要选择其中一种口味。但是一旦您选择浏览器类型 Chromium,您仍然可以将 executablePath 传递给 launch 函数。

【讨论】:

    【解决方案2】:

    在 1.19 中您可以使用 chrome。

    browser = playwright.chromium.launch(channel="chrome")
    

    或者您可以简单地将其放入您的剧本配置文件中,例如:

    ////
        use: {
            headless: true,
            viewport: { width: 1600, height: 1000},
            ignoreHTTPSErrors: true,
            trace: 'on',
            screenshot: 'on',
            channel: "chrome",
            video: 'on'
        },
        ////
    

    更多关于https://playwright.dev/python/docs/browsers

    【讨论】:

      猜你喜欢
      • 2011-06-21
      • 2021-03-24
      • 1970-01-01
      • 1970-01-01
      • 2022-12-03
      • 2021-11-16
      • 2020-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多