Reputation: 33
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.
Upvotes: 3
Views: 9475
Reputation: 96
Try await test.step('',{});
this allows you to run some tests asynchronously while steps are executed in order within the test (note there is await
before each test.step
)
import { test,expect } from '@playwright/test';
let page;
test.beforeAll(async ({ browser }) => { page = await browser.newPage(); });
test.afterAll(async () => { await page.close(); });
test('Async test 1', async () => {
await page.goto('https://playwright.dev/community/welcome');
let heading = page.getByRole('heading', { name: 'Welcome' });
await expect(heading).toBeVisible();
});
test('Async test 2', async () => {
await page.goto('https://playwright.dev/docs/api/class-playwright');
let heading = page.getByRole('heading', { name: 'Playwright Library' });
await expect(heading).toBeVisible();
});
test('Steps are executed synchronously', async () => {
await test.step('Step 1', async () => {
await page.goto('https://playwright.dev/');
});
await test.step('Step 2', async () => {
await page.getByText('Get Started').click();
});
await test.step('Step 3', async () => {
let heading = page.getByRole('heading', { name: 'Installation' });
await expect(heading).toBeVisible();
});
});
See https://playwright.dev/docs/api/class-test#test-step
Upvotes: 0
Reputation: 190
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();
});
Upvotes: 5