Search code examples
testingplaywright

How to run Playwright spec files in order


Is there anyway to specify in Playwright to run Spec files (not individual tests in a file) in an order. For example I want tests to be in this order:

  1. Login.spec.ts
  2. profile.spec.ts

Solution

  • It depends on whether you need them to run serially, with each test starting after the other finishes, or whether you want files to be started in a specific order, but still in parallel and thus don’t care about anything inside them going before or not (since each file will take a different amount of time, any execution, including individual tests themselves within the file, could happen at various times intermingled with other files).

    If the serial option, you’ll need to disable parallelism by limiting workers to 1 and either alphabetically name your files for automatic sorting or create a test list file that runs them in the order you specify, as described by Playwright on controlling test order.

    If the parallel option, just wanted to start in a certain order, I imagine the options from the serial approach would cause that behavior when workers is not limited to 1. But it would again only control file start order, not individual tests. Unless you have the fullyParallel option on, in which case I believe it would also individually start tests within a file in order before moving on. Or individual test start order could be theoretically controlled similarly if you have one test per file.

    So if you need each test to finish before starting the next, do the serial approach as described by that doc. If you only care about start order and not inside execution or finishing order, theoretically just use one of those approaches but with worker limit more than 1, and fullyParallel on for individual tests or off for ordering at just the file level.

    Hope that helps!