Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

241
Visualizações
Playwright browser is reopening every test statement

How to stop browser from reopening every time the the every test statement is done? I mean the code below is supposedly in 1 page continuing. Why is it the browser closes, open again and execute the second test. How to prevent that? Thanks


  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();
  }); 
})```
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

For the tests that share the same page and rely on the previous test results you need to wrap them in test.describe.serial and initialize the page in beforeAll, see this guide for more information.

Your example would look like this:

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();
  }); 
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda