PW Test Generator
Generates a spec that matches the specs already in src/tests/.
Read first
src/tests/e2e/e2e-checkout.spec.ts for the house style.
Contract
- Import
testandexpectfrom@fixtures/test-base, never from@playwright/test. That is what gives the test its page objects. - Take page objects from the fixture parameters. Never
new SomePage(page)in a spec. - Keep no locators in the spec. If a selector is missing, add it to the POM.
- Wrap each user-visible stage in
visualStep(page, 'title', async () => {...})from@utils/visualStep, which istest.stepplus an optional screenshot whenATTACH_SCREENSHOTS=true. - Add a scoped logger,
const log = createLogger('<spec-name>'), and give each spec its own scope sologs/combined.logstays readable. - Random data comes from
DataGenerator. Config-driven data comes from@config/env. - Tag the describe title. The suite uses
@P0,@Regression,@Checkout,@FixtureExample; the reporter surfaces them as filters.
Output shape
import { test, expect } from '@fixtures/test-base';
import { DataGenerator } from '@utils/DataGenerator';
import { credentials } from '@config/credentials';
import { createLogger } from '@utils/logger';
import { visualStep } from '@utils/visualStep';
const log = createLogger('cart.spec');
test.describe('@P0 @Regression @Cart Cart Feature', () => {
test.beforeEach(async ({ loginPage }) => {
await loginPage.open();
await loginPage.loginAs(credentials.standardUser, credentials.password);
});
test('removes an item from the cart', async ({ page, loginWithSelectedItem, cartPage }) => {
await visualStep(page, 'Open the cart', async () => {
await cartPage.open();
expect(await cartPage.rowCount()).toBe(1);
});
await visualStep(page, 'Remove the item', async () => {
await cartPage.remove(loginWithSelectedItem.itemId);
expect(await cartPage.rowCount()).toBe(0);
});
});
});
Do not
Duplicate a describe + test title that already exists. e2e-checkout.spec.ts and
e2e-checkout-env.spec.ts differ by title on purpose.
Verify
npx playwright test <the new spec>