kin*_*oen 14 ssl code-generation end-to-end jestjs playwright
我正在使用 jest-playwright 库(https://github.com/playwright-community/jest-playwright)来执行端到端测试。在 jest.config.js 文件中,您可以设置一个选项来忽略 SSL 错误:
contextOptions: {
ignoreHTTPSErrors: true,
}
Run Code Online (Sandbox Code Playgroud)
当用 jest 运行测试时,这工作得很好。
现在,我希望剧作家在使用命令单击网站元素时生成代码npx playwright codegen example.com。然而,剧作家在打开网站时由于 SSL 错误而停止。
使用剧作家代码生成时是否可以选择忽略 SSL 错误?
rob*_*uck 13
另一种选择是配置test忽略 HTTPS 错误。
import { test } from "@playwright/test";
test.use({
ignoreHTTPSErrors: true,
});
test("test", async ({ page }) => {
await page.goto(
"https://example.com/"
);
});
Run Code Online (Sandbox Code Playgroud)
注意 -test.use...是运行时包含的内容npx playwright codegen --ignore-https-errors。
更新该设置也可以包含在您的playwright.config.ts文件中(请参阅文档)。
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
ignoreHTTPSErrors: true,
},
});
Run Code Online (Sandbox Code Playgroud)
the*_*ton 11
您可以使用自定义设置运行 codegen。只需调用page.pause()您的初始脚本,如果您运行,它将打开 codegen 控件node my-initial-script.js。
示例代码如下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();
})();
Run Code Online (Sandbox Code Playgroud)
然后您可以毫无问题地访问https://expired.badssl.com/并像通常使用 codegen 一样记录您的操作。
Rae*_*nha 10
在 的更新版本上playwright,您可以运行:
npx playwright codegen --ignore-https-errors https://example.com
Run Code Online (Sandbox Code Playgroud)
codegen可以找到正在运行的其他选项npx playwright codegen --help。
| 归档时间: |
|
| 查看次数: |
28466 次 |
| 最近记录: |