Back to All Questions
Question 77 of 100
Execution
Intermediate
How do you control test execution order?
The Answer
By default, tests within a file run sequentially in the order they are defined. Tests across files run in parallel. You can use `test.describe.serial()` to enforce serial execution within a group.
Deep Dive Explanation
Avoid relying on test ordering in general β it creates fragile, order-dependent suites. The exception is true workflows where each step depends on the previous (e.g., a checkout flow). In those cases, `test.describe.serial()` is the right tool, and Playwright will intelligently skip subsequent steps if an earlier one fails.
example.spec.ts
// Tests within this describe run in order, one at a time
test.describe.serial('E-commerce checkout flow', () => {
test('1. Add item to cart', async ({ page }) => { /* ... */ });
test('2. Proceed to checkout', async ({ page }) => { /* ... */ });
test('3. Enter payment details', async ({ page }) => { /* ... */ });
test('4. Confirm order', async ({ page }) => { /* ... */ });
});
// If test 2 fails, tests 3 and 4 are skipped automatically
// Run a specific test file only
// npx playwright test tests/checkout.spec.ts
// Run tests matching a grep pattern
// npx playwright test --grep="checkout"