playwrightplaywright-test

How to run a subset of tests sequentially using Playwright?


Say, I kick off all my 87 (random number here) tests and there are 5 (basically, "some") of them that test on the same page and all of them make changes to that same page... of course, the tests all use the same userid to authenticate. Nope, I cannot have several different userids here

The tests all run in parallel using playwright workers.

Is there a way to mark these "few tests", like to place them in a queue, such as they will run alone, not in parallel with each other ? Some keyword to add to the test ? Something like "alone" or "enqueue" ?

Or any other idea ? Thanks.


Solution

  • Serial Mode

    You can group those "few tests" together in a separate test file and annotate those 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.

    Run an subset of tests in serial mode in separate file like below:

    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();
    });