【问题标题】:Ignore SSL errors with playwright code generation使用 playwright 代码生成忽略 SSL 错误
【发布时间】:2021-07-06 22:42:40
【问题描述】:

我正在使用 jest-playwright 库 (https://github.com/playwright-community/jest-playwright) 执行端到端测试。在 jest.config.js 文件中,您可以设置忽略 SSL 错误的选项:

contextOptions: {
   ignoreHTTPSErrors: true,
}

这在使用 jest 运行测试时效果很好。
现在,我希望剧作家在使用命令npx playwright codegen example.com 单击网站元素时生成代码。但是,剧作家在打开网站时因为 SSL 错误而停止。

使用 playwright 代码生成时是否有忽略 SSL 错误的选项?

【问题讨论】:

    标签: ssl jestjs code-generation end-to-end playwright


    【解决方案1】:

    您可以运行codegen with custom setup。只需在您的初始脚本中调用page.pause(),如果您运行node my-initial-script.js,它将打开代码生成控件。

    example codebrowser.newContext({ ignoreHTTPSErrors: true }) 看起来像这样:

    // my-initial-script.js
    const { chromium } = require('playwright');
    
    (async () => {
      // Make sure to run headed.
      const browser = await chromium.launch({ headless: false });
    
      // Setup context however you like.
      const context = await browser.newContext({ /* pass any options */ ignoreHTTPSErrors: true });
    
      // Pause the page, and start recording manually.
      const page = await context.newPage();
      await page.pause();
    })();
    

    然后您就可以毫无问题地访问https://expired.badssl.com/,并以与通常使用 codegen 相同的方式记录您的操作。

    【讨论】:

      【解决方案2】:

      playwright 的更新版本上,您可以运行:

      npx playwright codegen --ignore-https-errors https://example.com
      

      codegen 的其他选项可以在运行 npx playwright codegen --help 时找到。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-03-11
        • 2012-05-10
        • 2014-07-30
        • 1970-01-01
        • 2012-08-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多