Guest mode. You can read posts without signing up. Comments, ratings, job contacts and your own posts open after you sign up and accept the rules. What is Kommit →

Редакция КоммитРедакция портала
commit 0cab7fa · 19 days ago

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:

ReasonDecision
Fixed pauses sleepPlaywright and expect(...).toBeVisible()
Dependence on data from other testsyour data in each test
Animations and slow meshwaiting for states rather than timing
External servicesmocks 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 00 участников · 0 гостей🔒 Rate and discuss after signing up

Comments · 0

No comments yet.Sign in to comment, rate and see all comments.