我发现我可以使用 page.route
在 Playwright 中模拟响应
await page.route('https://dog.ceo/api/breeds/list/all', async route => {
const json = {
message: { 'test_breed': [] }
};
await route.fulfill({ json });
});
这太棒了,但是我可以对所有测试执行此操作,而无需在每个文件中调用它吗?
playwright.config
中是否有模拟配置或类似的配置?
最佳答案
找到答案here 。
目前似乎没有办法像 jest 或其他框架那样对所有测试进行 beforeEach
。该问题仍然存在,因此我们只能希望......
此时建议在每个文件上都有 beforeEach :
import { sharedBeforeEachFunction } from './hooks.mjs'
test.beforeEach(sharedBeforeEachFunction);
test('Login Sanity Test @smoke', async ({ page }) => {
});
关于javascript - Playwright - beforeEach 用于套件中的所有文件,或对所有测试的模拟响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74839988/