Automation QA Guidelines
Tài liệu tổng hợp Automation QA — overview, setup, coding standards, test design, CI/CD
AUTOMATION QA GUIDELINES
Project: Stack Trading
Date created: 2026-07-21
Version: v1.0
Owner: AQA
Language: Vietnamese / English
Tài liệu duy nhất cho Automation QA (AQA): phạm vi, setup framework, coding standards, thiết kế test và CI/CD reporting.
Mục lục
| Phần | Nội dung |
|---|---|
| I. Overview | Mục tiêu, phạm vi, vai trò, tech stack, nguyên tắc |
| II. Framework Setup | Cài đặt, env, chạy test, cấu trúc repo, troubleshooting |
| III. Coding Standards | Naming, Gherkin, steps, selectors, data, PR checklist |
| IV. Test Design | Priority, tags, scenario structure, DoD |
| V. CI/CD & Reporting | Pipeline, artifacts, flake policy, quality gates |
I. Overview
I.1. Mục tiêu
Automation QA đảm bảo:
- Các luồng nghiệp vụ quan trọng (checkout, evaluation, KYC, trading dashboard, payout…) được kiểm thử lặp lại ổn định trên môi trường test.
- Regression chạy nhanh sau mỗi build / sprint mà không phụ thuộc hoàn toàn vào manual QC.
- Framework, test data và report tách biệt khỏi dữ liệu nhạy cảm của dự án khác — chỉ dùng data/fixture thuộc Stack Trading (hoặc demo public khi POC).
I.2. Phạm vi
| In scope | Out of scope (ban đầu) |
|---|---|
| E2E UI smoke & regression (Playwright + Cucumber BDD) | Load / stress / security deep-dive (có thể bổ sung sau) |
| Critical happy path + lỗi validation chính | Exploratory testing thuần manual |
| Cross-browser: Chromium (default); Firefox/WebKit theo nhu cầu | Mobile native app automation |
| CI report (HTML Cucumber + JUnit) | Performance budget gate bắt buộc trên mọi PR (tuỳ chọn) |
I.3. Vai trò & trách nhiệm
| Role | Responsibility |
|---|---|
| AQA | Thiết kế scenario BDD, implement step/page object, maintain framework, triage flaky tests |
| Manual QC | Test case gốc, exploratory, UAT support; review coverage với AQA |
| BA | SRS / common rules — nguồn truth cho expected behavior |
| Dev | Stabilize selectors/data-test, fix defect từ automation |
I.4. Tech stack chuẩn
| Layer | Choice |
|---|---|
| Language | TypeScript |
| Browser automation | Playwright |
| BDD | Cucumber (@cucumber/cucumber) + Gherkin .feature |
| Assertion | @playwright/test expect |
| Reports | multiple-cucumber-html-reporter + JSON / JUnit |
| Repo framework | StackTrading-automation-test |
I.5. Luồng làm việc AQA
BA SRS / QC test case
│
▼
AQA viết Feature (Gherkin) ──► Review với QC (coverage)
│
▼
Implement steps + page objects + testData
│
▼
Chạy local (npm run test:chromium)
│
▼
Merge PR ──► CI chạy automation ──► Report HTML / JUnit
│
▼
Fail → bug ticket / flaky triageI.6. Nguyên tắc bắt buộc
- Không commit credentials thật, token, webhook, PII của trader/customer.
- Test data chỉ lấy từ
testData/của repo automation hoặc env CI secrets. - Mỗi scenario phải độc lập (không phụ thuộc thứ tự chạy).
- Prefer
data-test/ role / label ổn định — tránh XPath phụ thuộc CSS layout. - Fail phải có screenshot + log step rõ ràng để QC/Dev triage nhanh.
I.7. Liên kết liên quan
- BA Common Rules: Quy Tắc Nghiệp Vụ Chung
- Project context:
project_context.md(repo BA-QC) - Automation repo:
https://github.com/sotatek-dev/StackTrading-automation-test
II. Framework Setup
II.1. Prerequisites
| Requirement | Version tối thiểu |
|---|---|
| Node.js | 18+ |
| npm | 9+ |
| Git | Latest |
| OS | macOS / Linux / Windows |
Network access tới môi trường test Stack Trading (hoặc https://www.saucedemo.com/ khi chạy POC demo).
II.2. Clone & install
git clone git@github.com:sotatek-dev/StackTrading-automation-test.git
cd StackTrading-automation-test
npm install
npm run install:browsersHoặc one-shot:
npm run setup(setup = install deps + husky + Playwright browsers + lint/review checks)
II.3. Cấu hình môi trường
| Variable | Default | Mô tả |
|---|---|---|
BASE_URL | https://www.saucedemo.com/ (POC) | URL app under test |
BROWSER | chromium | Browser name cho report path |
CI | unset | true → headless + retry |
DEBUG | unset | true → log console/pageerror |
PERF_FAIL_ON_BUDGET | unset | true → fail khi vượt perf budget |
Ví dụ:
BASE_URL="https://staging.stacktrading.example/" npm run test:chromiumTest data tĩnh:
testData/
testSite.json # baseUrl fallback
users.json # demo / test accounts (không chứa secret production)
messages.json # expected UI textII.4. Chạy test
# Chromium (recommended default)
npm run test:chromium
# Firefox / WebKit
npm run test:firefox
npm run test:webkit
# All browsers
npm run test:all-browsersChạy trực tiếp Cucumber (debug):
BASE_URL="https://www.saucedemo.com/" BROWSER="chromium" \
npx cucumber-js --require-module ts-node/register \
--config config/cucumber.config.ts --profile chromiumII.5. Cấu trúc thư mục framework
StackTrading-automation-test/
├── features/ # Gherkin *.feature
│ └── SauceDemo/
├── stepDefinitions/ # Cucumber steps (*.steps.ts)
├── pageObjects/ # Page Object classes (optional)
├── testData/ # JSON fixtures
├── hooks/ # Before/After + performance hooks
├── support/ # World, globalSetup/Teardown
├── config/
│ ├── playwright.config.ts
│ ├── cucumber.config.ts
│ └── report/ # HTML reporter
├── performance/e2e/ # Web Vitals capture (optional)
├── reports/ # Generated (gitignored)
└── package.jsonII.6. Reports sau khi chạy
npm run report:open| Path | Nội dung |
|---|---|
reports/<browser>/html-report/ | Cucumber HTML |
reports/<browser>/cucumber-report.json | Raw JSON |
reports/<browser>/junit-report.xml | JUnit (CI) |
reports/<browser>/performance/ | Web Vitals summary |
reports/ và test-results/ không commit (đã có trong .gitignore).
II.7. Troubleshooting nhanh
| Triệu chứng | Hướng xử lý |
|---|---|
| Browser not found | npm run install:browsers |
| Timeout navigation | Kiểm tra BASE_URL, VPN, env staging |
| Undefined step | Step text không khớp stepDefinitions/*.ts |
| Flaky assertion | Tăng timeout có kiểm soát; ưu tiên data-test selector |
| CI fail WAF/bot | Chạy Chromium; check egress IP / allowlist |
III. Coding Standards
Áp dụng cho mọi PR trong repo
StackTrading-automation-test.
III.1. Naming
| Artifact | Convention | Example |
|---|---|---|
| Feature folder | PascalCase / domain name | features/Checkout/ |
| Feature file | kebab-case + .feature | checkout-smoke.feature |
| Step file | *.steps.ts | checkout.steps.ts |
| Page Object | *Page.ts (PascalCase class) | LoginPage.ts |
| Test data | camelCase .json | users.json |
| Scenario name | English, action-oriented | Successful login with standard user |
| Tag | lowercase @ | @smoke @regression @checkout |
III.2. Gherkin style
- Dùng Given / When / Then rõ ràng; Background chỉ cho setup chung thật sự.
- Tránh bước “And I wait 5 seconds” — chờ bằng assertion / Playwright auto-wait.
- Data biến động đưa vào
{string}hoặc Examples (Scenario Outline). - Không hardcode URL môi trường trong feature — lấy từ config /
testData.
Good:
Given I open the SauceDemo login page
When I login with username "standard_user" and password "secret_sauce"
Then I should be logged in and see the Products pageAvoid:
When I click the third blue button on the left
And I sleep for 10 secondsIII.3. Step definitions
- Một domain ≈ một file steps (không gom “god file”).
- Steps gọi Page Object hoặc locator tập trung; tránh copy-paste selector.
- Log action/verify qua
lib/log(logAction,logVerify,logInfo). - Không
console.lograw secrets (password → mask************).
When('I login with username {string} and password {string}', async function (username, password) {
await this.page.locator('#user-name').fill(username);
await this.page.locator('#password').fill(password);
await this.page.locator('#login-button').click();
});III.4. Selectors (ưu tiên)
| Priority | Pattern | Example |
|---|---|---|
| 1 | data-test / data-testid | [data-test="title"] |
| 2 | Role + accessible name | getByRole('button', { name: 'Login' }) |
| 3 | Label / placeholder | getByLabel('Username') |
| 4 | Stable id | #login-button |
| 5 | CSS/XPath layout-based | Chỉ khi không còn cách khác |
Tránh selector phụ thuộc index (nth-child(3)), class hash CSS-in-JS, text i18n chưa ổn định.
III.5. Test data
- Mọi account / message / URL fallback nằm trong
testData/*.json. - Load qua
dataHelper.loadTestData('users.json'). - Cấm commit: production password, OTP seed, Slack token, API key.
- Demo public (vd. SauceDemo
secret_sauce) được phép ghi rõ trong docs/feature.
III.6. Hooks & World
hooks/hooks.ts: init browser, screenshot on fail, cleanup.support/world.ts: chỉ giữ state dùng chung (page,config); không nhồi business logic.- Timeout step mặc định đủ lớn cho E2E; không tăng vô hạn để che flake.
III.7. PR checklist (AQA)
- Feature + steps + data nằm đúng folder
- Scenario độc lập, có tag
@smokenếu thuộc critical path - Không commit
reports/,node_modules/, secrets - Chạy pass local trên Chromium trước khi request review
- Selector ưu tiên
data-test/ role - Fail path có assertion message rõ
IV. Test Design
IV.1. Nguồn đầu vào
| Source | Dùng để |
|---|---|
BA SRS / UC (docs/BA/) | Expected behavior, business rules |
| Common rules | Validation chung (form, list, upload…) |
| Manual QC test cases | Ưu tiên automate case ổn định, high frequency |
CR / QnA (References/) | Cập nhật scenario khi requirement đổi |
Mỗi automated scenario nên map được tới UC-ID hoặc QC case ID (ghi trong comment Feature hoặc tag).
IV.2. Mức độ ưu tiên automate
| Priority | Tiêu chí | Ví dụ Stack Trading |
|---|---|---|
| P0 — Smoke | Broken = block release | Login, mở dashboard, mua gói evaluation (happy path) |
| P1 — Regression | Core journey mỗi sprint | Stage 2 evaluation rules, KYC submit, payout request |
| P2 — Extended | Edge / negative ổn định | Invalid payment, locked account message |
| P3 — Later | UI cosmetic, rare path | Theme toggle, empty-state copy |
Không automate trước: exploratory one-off, bug chưa ổn định UI, flow phụ thuộc CAPTCHA/OTP thật chưa có test hook.
IV.3. Tags chuẩn
| Tag | Ý nghĩa |
|---|---|
@smoke | Chạy mỗi PR / nightly tối thiểu |
@regression | Full suite theo schedule |
@wip | Đang viết — không fail CI |
@checkout @kyc @payout … | Theo domain WBS |
Ví dụ:
@smoke @login
Feature: Authentication smokeCI default nên chạy: @smoke hoặc full suite trừ @wip.
IV.4. Cấu trúc scenario tốt
- Arrange — mở page / login (Background nếu dùng lại nhiều lần).
- Act — một hành động chính rõ ràng.
- Assert — 1–3 verification đủ để chứng minh pass/fail.
Tránh scenario “siêu dài” trừ khi đó là journey test có chủ đích và tag riêng (@e2e-journey).
IV.5. Positive vs negative
| Type | Mục tiêu | Gợi ý |
|---|---|---|
| Happy path | Prove flow works | @smoke |
| Validation error | Message / state đúng rule BA | Assert text từ messages.json hoặc common rules |
| Authz / locked | Không vào được vùng cấm | Không lộ data user khác |
IV.6. Data strategy
| Strategy | Khi nào dùng |
|---|---|
| Static JSON | Message, product name, demo user |
| Dynamic unique | Email/username tạo mới mỗi run (timestamp suffix) |
| Env secrets (CI) | Password staging — không commit |
| Cleanup | API/UI teardown sau scenario nếu tạo data bẩn |
IV.7. Traceability matrix (mẫu)
| Scenario | UC / QC ID | Priority | Tag | Status |
|---|---|---|---|---|
| Successful login | UC_xx / TC-001 | P0 | @smoke | Automated |
| Locked out user | UC_xx / TC-014 | P2 | @regression | Automated |
| Checkout complete | UC_xx / TC-050 | P0 | @smoke @checkout | Planned |
IV.8. Definition of Done (scenario)
- Feature + steps + data merged
- Pass ổn định ≥ 3 lần local / CI
- Có tag priority phù hợp
- Map UC/QC ID
- Screenshot on fail hoạt động
- Manual QC confirm coverage đủ cho case đã chọn
V. CI/CD & Reporting
V.1. Mục tiêu CI
- Chạy smoke trên mỗi PR (nhanh, ổn định).
- Chạy regression theo lịch (nightly / end of sprint).
- Xuất artifact HTML + JUnit để QC/Dev xem mà không cần máy local.
V.2. Pipeline đề xuất
checkout → npm ci → playwright install →
cucumber (chromium, tags=@smoke) →
report:html → upload artifacts (reports/)| Job | Trigger | Tags | Browser |
|---|---|---|---|
aqa-smoke | Pull request | @smoke | Chromium |
aqa-regression | Schedule / main merge | @regression or all except @wip | Chromium (+ Firefox optional) |
Env trên CI:
env:
CI: "true"
BASE_URL: ${{ secrets.STAGING_BASE_URL }}
# credentials qua secrets, không hardcodeV.3. Scripts liên quan (repo automation)
| npm script | Vai trò |
|---|---|
test:chromium | Chạy suite + HTML report + perf report |
report:html | Generate multiple-cucumber-html-reporter |
report:open | Mở report local (tránh file:// block) |
ci:zip-report | Zip report để upload artifact |
perf:report | Web Vitals summary (không bắt buộc fail PR) |
V.4. Artifacts cần upload
| Artifact | Retention gợi ý |
|---|---|
reports/chromium/html-report/ | 14–30 ngày |
reports/chromium/junit-report.xml | 14 ngày (publish test summary) |
| Screenshots fail | Cùng retention với HTML report |
reports/*/performance/ | Optional |
Không upload node_modules hay binary app nội bộ.
V.5. Đọc report
- Mở HTML report → Features / Scenarios.
- Scenario FAILED → xem step đỏ + screenshot đính kèm.
- Phân loại:
- Product bug → ticket Dev, gắn UC/CR
- Test bug (selector/data) → AQA fix PR
- Env / flake → retry + quarantine
@wipnếu tái diễn
V.6. Flaky test policy
| Lần fail liên tiếp (cùng scenario) | Hành động |
|---|---|
| 1 | Re-run CI; ghi note |
| 2 | AQA investigate trong 1 ngày làm việc |
| 3 | Tag @wip hoặc skip có ticket; không để flake đỏ lâu trên main |
Nguyên tắc: sửa gốc (wait đúng, selector ổn) trước khi tăng retry vô hạn.
Retry Cucumber trên CI (khi CI=true) chỉ là lớp an toàn tạm thời.
V.7. Quality gates (đề xuất)
| Gate | PR | Nightly |
|---|---|---|
@smoke pass | Required | Required |
| Full regression | Optional | Required |
Perf budget (PERF_FAIL_ON_BUDGET) | Off | Optional On |
V.8. Bảo mật trên CI
- Secrets chỉ qua GitHub Actions / CI vault.
- Log không in password / token.
BASE_URLstaging — không trỏ production trừ khi có approval riêng.