agents-cli-automation 1.0.14 → 1.0.16
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.
- package/package.json +1 -1
- package/src/templates/playwright-agent-ts.md +208 -76
package/package.json
CHANGED
|
@@ -1,93 +1,225 @@
|
|
|
1
|
+
|
|
1
2
|
name: Playwright UI Testing - TypeScript (current repo)
|
|
2
|
-
description: Snapshot and quick guide for the Playwright + TypeScript
|
|
3
|
+
description: Snapshot and quick guide for the Playwright + TypeScript+BDD setup present in this repository.
|
|
3
4
|
argument-hint: "(no args)"
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
----
|
|
7
|
+
# Playwright + TypeScript — repo snapshot
|
|
8
|
+
**Current Setup**
|
|
9
|
+
- **@playwright/test**: pinned to a verified stable version
|
|
10
|
+
- **playwright-bdd**: used in this repo; the `test` script runs `bddgen` to convert Gherkin features into Playwright specs
|
|
11
|
+
- **TypeScript**: pinned to a verified stable version
|
|
12
|
+
|
|
13
|
+
This scaffold uses a generator-based BDD flow: Gherkin feature files in `tests/features/` are converted to Playwright specs by `bddgen` (from `playwright-bdd`), and those specs are executed with `@playwright/test`.
|
|
6
14
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Initial setup installs latest versions, then locks them to prevent unexpected updates.
|
|
16
|
-
|
|
17
|
-
This document explains the current Playwright + TypeScript scaffold and details the recommended layout for:
|
|
18
|
-
- Page Object Models using `@playwright/test`
|
|
19
|
-
- A small JSON data util
|
|
20
|
-
- Fixtures wired for `playwright-bdd`
|
|
21
|
-
- Step definitions that consume fixtures via `playwright-bdd`
|
|
22
|
-
|
|
23
|
-
**Key points (current state and recommended layout)**
|
|
24
|
-
- Playwright config uses `defineBddConfig()` from `playwright-bdd` to export the BDD configuration: see [playwright.config.ts](playwright.config.ts). The config includes `features`, `steps`, and `outputDir` patterns with reporter configuration for HTML, JSON, and JUnit outputs.
|
|
25
|
-
- The `ui` project has `testDir: '.features-gen'` and `testMatch: '**/*.feature.spec.{ts,js}'` to discover generated specs.
|
|
26
|
-
- Place Gherkin features in `tests/features/*.feature` (example: [tests/features/login.feature](tests/features/login.feature)).
|
|
27
|
-
- Page Objects: implement page classes under `tests/pages/` (example: `tests/pages/login.page.ts`) and import `Page` from `@playwright/test`.
|
|
28
|
-
- Test data util: add a JSON reader like `tests/utils/data.ts` that loads `tests/data/*.json` so tests/steps can read credentials and fixtures.
|
|
29
|
-
- Fixtures: create `tests/fixtures/base.fixture.ts` that extends `test` from `playwright-bdd` with proper TypeScript type definitions via `CustomFixtures` interface. This ensures fixtures are properly typed (for example `loginPage`). Include the fixtures file in the `steps` pattern in `bddConfig` so the generator can discover them.
|
|
30
|
-
- Steps: implement step definitions under `tests/steps/*.ts`. Use `createBdd(test)` from `playwright-bdd` and register Given/When/Then handlers that accept fixtures (e.g., `loginPage`) and call page object methods.
|
|
31
|
-
- Generated specs: the generator writes Playwright specs into `.features-gen` (configured via `outputDir` in `bddConfig`) when using `npx bddgen`. The generated files are `.feature.spec.js` (or `.ts`) and are discovered by the `ui` project via `testMatch: '**/*.feature.spec.{ts,js}'`.
|
|
32
|
-
- Reporters: HTML (in `playwright-report/`), JSON (for CI integration), and JUnit (for CI/CD pipelines) are configured by default.
|
|
33
|
-
|
|
34
|
-
Files to inspect or add quickly
|
|
15
|
+
Key points
|
|
16
|
+
- Generator flow: the `test` script runs `npx bddgen` followed by `npx playwright test` to generate specs and run them.
|
|
17
|
+
- Features: put Gherkin files in `tests/features/*.feature`.
|
|
18
|
+
- Steps: add step definitions in `tests/steps/*.ts`. Include fixtures (for example `tests/fixtures/**/*.ts`) in the generator `steps` pattern so `bddgen` can connect them to the test instance.
|
|
19
|
+
- Fixtures: `tests/fixtures/base.fixture.ts` provides typed page-object fixtures used by generated specs and step handlers.
|
|
20
|
+
|
|
21
|
+
Quick files to review
|
|
35
22
|
- Playwright config: [playwright.config.ts](playwright.config.ts)
|
|
36
|
-
-
|
|
23
|
+
- TypeScript config: [tsconfig.json](tsconfig.json)
|
|
37
24
|
- Page object example: [tests/pages/login.page.ts](tests/pages/login.page.ts)
|
|
38
|
-
- JSON data
|
|
39
|
-
- Test data: [tests/data/users.json](tests/data/users.json)
|
|
25
|
+
- JSON data utility: [tests/utils/data.ts](tests/utils/data.ts)
|
|
40
26
|
- Fixtures: [tests/fixtures/base.fixture.ts](tests/fixtures/base.fixture.ts)
|
|
41
27
|
- Steps: [tests/steps/loginSteps.ts](tests/steps/loginSteps.ts)
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
28
|
+
- Features: [tests/features/login.feature](tests/features/login.feature)
|
|
29
|
+
|
|
30
|
+
Quick runnable example (Sauce Demo)
|
|
31
|
+
----------------------------------
|
|
32
|
+
|
|
33
|
+
Use https://www.saucedemo.com/ with these demo credentials to get a working test quickly:
|
|
34
|
+
|
|
35
|
+
- username: `standard_user`
|
|
36
|
+
- password: `secret_sauce`
|
|
37
|
+
|
|
38
|
+
Here's a minimal Playwright test that performs a login and asserts the inventory page loads:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { test, expect } from '@playwright/test';
|
|
42
|
+
|
|
43
|
+
test('saucedemo login works', async ({ page }) => {
|
|
44
|
+
await page.goto('https://www.saucedemo.com/');
|
|
45
|
+
await page.fill('[data-test="username"]', 'standard_user');
|
|
46
|
+
await page.fill('[data-test="password"]', 'secret_sauce');
|
|
47
|
+
await page.click('[data-test="login-button"]');
|
|
48
|
+
await expect(page).toHaveURL(/inventory.html/);
|
|
49
|
+
await expect(page.locator('.inventory_list')).toBeVisible();
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
To run this example locally:
|
|
60
54
|
|
|
61
55
|
```bash
|
|
56
|
+
npx playwright test tests/example.spec.ts # or run `npm test`
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
If you want, I can update the existing `tests/example.spec.ts` and `tests/pages/login.page.ts` to use this Sauce Demo flow and run the tests here.
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
Run the tests (generator BDD flow):
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npm install
|
|
66
|
+
npm install -D playwright-bdd
|
|
67
|
+
# Playwright + TypeScript — repo snapshot
|
|
68
|
+
|
|
69
|
+
## Current setup
|
|
70
|
+
|
|
71
|
+
- **@playwright/test** — pinned to a verified stable version.
|
|
72
|
+
- **playwright-bdd** — optional generator used in this repo; the `test` script runs `bddgen` to convert Gherkin features into Playwright specs.
|
|
73
|
+
- **TypeScript** — pinned to a verified stable version.
|
|
74
|
+
|
|
75
|
+
This repository uses a generator-based BDD flow: Gherkin feature files in `tests/features/` are converted to Playwright specs by `bddgen` (from `playwright-bdd`), and those specs are executed with `@playwright/test`.
|
|
76
|
+
|
|
77
|
+
## Key points
|
|
78
|
+
|
|
79
|
+
- **Generator flow**: the `test` script runs `npx bddgen` followed by `npx playwright test` to generate specs and run them.
|
|
80
|
+
- **Features**: place Gherkin files in `tests/features/*.feature`.
|
|
81
|
+
- **Steps**: implement step definitions in `tests/steps/*.ts`. Include fixtures (for example `tests/fixtures/**/*.ts`) in the generator `steps` pattern so `bddgen` can wire them to the test instance.
|
|
82
|
+
- **Fixtures**: `tests/fixtures/base.fixture.ts` provides typed page-object fixtures used by generated specs and step handlers.
|
|
83
|
+
|
|
84
|
+
## Quick files to review
|
|
85
|
+
|
|
86
|
+
- Playwright config: [playwright.config.ts](playwright.config.ts)
|
|
87
|
+
- TypeScript config: [tsconfig.json](tsconfig.json)
|
|
88
|
+
- Page object example: [tests/pages/login.page.ts](tests/pages/login.page.ts)
|
|
89
|
+
- JSON data utility: [tests/utils/data.ts](tests/utils/data.ts)
|
|
90
|
+
- Fixtures: [tests/fixtures/base.fixture.ts](tests/fixtures/base.fixture.ts)
|
|
91
|
+
- Steps: [tests/steps/loginSteps.ts](tests/steps/loginSteps.ts)
|
|
92
|
+
- Features: [tests/features/login.feature](tests/features/login.feature)
|
|
93
|
+
|
|
94
|
+
## Run the tests (generator BDD flow)
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
npm install
|
|
98
|
+
npm install -D playwright-bdd
|
|
62
99
|
npx playwright install
|
|
63
|
-
|
|
64
|
-
npx playwright show-report # View HTML report
|
|
65
|
-
npx playwright test --project=ui tests/specs/login.spec.ts
|
|
100
|
+
npm test
|
|
66
101
|
```
|
|
67
102
|
|
|
68
|
-
|
|
103
|
+
Handling missing bddgen
|
|
104
|
+
-----------------------
|
|
105
|
+
|
|
106
|
+
If you see the message "To get \"bddgen\" CLI please install \"playwright-bdd\" package", you have two options:
|
|
107
|
+
|
|
108
|
+
- Install the generator (recommended if you use Gherkin features):
|
|
69
109
|
|
|
70
110
|
```bash
|
|
111
|
+
npm install -D playwright-bdd
|
|
112
|
+
npx playwright install
|
|
71
113
|
npm test
|
|
72
114
|
```
|
|
73
|
-
|
|
74
|
-
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
115
|
+
|
|
116
|
+
- Skip the generator and run Playwright directly (if you don't use Gherkin features):
|
|
117
|
+
|
|
118
|
+
1. Remove `npx bddgen &&` from your `test` script in `package.json`, or run Playwright directly:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
npx playwright test
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
2. Example `package.json` scripts without `bddgen`:
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
"scripts": {
|
|
128
|
+
"test": "npx playwright test",
|
|
129
|
+
"playwright:install": "npx playwright install"
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
## Notes
|
|
135
|
+
|
|
136
|
+
- The `test` script runs `npx bddgen` and then `npx playwright test`. If `playwright-bdd` is not installed, you'll be prompted to run `npm install -D playwright-bdd`.
|
|
137
|
+
- Generated specs are written to the configured output directory (commonly `.features-gen`) and then executed by Playwright.
|
|
138
|
+
|
|
139
|
+
## How to enable generator-based BDD later
|
|
140
|
+
|
|
141
|
+
- Install `playwright-bdd` as a dev dependency and add `npx bddgen` to the `test` script.
|
|
142
|
+
- Add step definitions under `tests/steps/` and include fixtures in the generator `steps` pattern.
|
|
143
|
+
|
|
144
|
+
## Ways I can help
|
|
145
|
+
|
|
146
|
+
- Add `playwright-bdd` to `devDependencies` and update `package.json` so `npm install` installs it automatically.
|
|
147
|
+
- Add a GitHub Actions workflow that runs `npm test` on push.
|
|
148
|
+
- Expand page objects, feature coverage, or step definitions.
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
_Generated: Playwright + TypeScript snapshot and quick guide._
|
|
153
|
+
|
|
154
|
+
## Data utilities (read JSON / YAML)
|
|
155
|
+
|
|
156
|
+
You can add a small utility to load test data from JSON or YAML. Install the YAML parser and optional types:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
npm install js-yaml
|
|
160
|
+
npm install -D @types/js-yaml
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Example TypeScript utility (`tests/utils/readData.ts`):
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
import fs from 'fs';
|
|
167
|
+
import path from 'path';
|
|
168
|
+
import yaml from 'js-yaml';
|
|
169
|
+
|
|
170
|
+
export function readData(filePath: string): any {
|
|
171
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
172
|
+
const raw = fs.readFileSync(filePath, 'utf8');
|
|
173
|
+
if (ext === '.json') return JSON.parse(raw);
|
|
174
|
+
if (ext === '.yml' || ext === '.yaml') return yaml.load(raw);
|
|
175
|
+
throw new Error(`Unsupported data format: ${ext}`);
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Usage example in a test or step definition:
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
import { readData } from '../utils/readData';
|
|
183
|
+
|
|
184
|
+
const login = readData('tests/data/login.yaml');
|
|
185
|
+
// use `login.username`, `login.password` in your steps
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Tips
|
|
189
|
+
|
|
190
|
+
- If you prefer importing JSON directly, enable `resolveJsonModule` in `tsconfig.json`.
|
|
191
|
+
- For large or frequently-modified data files, consider caching the parsed result in the utility.
|
|
192
|
+
|
|
193
|
+
## Dependency updates & provisioning
|
|
194
|
+
|
|
195
|
+
To update dev dependencies in `package.json` to the latest compatible versions you can use `npm-check-updates` (ncu). The command below updates `devDependencies` in `package.json`:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
# update devDependencies in package.json
|
|
199
|
+
npx npm-check-updates -u '/.*/' --dep dev
|
|
200
|
+
|
|
201
|
+
# install updates
|
|
202
|
+
npm install
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Notes and troubleshooting
|
|
206
|
+
|
|
207
|
+
- `npx npm-check-updates -u` only modifies `package.json`. If `package-lock.json` or `node_modules` pin old versions, run a fresh install:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
# remove lockfile and node_modules then reinstall (cross-platform idea)
|
|
211
|
+
rm -rf node_modules package-lock.json
|
|
212
|
+
npm install
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
- On Windows PowerShell use:
|
|
216
|
+
|
|
217
|
+
```powershell
|
|
218
|
+
Remove-Item -Recurse -Force node_modules
|
|
219
|
+
Remove-Item package-lock.json
|
|
220
|
+
npm install
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
- If `npm install` reports peer dependency conflicts or fails, it's usually due to incompatible major versions; I can help resolve those selectively.
|
|
224
|
+
|
|
225
|
+
Would you like me to run the `npx npm-check-updates -u '/.*/' --dep dev` and `npm install` commands now, or create a commit/update `package.json` myself? If you prefer, I can also open a PR with the changes.
|