0
votes

Is it possible to run multiple tests in one browser window for playwright/test?

currently it will hit browser.close(); after every test even though they are testing on the same page which puts a lot of extra time on the tests.

test.beforeAll(async ({ browser }) => {
  const context = await browser.newContext();
  const page = await context.newPage();
  await page.goto('https://example.com');
});

test('nav test', async ({ page }) => {    
  const name = await page.innerText('.navbar__title');  
  expect(name).toBe('Playwright');
});

test('header test', async ({ page }) => {   
  const name = await page.innerText('.navbar__header');  
  expect(name).toBe('Playwright');
});
1

1 Answers

0
votes

Can you try wrapping the tests in a describe block? So they are treated as a group and not as an individual tests.

test.describe('two tests for same page', () => {
   test('nav test', async ({ page }) => {    
     const name = await page.innerText('.navbar__title');  
     expect(name).toBe('Playwright');
   });

   test('header test', async ({ page }) => {   
    const name = await page.innerText('.navbar__header');  
    expect(name).toBe('Playwright');
  });
});