@toolstackhq/create-qa-patterns 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +29 -10
  2. package/index.js +460 -1
  3. package/package.json +4 -3
  4. package/templates/playwright-template/.env.example +17 -0
  5. package/templates/playwright-template/.github/workflows/playwright-tests.yml +126 -0
  6. package/templates/playwright-template/README.md +234 -0
  7. package/templates/playwright-template/allurerc.mjs +10 -0
  8. package/templates/playwright-template/components/flash-message.ts +16 -0
  9. package/templates/playwright-template/config/environments.ts +41 -0
  10. package/templates/playwright-template/config/runtime-config.ts +53 -0
  11. package/templates/playwright-template/config/secret-manager.ts +28 -0
  12. package/templates/playwright-template/config/test-env.ts +9 -0
  13. package/templates/playwright-template/data/README.md +9 -0
  14. package/templates/playwright-template/data/factories/data-factory.ts +33 -0
  15. package/templates/playwright-template/data/generators/id-generator.ts +17 -0
  16. package/templates/playwright-template/data/generators/seeded-faker.ts +13 -0
  17. package/templates/playwright-template/docker/Dockerfile +21 -0
  18. package/templates/playwright-template/eslint.config.mjs +66 -0
  19. package/templates/playwright-template/fixtures/test-fixtures.ts +43 -0
  20. package/templates/playwright-template/lint/architecture-plugin.cjs +118 -0
  21. package/templates/playwright-template/package-lock.json +4724 -0
  22. package/templates/playwright-template/package.json +34 -0
  23. package/templates/playwright-template/pages/base-page.ts +24 -0
  24. package/templates/playwright-template/pages/login-page.ts +22 -0
  25. package/templates/playwright-template/pages/people-page.ts +39 -0
  26. package/templates/playwright-template/playwright.config.ts +46 -0
  27. package/templates/playwright-template/reporters/structured-reporter.ts +61 -0
  28. package/templates/playwright-template/scripts/generate-allure-report.mjs +57 -0
  29. package/templates/playwright-template/scripts/run-tests.sh +6 -0
  30. package/templates/playwright-template/tests/api-people.spec.ts +28 -0
  31. package/templates/playwright-template/tests/ui-journey.spec.ts +30 -0
  32. package/templates/playwright-template/tsconfig.json +31 -0
  33. package/templates/playwright-template/utils/logger.ts +55 -0
  34. package/templates/playwright-template/utils/test-step.ts +22 -0
