Search code examples
playwright

Playwright: Running certain files parallel and others serial in


I've created a few tests for my project, some test need to be run async while others can run sync.

Currently the config file is set to run async.

I've set a test file which runs them in the correct order. I've imported all the tests that should run sync into a single file. And tried adding

test.describe.configure({ mode: 'parallel' })

This changes the whole test process to run in parallel.

I can't seem to find any documentation on how to only execute certain test async and other sync. Does anyone have experience with this?

The reason I need it to run async for certain files is to log in and authenticate before continuing, also certain actions affect the layout of the whole UI (even in a different browser) and will mess up other tests screenshots.


Solution

  • PW runs all test in parallel by default. But there are options to serialize tests per file. You cannot have both paralel and serial tests in one file.

    From the playwright docs about Serial Mode

    Serial mode

    You can annotate inter-dependent tests as serial. If one of the serial tests fails, all subsequent tests are skipped. All tests in a group are retried together.

    import { test, Page } from '@playwright/test';
    
    // Annotate entire file as serial.
    test.describe.configure({ mode: 'serial' });
    
    let page: Page;
    
    test.beforeAll(async ({ browser }) => { page = await browser.newPage(); });
    test.afterAll(async () => { await page.close(); });
    
    test('runs first', async () => {
      await page.goto('https://playwright.dev/');
    });
    
    test('runs second', async () => {
      await page.getByText('Get Started').click();
    });