¿Cómo evitar que el navegador se vuelva a abrir cada vez que se realiza cada declaración de prueba? Quiero decir que el código a continuación supuestamente está en 1 página continua. ¿Por qué se cierra el navegador, se abre de nuevo y se ejecuta la segunda prueba? ¿Cómo prevenir eso? Gracias
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(); }); })```Para las pruebas que comparten la misma página y se basan en los resultados de las pruebas anteriores, debe envolverlas en test.describe.serial e inicializar la página en beforeAll , consulte esta guía para obtener más información.
Su ejemplo se vería así:
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(); }); });