gpt4 book ai didi

javascript - 使用 test.BeforeAll 转到页面 URL 以获取 playwright-test runner

转载 作者:行者123 更新时间:2023-12-05 00:36:27 28 4
gpt4 key购买 nike

test.beforeAll(async ({ page }) => {
// Go to the starting url before each test.
await page.goto('https://my.start.url/');
});
playwright-test runner 中是否有一种很好的方法来设置浏览器并导航到与页面对象相关的页面以运行该文件中的测试?
如果可能的话,我想避免为每个人做这个“test.beforeEach”。目前在 playwright-test 中不可能做到这一点,但在玩笑中是可能的。有任何想法吗?
Property 'page' does not exist on type 'PlaywrightWorkerArgs & PlaywrightWorkerOptions'.

最佳答案

如上所述(Leon),您可以创建自己的页面,但为了避免为每个测试创建一个新页面(Joaquin Casco 询问过它),只是不要将页面作为参数传递给您的测试函数。
我是说:

const { chromium } = require('playwright');
const { test } = require('@playwright/test');

test.beforeAll(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();

// Go to the starting url before each test.
await page.goto('https://my.start.url/');
});

// Will create a new page instance
test('Test with page as parameter', async ({ page }) => {})

// Does not create new page, so you can use the page from beforeAll hook (if you bring it into the scope)
test('Test without page as parameter', async () => {})

关于javascript - 使用 test.BeforeAll 转到页面 URL 以获取 playwright-test runner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68281091/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com