
QA and Auto Tests, Part 3: E2E Playwright Tests and Auto Tests in CI
🌐 Machine-translated from Russian. Show original
In this part:
Which scenarios to automate#
Only key user paths that cost money to break are: registration and login, order placement, payment, creation of the main document. The rest is done via API and unit tests.
First test#
npm init playwright@latest
import { test, expect } from "@playwright/test";
test("пользователь оформляет заказ", async ({ page }) => {
await page.goto("/");
await page.getByRole("link", { name: "Каталог" }).click();
await page.getByRole("button", { name: "В корзину" }).first().click();
await page.getByRole("link", { name: "Корзина" }).click();
await page.getByRole("button", { name: "Оформить заказ" }).click();
await expect(page.getByText("Заказ оформлен")).toBeVisible();
});
Locators#
- Search for elements as a user: by role and text (
getByRole,getByLabel,getByText). - For complex areas, negotiate stable attributes with the
data-testid. - Don't use long CSS/XPath chains from layout — they break every time the design changes.
Flaky tests#
Causes and solutions:
| Reason | Decision |
|---|---|
Fixed pauses sleep | Playwright and expect(...).toBeVisible() |
| Dependence on data from other tests | your data in each test |
| Animations and slow mesh | waiting for states rather than timing |
| External services | mocks for payments and SMS |
An unstable test is worse than an absent: the team stops trusting the red status. Fix or delete.
Tests in CI#
Add a step to the pipeline from the "Docker and CI/CD from scratch" series:
e2e:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 22, cache: npm }
- run: npm ci
- run: npx playwright install --with-deps chromium
- run: npx playwright test
- uses: actions/upload-artifact@v4
if: failure()
with: { name: playwright-report, path: playwright-report }
- The report with traces and screenshots is saved when a crash — it's immediately clear what went wrong.
- Merge to main — only for green tests.
Quality Metrics#
- the proportion of defects found before release;
- test run time (if it's an hour, they will stop running);
- number of unstable tests;
- defects returned after correction.
🎉 Series completed. Return to contents.
Comments · 0
No comments yet.Sign in to comment, rate and see all comments.