剧作家浏览器正在重新打开每个测试语句



如何阻止浏览器在每次测试语句完成时重新打开?我的意思是,下面的代码应该是在1页继续。为什么浏览器会关闭,然后重新打开并执行第二个测试。如何预防呢?由于


test('When user logs in', async ({page}) => {
const commonAction = new CommonAction();
await commonAction.gotoPage(page);
await expect(page).toHaveURL('https://uat.mercator.createit.dev/login');
await commonAction.login( page, janEmail, janPasswd );
});
test('Then user is in my account page', async ({page}) => {
const navigationAction = new NavigationAction();
await navigationAction.verifyAccountPage(page);  
});

test('When user goes to newsletter subscriptions', async ({page}) => {
const navigationAction = new NavigationAction();
await navigationAction.goToNewsSubscription(page);  
});
test('Then user is in Newsletter subscription page', async ({page}) => {
const navigationAction = new NavigationAction();
await navigationAction.verifyNewsletterPage(page);  
});
test('When user updates subscription', async ({page}) => {
const newsletterAction = new NewsletterAction();
newsletterAction.subscribe(page);
});
test('Then user is redirected to My Account page after subscription updates', async ({page}) => {
const navigationAction = new NavigationAction();
await navigationAction.verifyAccountPage();
}); 
})```

对于共享同一页面并依赖于先前测试结果的测试,您需要将它们包装在test.describe.serial中并初始化beforeAll中的页面,请参阅本指南以获取更多信息。

你的例子看起来像这样:

const { test } = require('@playwright/test');
test.describe.serial('use the same page', () => {
/** @type {import('@playwright/test').Page} */
let page;
test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
});
test.afterAll(async () => {
await page.close();
});
test('When user logs in', async ({}) => {
const commonAction = new CommonAction();
await commonAction.gotoPage(page);
await expect(page).toHaveURL('https://uat.mercator.createit.dev/login');
await commonAction.login( page, janEmail, janPasswd );
});
test('Then user is in my account page', async ({}) => {
const navigationAction = new NavigationAction();
await navigationAction.verifyAccountPage(page);  
});

test('When user goes to newsletter subscriptions', async ({}) => {
const navigationAction = new NavigationAction();
await navigationAction.goToNewsSubscription(page);  
});
test('Then user is in Newsletter subscription page', async ({}) => {
const navigationAction = new NavigationAction();
await navigationAction.verifyNewsletterPage(page);  
});
test('When user updates subscription', async ({}) => {
const newsletterAction = new NewsletterAction();
newsletterAction.subscribe(page);
});
test('Then user is redirected to My Account page after subscription updates', async ({}) => {
const navigationAction = new NavigationAction();
await navigationAction.verifyAccountPage();
}); 
});

最新更新