agents-cli-automation 1.0.15 → 1.0.17
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 +142 -88
package/package.json
CHANGED
|
@@ -1,104 +1,160 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
name: Playwright UI Testing - TypeScript (current repo)
|
|
3
|
-
description: Snapshot and quick guide for the Playwright + TypeScript setup present in this repository.
|
|
3
|
+
description: Snapshot and quick guide for the Playwright + TypeScript+BDD setup present in this repository.
|
|
4
4
|
argument-hint: "(no args)"
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
----
|
|
7
|
+
# Playwright + TypeScript (BDD) — repo snapshot
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
**Current Setup (Feb 2026)**
|
|
10
|
-
- **@playwright/test**: pinned to a verified stable version
|
|
11
|
-
- **playwright-bdd**: optional generator used in this repo; the `test` script runs `bddgen` to convert Gherkin features into Playwright specs
|
|
12
|
-
- **TypeScript**: pinned to a verified stable version
|
|
9
|
+
## Current Setup
|
|
13
10
|
|
|
14
|
-
|
|
11
|
+
- **@playwright/test**: v1.36.0 (or later)
|
|
12
|
+
- **playwright-bdd**: v8.4.2 (latest) — generator that converts Gherkin `.feature` files into Playwright specs
|
|
13
|
+
- **TypeScript**: v5.1.0 (or later)
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
15
|
+
This repository uses a **generator-based BDD flow**: Gherkin feature files in `tests/features/` are converted to Playwright specs by `bddgen`, and those specs are executed with `@playwright/test`.
|
|
16
|
+
|
|
17
|
+
## Key Points
|
|
18
|
+
|
|
19
|
+
- **Generator flow**: the `test` script runs `npx bddgen` (generates specs from features) followed by `npx playwright test` (runs generated specs).
|
|
20
|
+
- **Features**: place Gherkin files in `tests/features/*.feature`.
|
|
21
|
+
- **Steps**: implement step definitions in `tests/steps/*.ts`.
|
|
22
|
+
- **Fixtures**: `tests/fixtures/base.fixture.ts` extends the `playwright-bdd` `test` with custom fixtures like `loginPage`, and is included in the `steps` pattern so `bddgen` can wire fixtures to step handlers.
|
|
23
|
+
- **Config**: `playwright.config.ts` defines BDD config with `defineBddConfig()`, specifying `features`, `steps` (including fixtures first), and `outputDir`.
|
|
24
|
+
|
|
25
|
+
## Quick Files to Review
|
|
21
26
|
|
|
22
|
-
Quick files to review
|
|
23
27
|
- Playwright config: [playwright.config.ts](playwright.config.ts)
|
|
24
28
|
- TypeScript config: [tsconfig.json](tsconfig.json)
|
|
25
29
|
- Page object example: [tests/pages/login.page.ts](tests/pages/login.page.ts)
|
|
26
|
-
- JSON data utility: [tests/utils/data.ts](tests/utils/data.ts)
|
|
27
30
|
- Fixtures: [tests/fixtures/base.fixture.ts](tests/fixtures/base.fixture.ts)
|
|
28
31
|
- Steps: [tests/steps/loginSteps.ts](tests/steps/loginSteps.ts)
|
|
29
32
|
- Features: [tests/features/login.feature](tests/features/login.feature)
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
## Setup & Run Tests
|
|
35
|
+
|
|
36
|
+
Install dependencies:
|
|
32
37
|
|
|
33
38
|
```bash
|
|
34
39
|
npm install
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
npx playwright install
|
|
41
|
+
```
|
|
37
42
|
|
|
38
|
-
|
|
43
|
+
Run the tests (generator BDD flow):
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm test
|
|
47
|
+
```
|
|
39
48
|
|
|
40
|
-
|
|
41
|
-
- **playwright-bdd** — optional generator used in this repo; the `test` script runs `bddgen` to convert Gherkin features into Playwright specs.
|
|
42
|
-
- **TypeScript** — pinned to a verified stable version.
|
|
49
|
+
This runs `npx bddgen` to generate Playwright specs from `.feature` files, then `npx playwright test` to execute them.
|
|
43
50
|
|
|
44
|
-
|
|
51
|
+
## Example: Sauce Demo Login
|
|
45
52
|
|
|
46
|
-
|
|
53
|
+
A working example is included that tests login at https://www.saucedemo.com/ using demo credentials:
|
|
54
|
+
- username: `standard_user`
|
|
55
|
+
- password: `secret_sauce`
|
|
47
56
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
**Feature file** (`tests/features/login.feature`):
|
|
58
|
+
```gherkin
|
|
59
|
+
Feature: Login
|
|
60
|
+
Scenario: Successful login to SauceDemo
|
|
61
|
+
Given I open the login page
|
|
62
|
+
When I login with "standard_user" and "secret_sauce"
|
|
63
|
+
Then I should see the inventory page
|
|
64
|
+
```
|
|
52
65
|
|
|
53
|
-
|
|
66
|
+
**Step definitions** (`tests/steps/loginSteps.ts`):
|
|
67
|
+
```ts
|
|
68
|
+
import { createBdd } from 'playwright-bdd';
|
|
69
|
+
import { expect } from '@playwright/test';
|
|
70
|
+
import { test } from '../fixtures/base.fixture';
|
|
54
71
|
|
|
55
|
-
|
|
56
|
-
- TypeScript config: [tsconfig.json](tsconfig.json)
|
|
57
|
-
- Page object example: [tests/pages/login.page.ts](tests/pages/login.page.ts)
|
|
58
|
-
- JSON data utility: [tests/utils/data.ts](tests/utils/data.ts)
|
|
59
|
-
- Fixtures: [tests/fixtures/base.fixture.ts](tests/fixtures/base.fixture.ts)
|
|
60
|
-
- Steps: [tests/steps/loginSteps.ts](tests/steps/loginSteps.ts)
|
|
61
|
-
- Features: [tests/features/login.feature](tests/features/login.feature)
|
|
72
|
+
const { Given, When, Then } = createBdd(test);
|
|
62
73
|
|
|
63
|
-
|
|
74
|
+
Given('I open the login page', async ({ page }) => {
|
|
75
|
+
await page.goto('/');
|
|
76
|
+
});
|
|
64
77
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
When('I login with {string} and {string}', async ({ loginPage }, username: string, password: string) => {
|
|
79
|
+
await loginPage.login(username, password);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
Then('I should see the inventory page', async ({ page }) => {
|
|
83
|
+
await expect(page).toHaveURL(/inventory.html/);
|
|
84
|
+
});
|
|
70
85
|
```
|
|
71
86
|
|
|
72
|
-
|
|
87
|
+
**Fixtures** (`tests/fixtures/base.fixture.ts`):
|
|
88
|
+
```ts
|
|
89
|
+
import { test as base } from 'playwright-bdd';
|
|
90
|
+
import { LoginPage } from '../pages/login.page';
|
|
73
91
|
|
|
74
|
-
|
|
75
|
-
|
|
92
|
+
type Fixtures = {
|
|
93
|
+
loginPage: LoginPage;
|
|
94
|
+
};
|
|
76
95
|
|
|
77
|
-
|
|
96
|
+
export const test = base.extend<Fixtures>({
|
|
97
|
+
loginPage: async ({ page }, use) => {
|
|
98
|
+
await use(new LoginPage(page));
|
|
99
|
+
},
|
|
100
|
+
});
|
|
78
101
|
|
|
79
|
-
|
|
80
|
-
|
|
102
|
+
export { expect } from '@playwright/test';
|
|
103
|
+
```
|
|
81
104
|
|
|
82
|
-
##
|
|
105
|
+
## Playwright Config
|
|
83
106
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
107
|
+
**Key sections** (`playwright.config.ts`):
|
|
108
|
+
```ts
|
|
109
|
+
import { defineConfig } from '@playwright/test';
|
|
110
|
+
import { defineBddConfig } from 'playwright-bdd';
|
|
111
|
+
|
|
112
|
+
export default defineConfig({
|
|
113
|
+
testDir: 'tests',
|
|
114
|
+
timeout: 30_000,
|
|
115
|
+
use: {
|
|
116
|
+
headless: true,
|
|
117
|
+
viewport: { width: 1280, height: 720 },
|
|
118
|
+
baseURL: 'https://www.saucedemo.com'
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
export const bdd = defineBddConfig({
|
|
123
|
+
features: 'tests/features/**/*.feature',
|
|
124
|
+
steps: ['tests/fixtures/**/*.ts', 'tests/steps/**/*.ts'],
|
|
125
|
+
outputDir: 'tests',
|
|
126
|
+
});
|
|
127
|
+
```
|
|
87
128
|
|
|
88
|
-
|
|
129
|
+
**Important**: Include `tests/fixtures/**/*.ts` **before** `tests/steps/**/*.ts` in the `steps` pattern so fixtures are loaded first and available to step definitions.
|
|
130
|
+
|
|
131
|
+
## Common Patterns
|
|
89
132
|
|
|
90
|
-
|
|
133
|
+
### Using Fixtures in Steps
|
|
91
134
|
|
|
92
|
-
|
|
135
|
+
To use a custom fixture in step definitions, import the fixture-extended `test` from your fixture file and pass it to `createBdd()`:
|
|
93
136
|
|
|
94
|
-
|
|
137
|
+
```ts
|
|
138
|
+
import { createBdd } from 'playwright-bdd';
|
|
139
|
+
import { test } from '../fixtures/base.fixture';
|
|
140
|
+
|
|
141
|
+
const { Given, When, Then } = createBdd(test);
|
|
142
|
+
|
|
143
|
+
When('I do something', async ({ myCustomFixture }) => {
|
|
144
|
+
// myCustomFixture is now available
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Data Utilities
|
|
149
|
+
|
|
150
|
+
Load test data from JSON or YAML files:
|
|
95
151
|
|
|
96
152
|
```bash
|
|
97
153
|
npm install js-yaml
|
|
98
154
|
npm install -D @types/js-yaml
|
|
99
155
|
```
|
|
100
156
|
|
|
101
|
-
Example
|
|
157
|
+
Example utility (`tests/utils/readData.ts`):
|
|
102
158
|
|
|
103
159
|
```ts
|
|
104
160
|
import fs from 'fs';
|
|
@@ -106,58 +162,56 @@ import path from 'path';
|
|
|
106
162
|
import yaml from 'js-yaml';
|
|
107
163
|
|
|
108
164
|
export function readData(filePath: string): any {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
165
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
166
|
+
const raw = fs.readFileSync(filePath, 'utf8');
|
|
167
|
+
if (ext === '.json') return JSON.parse(raw);
|
|
168
|
+
if (ext === '.yml' || ext === '.yaml') return yaml.load(raw);
|
|
169
|
+
throw new Error(`Unsupported data format: ${ext}`);
|
|
114
170
|
}
|
|
115
171
|
```
|
|
116
172
|
|
|
117
|
-
Usage
|
|
173
|
+
Usage in steps:
|
|
118
174
|
|
|
119
175
|
```ts
|
|
120
176
|
import { readData } from '../utils/readData';
|
|
121
177
|
|
|
122
|
-
const
|
|
123
|
-
|
|
178
|
+
const loginData = readData('tests/data/users.yaml');
|
|
179
|
+
When('I login as {string}', async ({ page }, username: string) => {
|
|
180
|
+
const user = loginData[username];
|
|
181
|
+
// use user.password, etc.
|
|
182
|
+
});
|
|
124
183
|
```
|
|
125
184
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
- If you prefer importing JSON directly, enable `resolveJsonModule` in `tsconfig.json`.
|
|
129
|
-
- For large or frequently-modified data files, consider caching the parsed result in the utility.
|
|
185
|
+
## Dependency Updates
|
|
130
186
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
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`:
|
|
187
|
+
To update dev dependencies to compatible latest versions:
|
|
134
188
|
|
|
135
189
|
```bash
|
|
136
|
-
# update devDependencies in package.json
|
|
137
190
|
npx npm-check-updates -u '/.*/' --dep dev
|
|
138
|
-
|
|
139
|
-
# install updates
|
|
140
191
|
npm install
|
|
141
192
|
```
|
|
142
193
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
- `npx npm-check-updates -u` only modifies `package.json`. If `package-lock.json` or `node_modules` pin old versions, run a fresh install:
|
|
194
|
+
If you encounter peer dependency conflicts or need a fresh install:
|
|
146
195
|
|
|
147
196
|
```bash
|
|
148
|
-
#
|
|
197
|
+
# Windows PowerShell:
|
|
198
|
+
Remove-Item -Recurse -Force node_modules
|
|
199
|
+
Remove-Item package-lock.json
|
|
200
|
+
npm install
|
|
201
|
+
|
|
202
|
+
# Or on macOS/Linux:
|
|
149
203
|
rm -rf node_modules package-lock.json
|
|
150
204
|
npm install
|
|
151
205
|
```
|
|
152
206
|
|
|
153
|
-
|
|
207
|
+
## Troubleshooting
|
|
154
208
|
|
|
155
|
-
|
|
156
|
-
Remove-Item -Recurse -Force node_modules
|
|
157
|
-
Remove-Item package-lock.json
|
|
158
|
-
npm install
|
|
159
|
-
```
|
|
209
|
+
**"BDD config not found" error**: Ensure `playwright.config.ts` exports `bdd = defineBddConfig({...})` and the `testDir` matches your `outputDir`.
|
|
160
210
|
|
|
161
|
-
|
|
211
|
+
**"Unknown parameter" in generated tests**: Make sure custom fixture files are included in the `steps` pattern **before** step definition files, so fixtures are loaded and available.
|
|
212
|
+
|
|
213
|
+
**Tests not found**: Verify `outputDir` in `defineBddConfig()` points to a directory inside (or at) Playwright's `testDir`, typically `'tests'`.
|
|
214
|
+
|
|
215
|
+
---
|
|
162
216
|
|
|
163
|
-
|
|
217
|
+
_Updated: Playwright + TypeScript + BDD setup snapshot_
|