问题描述
我正在使用 jest-playwright 库 (https://github.com/playwright-community/jest-playwright) 来执行端到端测试。在 jest.config.js 文件中,您可以设置一个选项来忽略 SSL 错误:
contextOptions: {
ignoreHTTPSErrors: true,}
这在用 jest 运行测试时工作正常。
现在,我希望剧作家在使用命令 npx playwright codegen example.com
单击网站元素时生成代码。但是,剧作家在打开网站时因为 SSL 错误而停止。
使用剧作家代码生成时是否可以选择忽略 SSL 错误?
解决方法
您可以运行 codegen with custom setup。只需在您的初始脚本中调用 page.pause()
,如果您运行 node my-initial-script.js
,它将打开代码生成控件。
带有 example code 的 browser.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 一样记录您的操作。