@@ -0,0 +1,234 @@
1
+ # Playwright Template
2
+
3
+ This is a Playwright + TypeScript automation framework template for UI and API tests.
4
+
5
+ ## Table of contents
6
+
7
+ - [Feature set](#feature-set)
8
+ - [How it works](#how-it-works)
9
+ - [Project structure](#project-structure)
10
+ - [Quick start](#quick-start)
11
+ - [Environment and secrets](#environment-and-secrets)
12
+ - [Main commands](#main-commands)
13
+ - [Reports and artifacts](#reports-and-artifacts)
14
+ - [Add a new test](#add-a-new-test)
15
+ - [Extend the framework](#extend-the-framework)
16
+ - [CI and Docker](#ci-and-docker)
17
+
18
+ ## Feature set
19
+
20
+ - Playwright + TypeScript setup
21
+ - page object pattern with selectors kept out of tests
22
+ - shared fixtures for config, logging, data, and page objects
23
+ - generic data factory pattern with `DataFactory`
24
+ - multi-environment runtime config with `dev`, `staging`, and `prod`
25
+ - env-based secret resolution with a replaceable `SecretProvider`
26
+ - Playwright HTML report by default
27
+ - optional Allure single-file report
28
+ - traces, screenshots, videos, and structured logs for debugging
29
+ - ESLint rules that protect framework conventions
30
+ - GitHub Actions workflow and Docker support
31
+
32
+ ## How it works
33
+
34
+ - tests import shared fixtures from `fixtures/test-fixtures.ts`
35
+ - page objects in `pages/` own locators and user actions
36
+ - runtime config is loaded from `config/runtime-config.ts`
37
+ - application URLs and credentials are resolved from `TEST_ENV`
38
+ - reports and artifacts are written under `reports/`, `allure-results/`, and `test-results/`
39
+
40
+ ## Project structure
41
+
42
+ ```text
43
+ playwright-template
44
+ ├── tests
45
+ ├── pages
46
+ ├── components
47
+ ├── fixtures
48
+ ├── data
49
+ ├── config
50
+ ├── reporters
51
+ ├── utils
52
+ ├── lint
53
+ ├── scripts
54
+ ├── docker
55
+ ├── playwright.config.ts
56
+ └── package.json
57
+ ```
58
+
59
+ ## Quick start
60
+
61
+ 1. Install dependencies.
62
+
63
+ ```bash
64
+ npm install
65
+ ```
66
+
67
+ 2. Start the target apps you want the tests to hit.
68
+
69
+ For the local demo apps from the root repo:
70
+
71
+ ```bash
72
+ npm run dev:ui
73
+ ```
74
+
75
+ ```bash
76
+ npm run dev:api
77
+ ```
78
+
79
+ 3. Run tests.
80
+
81
+ ```bash
82
+ npm test
83
+ ```
84
+
85
+ Default local values:
86
+
87
+ - UI base URL: `http://127.0.0.1:3000`
88
+ - API base URL: `http://127.0.0.1:3001`
89
+ - username: `tester`
90
+ - password: `Password123!`
91
+
92
+ ## Environment and secrets
93
+
94
+ The template supports:
95
+
96
+ - `TEST_ENV=dev`
97
+ - `TEST_ENV=staging`
98
+ - `TEST_ENV=prod`
99
+
100
+ Runtime values are resolved in this order:
101
+
102
+ 1. environment-specific variables such as `DEV_UI_BASE_URL`
103
+ 2. generic variables such as `UI_BASE_URL`
104
+ 3. built-in defaults from `config/environments.ts`
105
+
106
+ The same pattern is used for credentials:
107
+
108
+ 1. `DEV_APP_USERNAME` or `DEV_APP_PASSWORD`
109
+ 2. `APP_USERNAME` or `APP_PASSWORD`
110
+ 3. built-in defaults for the selected environment
111
+
112
+ For local overrides, copy:
113
+
114
+ ```bash
115
+ .env.example
116
+ ```
117
+
118
+ to:
119
+
120
+ ```bash
121
+ .env
122
+ ```
123
+
124
+ The template loads:
125
+
126
+ - `.env`
127
+ - `.env.<TEST_ENV>`
128
+
129
+ Example:
130
+
131
+ ```bash
132
+ TEST_ENV=staging \
133
+ STAGING_UI_BASE_URL=https://staging-ui.example.internal \
134
+ STAGING_API_BASE_URL=https://staging-api.example.internal \
135
+ STAGING_APP_USERNAME=my-user \
136
+ STAGING_APP_PASSWORD=my-password \
137
+ npx playwright test
138
+ ```
139
+
140
+ If your team uses a real secret system later, replace the implementation behind `config/secret-manager.ts`.
141
+
142
+ ## Main commands
143
+
144
+ ```bash
145
+ npm test
146
+ npm run test:smoke
147
+ npm run test:regression
148
+ npm run test:critical
149
+ npm run lint
150
+ npm run typecheck
151
+ npm run report:playwright
152
+ npm run report:allure
153
+ ```
154
+
155
+ ## Reports and artifacts
156
+
157
+ Default Playwright HTML report:
158
+
159
+ ```bash
160
+ npm run report:playwright
161
+ ```
162
+
163
+ Optional Allure report:
164
+
165
+ ```bash
166
+ npm run report:allure
167
+ ```
168
+
169
+ Outputs:
170
+
171
+ - Playwright HTML: `reports/html`
172
+ - Allure single file: `reports/allure/index.html`
173
+ - structured event log: `reports/logs/playwright-events.jsonl`
174
+ - raw Allure results: `allure-results`
175
+ - traces, screenshots, videos: `test-results`
176
+
177
+ If you only want Playwright reporting, remove the `allure-playwright` reporter entry in `playwright.config.ts`.
178
+
179
+ ## Add a new test
180
+
181
+ Create tests under `tests/` and import the shared fixtures:
182
+
183
+ ```ts
184
+ import { expect, test } from "../fixtures/test-fixtures";
185
+ ```
186
+
187
+ Keep the pattern simple:
188
+
189
+ - create data with `dataFactory`
190
+ - interact through page objects
191
+ - assert in the test
192
+
193
+ Example shape:
194
+
195
+ ```ts
196
+ test("do something @smoke", async ({ dataFactory, loginPage }) => {
197
+ const person = dataFactory.person();
198
+ // use page objects here
199
+ });
200
+ ```
201
+
202
+ ## Extend the framework
203
+
204
+ Common extension points:
205
+
206
+ - add page objects under `pages/`
207
+ - add reusable UI pieces under `components/`
208
+ - extend fixtures in `fixtures/test-fixtures.ts`
209
+ - add more generic builders under `data/factories/`
210
+ - add stronger custom lint rules in `lint/architecture-plugin.cjs`
211
+ - add custom reporters under `reporters/`
212
+
213
+ Recommended rules:
214
+
215
+ - keep selectors in page objects
216
+ - keep assertions in test files
217
+ - prefer semantic selectors such as `getByRole`, `getByLabel`, and `data-testid`
218
+ - keep the data layer generic until the project really needs domain-specific factories
219
+
220
+ ## CI and Docker
221
+
222
+ The CI entrypoint is:
223
+
224
+ ```bash
225
+ scripts/run-tests.sh
226
+ ```
227
+
228
+ Docker support is included in:
229
+
230
+ ```bash
231
+ docker/Dockerfile
232
+ ```
233
+
234
+ The included GitHub Actions workflow installs dependencies, runs tests, and uploads artifacts. The Docker path is also validated in CI so the container setup does not drift from the normal runner path.
@@ -0,0 +1,10 @@
1
+ export default {
2
+ name: "qa-patterns Playwright Template",
3
+ plugins: {
4
+ awesome: {
5
+ options: {
6
+ singleFile: true
7
+ }
8
+ }
9
+ }
10
+ };
@@ -0,0 +1,16 @@
1
+ import type { Locator, Page } from "@playwright/test";
2
+
3
+ export class FlashMessage {
4
+ private readonly message: Locator;
5
+
6
+ constructor(page: Page) {
7
+ this.message = page.getByTestId("flash-message");
8
+ }
9
+
10
+ async getText(): Promise<string | null> {
11
+ if (!(await this.message.count())) {
12
+ return null;
13
+ }
14
+ return this.message.textContent();
15
+ }
16
+ }
@@ -0,0 +1,41 @@
1
+ import type { TestEnvironment } from "./test-env";
2
+
3
+ type EnvironmentDefaults = {
4
+ uiBaseUrl: string;
5
+ apiBaseUrl: string;
6
+ credentials: {
7
+ username: string;
8
+ password: string;
9
+ };
10
+ };
11
+
12
+ const DEFAULTS: Record<TestEnvironment, EnvironmentDefaults> = {
13
+ dev: {
14
+ uiBaseUrl: "http://127.0.0.1:3000",
15
+ apiBaseUrl: "http://127.0.0.1:3001",
16
+ credentials: {
17
+ username: "tester",
18
+ password: "Password123!"
19
+ }
20
+ },
21
+ staging: {
22
+ uiBaseUrl: "https://staging-ui.example.internal",
23
+ apiBaseUrl: "https://staging-api.example.internal",
24
+ credentials: {
25
+ username: "staging-user",
26
+ password: "replace-me"
27
+ }
28
+ },
29
+ prod: {
30
+ uiBaseUrl: "https://ui.example.internal",
31
+ apiBaseUrl: "https://api.example.internal",
32
+ credentials: {
33
+ username: "prod-user",
34
+ password: "replace-me"
35
+ }
36
+ }
37
+ };
38
+
39
+ export function getEnvironmentDefaults(testEnv: TestEnvironment): EnvironmentDefaults {
40
+ return DEFAULTS[testEnv];
41
+ }
@@ -0,0 +1,53 @@
1
+ import path from "node:path";
2
+
3
+ import dotenv from "dotenv";
4
+ import { z } from "zod";
5
+
6
+ import { getEnvironmentDefaults } from "./environments";
7
+ import { EnvSecretProvider, SecretManager } from "./secret-manager";
8
+ import { loadTestEnvironment } from "./test-env";
9
+
10
+ const environment = loadTestEnvironment();
11
+
12
+ dotenv.config({ path: path.resolve(process.cwd(), ".env") });
13
+ dotenv.config({ path: path.resolve(process.cwd(), `.env.${environment}`), override: true });
14
+
15
+ const runtimeConfigSchema = z.object({
16
+ testEnv: z.enum(["dev", "staging", "prod"]),
17
+ testRunId: z.string().min(1),
18
+ uiBaseUrl: z.string().url(),
19
+ apiBaseUrl: z.string().url(),
20
+ credentials: z.object({
21
+ username: z.string().min(1),
22
+ password: z.string().min(1)
23
+ })
24
+ });
25
+
26
+ export type RuntimeConfig = z.infer<typeof runtimeConfigSchema>;
27
+
28
+ export function loadRuntimeConfig(): RuntimeConfig {
29
+ const defaults = getEnvironmentDefaults(environment);
30
+ const secretManager = new SecretManager(new EnvSecretProvider());
31
+
32
+ const uiBaseUrl =
33
+ process.env[`${environment.toUpperCase()}_UI_BASE_URL`] ??
34
+ process.env.UI_BASE_URL ??
35
+ defaults.uiBaseUrl;
36
+ const apiBaseUrl =
37
+ process.env[`${environment.toUpperCase()}_API_BASE_URL`] ??
38
+ process.env.API_BASE_URL ??
39
+ defaults.apiBaseUrl;
40
+
41
+ return runtimeConfigSchema.parse({
42
+ testEnv: environment,
43
+ testRunId: process.env.TEST_RUN_ID ?? "local",
44
+ uiBaseUrl,
45
+ apiBaseUrl,
46
+ credentials: {
47
+ username:
48
+ secretManager.getOptionalSecret("APP_USERNAME", environment) ?? defaults.credentials.username,
49
+ password:
50
+ secretManager.getOptionalSecret("APP_PASSWORD", environment) ?? defaults.credentials.password
51
+ }
52
+ });
53
+ }
@@ -0,0 +1,28 @@
1
+ import type { TestEnvironment } from "./test-env";
2
+
3
+ export interface SecretProvider {
4
+ getSecret(key: string, testEnv: TestEnvironment): string | undefined;
5
+ }
6
+
7
+ export class EnvSecretProvider implements SecretProvider {
8
+ getSecret(key: string, testEnv: TestEnvironment): string | undefined {
9
+ const envPrefix = testEnv.toUpperCase();
10
+ return process.env[`${envPrefix}_${key}`] ?? process.env[key];
11
+ }
12
+ }
13
+
14
+ export class SecretManager {
15
+ constructor(private readonly provider: SecretProvider) {}
16
+
17
+ getRequiredSecret(key: string, testEnv: TestEnvironment): string {
18
+ const value = this.provider.getSecret(key, testEnv);
19
+ if (!value) {
20
+ throw new Error(`Missing secret "${key}" for TEST_ENV=${testEnv}`);
21
+ }
22
+ return value;
23
+ }
24
+
25
+ getOptionalSecret(key: string, testEnv: TestEnvironment): string | undefined {
26
+ return this.provider.getSecret(key, testEnv);
27
+ }
28
+ }
@@ -0,0 +1,9 @@
1
+ import { z } from "zod";
2
+
3
+ export const testEnvironmentSchema = z.enum(["dev", "staging", "prod"]);
4
+
5
+ export type TestEnvironment = z.infer<typeof testEnvironmentSchema>;
6
+
7
+ export function loadTestEnvironment(): TestEnvironment {
8
+ return testEnvironmentSchema.parse(process.env.TEST_ENV ?? "dev");
9
+ }
@@ -0,0 +1,9 @@
1
+ # Data Layer
2
+
3
+ Keep the starter data layer generic.
4
+
5
+ - Start with `DataFactory.person()` or similarly small builders.
6
+ - Add domain-specific factories only when the project actually needs them.
7
+ - Introduce stricter validation later only if your team actually needs it.
8
+
9
+ The template should feel approachable before it feels comprehensive.
@@ -0,0 +1,33 @@
1
+ import { createSeededFaker } from "../generators/seeded-faker";
2
+ import { IdGenerator } from "../generators/id-generator";
3
+
4
+ export type PersonRecord = {
5
+ personId: string;
6
+ name: string;
7
+ role: string;
8
+ email: string;
9
+ };
10
+
11
+ export class DataFactory {
12
+ private readonly idGenerator: IdGenerator;
13
+
14
+ constructor(private readonly testRunId: string) {
15
+ this.idGenerator = new IdGenerator(testRunId);
16
+ }
17
+
18
+ person(overrides?: Partial<PersonRecord>): PersonRecord {
19
+ const personId = overrides?.personId ?? this.idGenerator.next("person");
20
+ const seededFaker = createSeededFaker(`${this.testRunId}:${personId}`);
21
+ const firstName = seededFaker.person.firstName();
22
+ const lastName = seededFaker.person.lastName();
23
+ const name = `${firstName} ${lastName}`;
24
+
25
+ return {
26
+ personId,
27
+ name,
28
+ role: overrides?.role ?? seededFaker.person.jobTitle(),
29
+ email: overrides?.email ?? `${firstName}.${lastName}.${personId}@example.test`.toLowerCase(),
30
+ ...overrides
31
+ };
32
+ }
33
+ }
@@ -0,0 +1,17 @@
1
+ export class IdGenerator {
2
+ private readonly counters = new Map<string, number>();
3
+
4
+ constructor(private readonly runId: string) {}
5
+
6
+ next(prefix: string): string {
7
+ const counter = (this.counters.get(prefix) ?? 0) + 1;
8
+ this.counters.set(prefix, counter);
9
+ return `${prefix}-${this.runId}-${String(counter).padStart(4, "0")}`;
10
+ }
11
+
12
+ nextSequence(prefix: string): number {
13
+ const counter = (this.counters.get(prefix) ?? 0) + 1;
14
+ this.counters.set(prefix, counter);
15
+ return counter;
16
+ }
17
+ }
@@ -0,0 +1,13 @@
1
+ import { faker } from "@faker-js/faker";
2
+
3
+ function hashSeed(value: string): number {
4
+ return value.split("").reduce((seed, character) => {
5
+ return ((seed << 5) - seed + character.charCodeAt(0)) | 0;
6
+ }, 0);
7
+ }
8
+
9
+ export function createSeededFaker(seedInput: string) {
10
+ const instance = faker;
11
+ instance.seed(Math.abs(hashSeed(seedInput)));
12
+ return instance;
13
+ }
@@ -0,0 +1,21 @@
1
+ FROM node:20-bookworm-slim
2
+
3
+ WORKDIR /workspace
4
+
5
+ COPY package.json package-lock.json tsconfig.json playwright.config.ts eslint.config.mjs allurerc.mjs ./
6
+ COPY config ./config
7
+ COPY components ./components
8
+ COPY data ./data
9
+ COPY fixtures ./fixtures
10
+ COPY lint ./lint
11
+ COPY pages ./pages
12
+ COPY reporters ./reporters
13
+ COPY scripts ./scripts
14
+ COPY tests ./tests
15
+ COPY utils ./utils
16
+ COPY .env.example ./.env.example
17
+
18
+ RUN npm ci
19
+ RUN npx playwright install --with-deps chromium
20
+
21
+ CMD ["bash", "./scripts/run-tests.sh"]
@@ -0,0 +1,66 @@
1
+ import js from "@eslint/js";
2
+ import tseslint from "@typescript-eslint/eslint-plugin";
3
+ import tsParser from "@typescript-eslint/parser";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ import architecturePlugin from "./lint/architecture-plugin.cjs";
7
+
8
+ const configDirectory = fileURLToPath(new globalThis.URL(".", import.meta.url));
9
+
10
+ export default [
11
+ {
12
+ ignores: [
13
+ "node_modules/**",
14
+ "reports/**",
15
+ "allure-results/**",
16
+ "allure-report/**",
17
+ "test-results/**",
18
+ "playwright-report/**"
19
+ ]
20
+ },
21
+ js.configs.recommended,
22
+ {
23
+ files: ["**/*.ts"],
24
+ languageOptions: {
25
+ parser: tsParser,
26
+ parserOptions: {
27
+ project: "./tsconfig.json",
28
+ tsconfigRootDir: configDirectory
29
+ },
30
+ globals: {
31
+ console: "readonly",
32
+ process: "readonly",
33
+ URL: "readonly"
34
+ }
35
+ },
36
+ plugins: {
37
+ "@typescript-eslint": tseslint,
38
+ architecture: architecturePlugin
39
+ },
40
+ rules: {
41
+ ...tseslint.configs.recommended.rules,
42
+ "@typescript-eslint/naming-convention": [
43
+ "error",
44
+ {
45
+ selector: "default",
46
+ format: ["camelCase"],
47
+ leadingUnderscore: "allow"
48
+ },
49
+ {
50
+ selector: "typeLike",
51
+ format: ["PascalCase"]
52
+ },
53
+ {
54
+ selector: "variable",
55
+ modifiers: ["const"],
56
+ format: ["camelCase", "UPPER_CASE", "PascalCase"]
57
+ }
58
+ ],
59
+ "@typescript-eslint/no-explicit-any": "off",
60
+ "no-empty-pattern": "off",
61
+ "architecture/no-raw-locators-in-tests": "error",
62
+ "architecture/no-wait-for-timeout": "error",
63
+ "architecture/no-expect-in-page-objects": "error"
64
+ }
65
+ }
66
+ ];
@@ -0,0 +1,43 @@
1
+ import { test as base } from "@playwright/test";
2
+
3
+ import { loadRuntimeConfig, type RuntimeConfig } from "../config/runtime-config";
4
+ import { DataFactory } from "../data/factories/data-factory";
5
+ import { LoginPage } from "../pages/login-page";
6
+ import { PeoplePage } from "../pages/people-page";
7
+ import { createLogger, type Logger } from "../utils/logger";
8
+ import { StepLogger } from "../utils/test-step";
9
+
10
+ type FrameworkFixtures = {
11
+ appConfig: RuntimeConfig;
12
+ logger: Logger;
13
+ stepLogger: StepLogger;
14
+ dataFactory: DataFactory;
15
+ loginPage: LoginPage;
16
+ peoplePage: PeoplePage;
17
+ };
18
+
19
+ export const test = base.extend<FrameworkFixtures>({
20
+ appConfig: async ({}, use) => {
21
+ await use(loadRuntimeConfig());
22
+ },
23
+ logger: async ({}, use, testInfo) => {
24
+ const logger = createLogger({
25
+ test: testInfo.titlePath.join(" > ")
26
+ });
27
+ await use(logger);
28
+ },
29
+ stepLogger: async ({ logger }, use) => {
30
+ await use(new StepLogger(logger.child({ scope: "steps" })));
31
+ },
32
+ dataFactory: async ({ appConfig }, use) => {
33
+ await use(new DataFactory(appConfig.testRunId));
34
+ },
35
+ loginPage: async ({ page, appConfig, logger }, use) => {
36
+ await use(new LoginPage(page, appConfig.uiBaseUrl, logger.child({ pageObject: "LoginPage" })));
37
+ },
38
+ peoplePage: async ({ page, appConfig, logger }, use) => {
39
+ await use(new PeoplePage(page, appConfig.uiBaseUrl, logger.child({ pageObject: "PeoplePage" })));
40
+ }
41
+ });
42
+
43
+ export { expect } from "@playwright/test";