shiplightai 0.1.93 → 0.1.94
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.
Potentially problematic release.
This version of shiplightai might be problematic. Click here for more details.
- package/README.md +2 -1
- package/dist/cjs/debugger-pw.cjs +24 -24
- package/dist/cjs/fixture.cjs +58 -58
- package/dist/cjs/index.cjs +37 -37
- package/dist/cjs/reporter.cjs +48 -48
- package/dist/cli.js +130 -101
- package/dist/debugger-pw.js +24 -24
- package/dist/fixture.js +58 -58
- package/dist/index.js +40 -40
- package/dist/reporter.js +48 -48
- package/dist/spec/actions.md +702 -0
- package/dist/spec/yaml.md +1047 -0
- package/package.json +3 -4
|
@@ -0,0 +1,1047 @@
|
|
|
1
|
+
# YAML Test Language Specification
|
|
2
|
+
|
|
3
|
+
**Version:** 1.4.0
|
|
4
|
+
**Status:** Living document — source of truth for the Shiplight YAML test format
|
|
5
|
+
|
|
6
|
+
> **Design principle:** This YAML format is designed for **coding agents to read and write**. The syntax is for humans to **read and understand**, not intended for humans to write directly.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Table of Contents
|
|
11
|
+
|
|
12
|
+
1. [Overview](#1-overview)
|
|
13
|
+
2. [File Conventions](#2-file-conventions)
|
|
14
|
+
3. [Top-Level Keys](#3-top-level-keys)
|
|
15
|
+
4. [Statements](#4-statements)
|
|
16
|
+
- [DRAFT](#41-draft)
|
|
17
|
+
- [ACTION](#42-action)
|
|
18
|
+
- [VERIFY](#43-verify-shorthand)
|
|
19
|
+
- [URL](#44-url-shorthand)
|
|
20
|
+
- [STEP](#45-step)
|
|
21
|
+
- [IF_ELSE](#46-if_else)
|
|
22
|
+
- [WHILE_LOOP](#47-while_loop)
|
|
23
|
+
- [Code](#48-code)
|
|
24
|
+
- [WAIT_UNTIL](#49-wait_until-shorthand)
|
|
25
|
+
- [WAIT](#410-wait-shorthand)
|
|
26
|
+
- [The `js:` Key — One Model](#411-the-js-key--one-model)
|
|
27
|
+
5. [Templates](#5-templates)
|
|
28
|
+
6. [Functions](#6-functions)
|
|
29
|
+
7. [Variables](#7-variables)
|
|
30
|
+
8. [Teardown](#8-teardown)
|
|
31
|
+
9. [Test Suites](#9-test-suites)
|
|
32
|
+
10. [Lifecycle Hooks](#10-lifecycle-hooks)
|
|
33
|
+
11. [Parameterized Tests](#11-parameterized-tests)
|
|
34
|
+
12. [Complete Examples](#12-complete-examples)
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 1. Overview
|
|
39
|
+
|
|
40
|
+
A Shiplight YAML test file (`.test.yaml`) defines one or more end-to-end tests. A file can be either a **single-test file** (one test) or a **suite file** (multiple tests grouped with shared config and hooks). The transpiler converts it into a Playwright test file (`.yaml.spec.ts`) that uses the `shiplightai` fixture for AI-powered and deterministic browser automation.
|
|
41
|
+
|
|
42
|
+
**Key concepts:**
|
|
43
|
+
- **DRAFT** statements are natural language instructions resolved by AI at runtime (~5-10s each).
|
|
44
|
+
- **ACTION** statements are enriched DRAFTs with an `intent` and a cache (`action:`/`locator:`) for deterministic replay (<1s each). When the cache fails, the agent auto-heals using the intent.
|
|
45
|
+
- **Suites** group multiple tests in one file with shared hooks and sequential execution.
|
|
46
|
+
- **Lifecycle hooks** (`beforeAll`, `afterAll`, `beforeEach`, `afterEach`) handle setup and cleanup.
|
|
47
|
+
- **Parameterized tests** generate multiple test instances from data sets using `{{variable}}` runtime variables.
|
|
48
|
+
- The transpiler produces standalone Playwright tests — no runtime YAML dependency.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 2. File Conventions
|
|
53
|
+
|
|
54
|
+
| Convention | Value |
|
|
55
|
+
|---|---|
|
|
56
|
+
| Test file extension | `*.test.yaml` |
|
|
57
|
+
| Generated output | `*.yaml.spec.ts` (sibling of YAML source) |
|
|
58
|
+
| Template files | Any `.yaml` — no naming restriction |
|
|
59
|
+
| Discovery | `**/*.test.yaml`, excluding `node_modules` |
|
|
60
|
+
| Max file size | 1 MB |
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 3. Top-Level Keys
|
|
65
|
+
|
|
66
|
+
A file must be either a **single-test file** (with `goal`/`statements`) or a **suite file** (with `suite`). Having both is an error. The `goal` field is auto-derived from `name` if not explicitly provided.
|
|
67
|
+
|
|
68
|
+
### Required Keys (Single-Test Files)
|
|
69
|
+
|
|
70
|
+
| Key | Type | Description |
|
|
71
|
+
|---|---|---|
|
|
72
|
+
| `goal` | `string` | Test objective. Becomes the Playwright test title if `name` is not set. Auto-derived from `name` if omitted. |
|
|
73
|
+
| `statements` | `Statement[]` | Ordered list of test steps. See [Statements](#4-statements). |
|
|
74
|
+
|
|
75
|
+
### Required Keys (Suite Files)
|
|
76
|
+
|
|
77
|
+
| Key | Type | Description |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| `suite` | `object` | Suite definition. See [Test Suites](#9-test-suites). Mutually exclusive with `goal`/`statements`. |
|
|
80
|
+
|
|
81
|
+
### Optional Keys
|
|
82
|
+
|
|
83
|
+
| Key | Type | Default | Description |
|
|
84
|
+
|---|---|---|---|
|
|
85
|
+
| `base_url` | `string` | — | Base URL for relative `URL:` statements. Maps to Playwright `test.use({ baseURL })`. Does **not** auto-navigate — use `URL: /` to navigate. |
|
|
86
|
+
| `test_case_id` | `number` | — | Links to a cloud test case for sync. |
|
|
87
|
+
| `name` | `string` | — | Test title override (single-test) or suite name (suite). If set on a single-test file without `goal`, `goal` is auto-derived from `name`. |
|
|
88
|
+
| `tags` | `string[]` | — | Playwright tags for `--grep` filtering. Each tag is prefixed with `@` in the test name. |
|
|
89
|
+
| `use` | `object` | — | Playwright `test.use()` config. Supports all Playwright use options (`baseURL`, `viewport`, `storageState`, `locale`, `timezoneId`, `httpCredentials`, etc.). |
|
|
90
|
+
| `teardown` | `Statement[]` | — | Cleanup steps that run in a `finally` block, even if the test fails. Single-test only. |
|
|
91
|
+
| `beforeEach` | `Statement[]` | — | Statements to run before each test. Single-test files only. See [Lifecycle Hooks](#10-lifecycle-hooks). |
|
|
92
|
+
| `afterEach` | `Statement[]` | — | Statements to run after each test. Single-test files only. See [Lifecycle Hooks](#10-lifecycle-hooks). |
|
|
93
|
+
| `parameters` | `ParameterSet[]` | — | Data sets for parameterized test generation. See [Parameterized Tests](#11-parameterized-tests). |
|
|
94
|
+
| `timeout` | `number` | — | Per-test timeout in milliseconds. Transpiles to `test.setTimeout()`. |
|
|
95
|
+
| `skip` | `boolean \| string` | — | Skip test. `true` skips unconditionally; a string skips with a reason message. Prefer string form (`skip: "Bug #123"`) so reason is visible in reports. |
|
|
96
|
+
| `fail` | `boolean \| string` | — | Mark test as expected failure. `true` or a reason string. Prefer string form (`fail: "Known issue"`) so reason is visible in reports. |
|
|
97
|
+
| `only` | `boolean` | — | Focus: run only this test. Transpiles to `test.only()`. |
|
|
98
|
+
| `slow` | `boolean` | — | Triple the test timeout. Transpiles to `test.slow()`. |
|
|
99
|
+
| `final_feedback` | `string` | — | Runtime field. Final execution feedback from the last run. |
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## 4. Statements
|
|
104
|
+
|
|
105
|
+
Statements are the building blocks of a test. Each statement has a `type` (inferred from YAML syntax) and a system-generated `uid` (UUID v4, assigned during parsing).
|
|
106
|
+
|
|
107
|
+
### Core Statement Types
|
|
108
|
+
|
|
109
|
+
| Type | Enriched? | Description |
|
|
110
|
+
|---|---|---|
|
|
111
|
+
| `DRAFT` | No | Natural language instruction. Requires AI agent execution at runtime. |
|
|
112
|
+
| `ACTION` | Yes | Enriched with a cache (`action:`/`locator:`) for deterministic replay. |
|
|
113
|
+
| `STEP` | Yes | A multi-action container — groups multiple child statements (ACTIONs, DRAFTs, etc.). |
|
|
114
|
+
|
|
115
|
+
A DRAFT is not yet enriched. When the AI agent executes a DRAFT, it enriches into either an ACTION (single action produced) or a STEP (multiple actions produced). ACTIONs and STEPs are already enriched and replay deterministically.
|
|
116
|
+
|
|
117
|
+
### Statement Type Inference
|
|
118
|
+
|
|
119
|
+
| YAML Syntax | Inferred Type | Description |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| `VERIFY: ...` | `ACTION` | Assertion shorthand |
|
|
122
|
+
| `URL: ...` | `ACTION` (go_to_url) | Navigation shorthand (auto-generates `action_entity`) |
|
|
123
|
+
| `intent` only | `DRAFT` | Natural language instruction in object form |
|
|
124
|
+
| Object with `action` key | `ACTION` | Deterministic browser action |
|
|
125
|
+
| `STEP: ...` + `statements:` | `STEP` | Group of related statements |
|
|
126
|
+
| `IF: ...` + `THEN: ...` | `IF_ELSE` | Conditional execution |
|
|
127
|
+
| `WHILE: ...` + `DO: ...` | `WHILE_LOOP` | Loop with timeout |
|
|
128
|
+
| `description:` + `js:` | `ACTION` | Inline JavaScript escape hatch (no self-healing) |
|
|
129
|
+
| `WAIT_UNTIL: ...` | `ACTION` (ai_wait_until) | Condition wait with timeout — AI (default), or JS via a sibling `js:` key |
|
|
130
|
+
| `WAIT: ...` | `ACTION` (wait) | Fixed duration wait (use sparingly) |
|
|
131
|
+
| `template: ...` | *(inlined)* | Expanded before parsing — not a statement type |
|
|
132
|
+
| `call: "file#export"` | `ACTION` | Calls a custom function — see [Functions](#6-functions) |
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
### 4.1 DRAFT
|
|
137
|
+
|
|
138
|
+
A natural language instruction that requires AI agent execution at runtime. The agent interprets the instruction and produces concrete browser actions. After execution, a DRAFT is enriched into an ACTION (single action produced) or a STEP (multiple actions produced).
|
|
139
|
+
|
|
140
|
+
**Syntax:**
|
|
141
|
+
|
|
142
|
+
```yaml
|
|
143
|
+
statements:
|
|
144
|
+
- intent: Click the login button
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**Performance:** ~5-10 seconds per DRAFT (AI resolution).
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
### 4.2 ACTION
|
|
152
|
+
|
|
153
|
+
An enriched browser action that replays deterministically (<1s). Every ACTION has an `intent` that defines _what_ the action does. The `action`/`locator` fields are **caches** of _how_ to do it. When a cache fails (stale locator, changed DOM), the agent self-heals by using the intent to re-inspect the page and regenerate the action.
|
|
154
|
+
|
|
155
|
+
In YAML, the presence of an `action` key distinguishes an ACTION from a DRAFT — an `intent`-only object is parsed as a DRAFT. (For one-off Playwright code that has no named action, use the [Code](#48-code) escape hatch — but note it does **not** self-heal.)
|
|
156
|
+
|
|
157
|
+
**Structured format** — named action with parameters. All fields other than `intent`, `action`, `locator`, `xpath` are passed as arguments to the action. Run `npx shiplight spec actions` for available actions and their parameters.
|
|
158
|
+
|
|
159
|
+
```yaml
|
|
160
|
+
statements:
|
|
161
|
+
- intent: Click the login button
|
|
162
|
+
action: click
|
|
163
|
+
locator: "getByRole('button', { name: 'Login' })"
|
|
164
|
+
|
|
165
|
+
- intent: Enter email address
|
|
166
|
+
action: input_text
|
|
167
|
+
locator: "getByPlaceholder('Email')"
|
|
168
|
+
text: "user@example.com"
|
|
169
|
+
|
|
170
|
+
- intent: Select country
|
|
171
|
+
action: select_dropdown_option
|
|
172
|
+
locator: "getByRole('combobox')"
|
|
173
|
+
option: "United States"
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**Fields:**
|
|
177
|
+
|
|
178
|
+
| Field | Type | Required | Description |
|
|
179
|
+
|---|---|---|---|
|
|
180
|
+
| `intent` | `string` | Yes | Human-readable intent (used for self-healing). |
|
|
181
|
+
| `action` | `string` | Yes | Action name. Run `npx shiplight spec actions` for available actions. |
|
|
182
|
+
| `locator` | `string` | No | Playwright locator string. |
|
|
183
|
+
| `xpath` | `string` | No | XPath selector. Only needed when an ACTION has neither `locator` nor a named target. |
|
|
184
|
+
|
|
185
|
+
**Performance:** ~1 second (deterministic replay).
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
### 4.3 VERIFY (Shorthand)
|
|
190
|
+
|
|
191
|
+
Shorthand for assertions.
|
|
192
|
+
|
|
193
|
+
**Syntax:**
|
|
194
|
+
|
|
195
|
+
```yaml
|
|
196
|
+
statements:
|
|
197
|
+
# Draft (AI-only, no cache)
|
|
198
|
+
- VERIFY: The dashboard heading is visible
|
|
199
|
+
- VERIFY: Shopping cart shows 3 items
|
|
200
|
+
|
|
201
|
+
# Enriched (with JS code cache — quote values containing { } : or other special YAML chars)
|
|
202
|
+
- VERIFY: button ABC is visible
|
|
203
|
+
js: "await expect(page.getByRole('button', { name: 'ABC' })).toBeVisible({ timeout: 2000 })"
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
When the optional `js` sibling key is present, it acts as a code cache for the assertion.
|
|
207
|
+
|
|
208
|
+
**Execution behavior:**
|
|
209
|
+
- **`statement` only (draft):** AI evaluates the natural language assertion (~5-10s).
|
|
210
|
+
- **`js` only:** Runs the JS assertion directly (<1s). No AI fallback.
|
|
211
|
+
- **Both `js` and `statement` (enriched):** Runs `js` first. If it fails, falls back to AI evaluation of `statement` (self-healing). The `js` cache is written by AI agents during enrichment, not by humans.
|
|
212
|
+
|
|
213
|
+
**Quoting rules:** Same as `js:` and `IF:`/`WHILE:` — quote the value when it contains special YAML characters (`{`, `}`, `:`, `#`, etc.).
|
|
214
|
+
|
|
215
|
+
VERIFY is the only `js:` surface with an AI fallback — see [The `js:` Key — One Model](#411-the-js-key--one-model) for the cross-statement comparison.
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
### 4.4 URL (Shorthand)
|
|
220
|
+
|
|
221
|
+
Shorthand for page navigation.
|
|
222
|
+
|
|
223
|
+
**Syntax:**
|
|
224
|
+
|
|
225
|
+
```yaml
|
|
226
|
+
statements:
|
|
227
|
+
# Plain URL
|
|
228
|
+
- URL: /inventory.html
|
|
229
|
+
- URL: https://app.example.com/login
|
|
230
|
+
|
|
231
|
+
# With optional arguments
|
|
232
|
+
- URL: /dashboard
|
|
233
|
+
new_tab: true
|
|
234
|
+
timeout_seconds: 30
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
**Optional sibling keys:**
|
|
238
|
+
|
|
239
|
+
| Key | Type | Default | Description |
|
|
240
|
+
|---|---|---|---|
|
|
241
|
+
| `new_tab` | `boolean` | `false` | Open the URL in a new browser tab. |
|
|
242
|
+
| `timeout_seconds` | `number` | — | Navigation timeout in seconds. |
|
|
243
|
+
|
|
244
|
+
**Notes:**
|
|
245
|
+
- Relative URLs (e.g., `/path`) resolve against Playwright's `baseURL` config.
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
### 4.5 STEP
|
|
250
|
+
|
|
251
|
+
A multi-action container that groups related child statements. A STEP is the enriched form when a DRAFT produces multiple actions, or it can be authored directly to organize logically related statements.
|
|
252
|
+
|
|
253
|
+
**Syntax:**
|
|
254
|
+
|
|
255
|
+
```yaml
|
|
256
|
+
statements:
|
|
257
|
+
- STEP: Complete checkout
|
|
258
|
+
statements:
|
|
259
|
+
- intent: Enter shipping address
|
|
260
|
+
- intent: Select payment method
|
|
261
|
+
- intent: Click Place Order
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
**Rules:**
|
|
265
|
+
- `STEP` (string, required): Description of what this group does.
|
|
266
|
+
- `statements` (array, required): Child statements (any type, including nested STEPs).
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
### 4.6 IF_ELSE
|
|
271
|
+
|
|
272
|
+
Conditional execution with an optional ELSE branch.
|
|
273
|
+
|
|
274
|
+
**Syntax — AI condition (default):**
|
|
275
|
+
|
|
276
|
+
```yaml
|
|
277
|
+
statements:
|
|
278
|
+
- IF: cookie consent dialog is visible
|
|
279
|
+
THEN:
|
|
280
|
+
- intent: Click Accept All
|
|
281
|
+
ELSE:
|
|
282
|
+
- VERIFY: no cookie dialog blocking
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
**Syntax — JavaScript condition:**
|
|
286
|
+
|
|
287
|
+
```yaml
|
|
288
|
+
statements:
|
|
289
|
+
- IF: "js: (await page.locator('.modal').count()) > 0"
|
|
290
|
+
THEN:
|
|
291
|
+
- intent: Close the modal
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
**Condition types:**
|
|
295
|
+
|
|
296
|
+
| Prefix | Type | Evaluation |
|
|
297
|
+
|---|---|---|
|
|
298
|
+
| *(none)* | `AI_MODE` | Natural language, evaluated by the AI agent at runtime |
|
|
299
|
+
| `js:` | `JS_CODE` | Inline Playwright expression, evaluated in the test context (Node.js). Must evaluate to truthy/falsy. |
|
|
300
|
+
|
|
301
|
+
A `js:` condition is a single **expression**, not a statement block — it is inlined verbatim into the transpiled Playwright test (`if (<expr>)`, `while (<expr>)`, or a polled predicate), so it must evaluate to truthy/falsy. It runs in the test context (Node.js) with the same scope as [Code](#48-code) statements (`page`, `expect`, `agent`), and `await` is allowed. Bare `document`/`window` are **not** in scope — use `page.locator(...)` probes, or `page.evaluate()` for browser-side DOM access. This applies to every `js:` condition position: `IF:`, `WHILE:`, and `WAIT_UNTIL:`. See [The `js:` Key — One Model](#411-the-js-key--one-model) for how conditions differ from the other `js:` surfaces.
|
|
302
|
+
|
|
303
|
+
**Rules:**
|
|
304
|
+
- `IF` (string, required): Condition expression.
|
|
305
|
+
- `THEN` (array, required): Statements to execute if condition is true.
|
|
306
|
+
- `ELSE` (array, optional): Statements to execute if condition is false.
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
### 4.7 WHILE_LOOP
|
|
311
|
+
|
|
312
|
+
Repeats statements until the condition is false or timeout is exceeded.
|
|
313
|
+
|
|
314
|
+
**Syntax:**
|
|
315
|
+
|
|
316
|
+
```yaml
|
|
317
|
+
statements:
|
|
318
|
+
- WHILE: there are more pages of results
|
|
319
|
+
DO:
|
|
320
|
+
- intent: Click the Next button
|
|
321
|
+
- VERIFY: new results loaded
|
|
322
|
+
timeout_ms: 60000
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
**Syntax — JavaScript condition:**
|
|
326
|
+
|
|
327
|
+
```yaml
|
|
328
|
+
statements:
|
|
329
|
+
- WHILE: "js: (await page.locator('.item').count()) < 10"
|
|
330
|
+
DO:
|
|
331
|
+
- intent: Scroll down
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
**Rules:**
|
|
335
|
+
- `WHILE` (string, required): Condition expression (same `AI_MODE`/`JS_CODE` rules as IF_ELSE).
|
|
336
|
+
- `DO` (array, required): Statements to execute each iteration.
|
|
337
|
+
- `timeout_ms` (number, optional): Maximum loop duration. Default: `180000` (3 minutes).
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
### 4.8 Code
|
|
342
|
+
|
|
343
|
+
The escape hatch for inline Playwright code that doesn't map to a named action — network mocking, localStorage manipulation, and other page-level scripting. A code statement is a `js:` body, optionally labeled with a `description:` (what the code does). Always write the `description:` — it's optional only so tools can round-trip code blocks, but it makes reports readable.
|
|
344
|
+
|
|
345
|
+
**No self-healing.** Unlike an ACTION, a code statement runs its `js` verbatim; if it fails, it fails. The `description` is informational only — it is **not** a re-resolvable intent.
|
|
346
|
+
|
|
347
|
+
**Syntax — single-line:**
|
|
348
|
+
|
|
349
|
+
```yaml
|
|
350
|
+
statements:
|
|
351
|
+
- description: Abort all API requests
|
|
352
|
+
js: "await page.route('**/api', r => r.abort())"
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
**Syntax — multiline (block scalar):**
|
|
356
|
+
|
|
357
|
+
```yaml
|
|
358
|
+
statements:
|
|
359
|
+
- description: Mock the users API to return a single user
|
|
360
|
+
js: |
|
|
361
|
+
await page.route('**/api/users', (route) => route.fulfill({
|
|
362
|
+
status: 200,
|
|
363
|
+
body: JSON.stringify([{ name: 'John' }]),
|
|
364
|
+
}));
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
**Fields:**
|
|
368
|
+
|
|
369
|
+
| Field | Type | Required | Description |
|
|
370
|
+
|---|---|---|---|
|
|
371
|
+
| `description` | `string` | No | What the code does. Labels the step; informational only (no self-healing). Recommended for readable reports; defaults to a generic label if omitted. |
|
|
372
|
+
| `js` | `string` | Yes | Complete, executable Playwright code (single line or block scalar). |
|
|
373
|
+
|
|
374
|
+
**Execution context:**
|
|
375
|
+
|
|
376
|
+
Code runs in the Playwright test context (Node.js). Use `page.evaluate()` for browser-context code.
|
|
377
|
+
|
|
378
|
+
The following are in scope:
|
|
379
|
+
|
|
380
|
+
| Identifier | Description |
|
|
381
|
+
|---|---|
|
|
382
|
+
| `page` | Playwright `Page` |
|
|
383
|
+
| `expect` | Playwright assertion library |
|
|
384
|
+
| `agent` | Shiplight `WebAgent` — see common methods below |
|
|
385
|
+
| `testContext` | The runtime variable store (same store as `{{variableName}}` in YAML). Use `.get(key)` / `.set(key, value)` or property-style access. |
|
|
386
|
+
| `request` | Playwright `APIRequestContext` — available when any statement in the file passes `request` as a function arg |
|
|
387
|
+
|
|
388
|
+
`agent` common methods:
|
|
389
|
+
|
|
390
|
+
```javascript
|
|
391
|
+
await agent.assert(page, "The shopping cart shows 3 items");
|
|
392
|
+
await agent.execute(page, "Click the Submit button");
|
|
393
|
+
await agent.extract(page, "the order confirmation number", "orderNumber");
|
|
394
|
+
await agent.waitForDownloadComplete(page, 10);
|
|
395
|
+
const filePath = agent.getRecentDownloadedFilePath();
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
**Importing packages** — use dynamic import (static imports are not supported):
|
|
399
|
+
|
|
400
|
+
```javascript
|
|
401
|
+
const fs = await import("node:fs");
|
|
402
|
+
const { v4: uuidv4 } = await import("uuid");
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
**Other notes:**
|
|
406
|
+
- `js:` is meaningful only as a standalone code statement (`description:` + `js:`) or as a `VERIFY:` assertion cache. On any other `action:` statement, `js:` is ignored.
|
|
407
|
+
- The debugger shows only the `js:` body; `description:` is rendered separately. If you copy a snippet from the debugger into a YAML file, re-add a `description:` — otherwise the label defaults to `Code block`.
|
|
408
|
+
|
|
409
|
+
### 4.9 WAIT_UNTIL (Shorthand)
|
|
410
|
+
|
|
411
|
+
Smart wait — repeatedly checks a condition until it's met or the timeout expires. The condition can be **natural language** (checked by the AI agent) or a **JavaScript expression** (checked in-process, no model calls), using the same `js:` prefix convention as [IF_ELSE](#46-if_else) and [WHILE_LOOP](#47-while_loop).
|
|
412
|
+
|
|
413
|
+
**WAIT_UNTIL synchronizes — it never fails the test.** It is an optimization of a fixed `WAIT:`: when the condition is met the test moves on early; when the timeout expires the test still continues, and the step result records a warning saying the condition was not met (or that the expression never evaluated cleanly). To *assert* that something holds, use `VERIFY:` — a wait is not a correctness gate.
|
|
414
|
+
|
|
415
|
+
**Syntax — AI condition (default):**
|
|
416
|
+
|
|
417
|
+
```yaml
|
|
418
|
+
statements:
|
|
419
|
+
- WAIT_UNTIL: Dashboard data has finished loading
|
|
420
|
+
timeout_seconds: 10
|
|
421
|
+
|
|
422
|
+
- WAIT_UNTIL: Spinner has disappeared
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
**Syntax — JS condition with intent (preferred):**
|
|
426
|
+
|
|
427
|
+
```yaml
|
|
428
|
+
statements:
|
|
429
|
+
- WAIT_UNTIL: The dashboard has finished loading
|
|
430
|
+
js: "(await page.locator('.spinner').count()) === 0"
|
|
431
|
+
timeout_seconds: 10
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
**Syntax — bare JS condition (legacy shorthand, no intent):**
|
|
435
|
+
|
|
436
|
+
```yaml
|
|
437
|
+
statements:
|
|
438
|
+
- WAIT_UNTIL: "js: (await page.locator('.result-row').count()) >= 10"
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
**Semantics:**
|
|
442
|
+
|
|
443
|
+
| Form | Behavior |
|
|
444
|
+
|---|---|
|
|
445
|
+
| Natural language only | AI polls the condition. Each check is a model call (~5-15s). |
|
|
446
|
+
| Natural language + sibling `js:` | The `js:` expression is polled exclusively, in-process (~4×/second), no model calls. The natural language is the label shown in reports and the source for regenerating a stale expression at authoring time. **No AI fallback at runtime.** |
|
|
447
|
+
| `"js: ..."` prefix | Same polling as above, without a label. Readable for round-trips, but discouraged for authoring — prefer the sibling form. |
|
|
448
|
+
|
|
449
|
+
Unlike `VERIFY:` (where `js:` is a cache and the AI re-checks the assertion when it throws), a WAIT_UNTIL `js:` never falls back: a wait has no failure signal to fall back on — falsy means "keep waiting", and a stale selector turning truthy looks like success. Repair happens at authoring time, from the preserved intent.
|
|
450
|
+
|
|
451
|
+
It is an error to combine both JS forms (a `"js: ..."`-prefixed condition plus a sibling `js:` key).
|
|
452
|
+
|
|
453
|
+
| Key | Type | Default | Description |
|
|
454
|
+
|---|---|---|---|
|
|
455
|
+
| `WAIT_UNTIL` | `string` | *(required)* | The condition. Natural language (the intent when `js:` is present), or a legacy `js:`-prefixed expression. |
|
|
456
|
+
| `js` | `string` | — | JavaScript expression polled in place of the AI check. Single expression, must evaluate to truthy/falsy. |
|
|
457
|
+
| `timeout_seconds` | `number` | `60` | Maximum seconds to wait before continuing (with a warning in the step result). Capped at 300 (applies to both AI and `js:` waits). |
|
|
458
|
+
|
|
459
|
+
**Which to use:**
|
|
460
|
+
- **Prefer the intent + `js:` form** for simple DOM/state checks — an element appearing or disappearing, a count reaching a threshold, a class toggling. It is polled cheaply with **no model calls**, so it's far faster and cheaper than an AI wait, and the intent keeps the step readable. An AI check takes 5–15 seconds *and* a model call each poll.
|
|
461
|
+
- **Use natural language alone** when the condition is semantic ("the order summary looks correct"), when there's no reliable selector, or when the DOM may drift and you want the check to self-heal.
|
|
462
|
+
|
|
463
|
+
**JavaScript execution context:**
|
|
464
|
+
- The expression runs in the Playwright test context (Node.js) with the same scope as [Code](#48-code) statements — `page`, `expect`, `agent` are in scope, and `await` is allowed (e.g. `await page.locator(...).count()`). Use `page.evaluate()` for browser-context code. It must evaluate to truthy/falsy.
|
|
465
|
+
|
|
466
|
+
**Notes:**
|
|
467
|
+
- Each AI condition check can take 5–15 seconds. For short fixed pauses, use `WAIT:` instead.
|
|
468
|
+
- **A `js:` wait does not self-heal at runtime.** If its selector goes stale, the expression can turn truthy immediately — the wait ends early without having synchronized anything, and a later step flakes. When a selector may drift, prefer natural language — or use the intent + `js:` form, whose preserved intent lets an agent regenerate the expression at authoring time.
|
|
469
|
+
- **A broken expression degrades to a fixed wait.** If the expression throws on every poll (e.g. it references a browser-only global like `document` in the Node test context) or fails to parse, the wait runs the full timeout and continues; the step result's warning names the error (e.g. "never evaluated successfully … document is not defined"). `shiplight transpile` catches syntax errors at authoring time, but only runtime can catch a bad reference.
|
|
470
|
+
- **The predicate must return truthy/falsy — not a Playwright wait.** `js: await page.locator('.spinner').waitFor({ state: 'detached' })` resolves to `undefined` (falsy), so the poll loop never sees "met" and waits the full timeout. Use a boolean-returning check instead: `js: (await page.locator('.spinner').count()) === 0`.
|
|
471
|
+
- **Use fast, non-retrying probes** — `count()`, `isVisible()`, or a `page.evaluate()` returning a boolean. An `expect()` assertion auto-retries internally (up to ~5s) and *throws* instead of returning a boolean, which fights the poll loop and can overshoot a short `timeout_seconds`.
|
|
472
|
+
|
|
473
|
+
### 4.10 WAIT (Shorthand)
|
|
474
|
+
|
|
475
|
+
Fixed duration wait, use for short durations.
|
|
476
|
+
|
|
477
|
+
**Syntax:**
|
|
478
|
+
|
|
479
|
+
```yaml
|
|
480
|
+
statements:
|
|
481
|
+
- WAIT: Wait for animation to complete
|
|
482
|
+
seconds: 3
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
| Key | Type | Default | Description |
|
|
486
|
+
|---|---|---|---|
|
|
487
|
+
| `WAIT` | `string` | — | Optional intent describing why the wait is needed |
|
|
488
|
+
| `seconds` | `number` | `3` | Number of seconds to wait |
|
|
489
|
+
|
|
490
|
+
### 4.11 The `js:` Key — One Model
|
|
491
|
+
|
|
492
|
+
Wherever it appears, `js:` means the same thing: **run this Playwright code in the test context (Node.js) instead of asking the AI.** The scope is always the same — `page`, `expect`, and `agent` are available, `await` is allowed, and `document`/`window` are **not** defined (browser-side state must go through `page.evaluate(() => ...)`). What varies by statement type is the form of the code, the role of the accompanying natural language, and what happens when the JS fails:
|
|
493
|
+
|
|
494
|
+
| Statement | Natural language is… | `js:` form | When the JS fails | Self-heals at runtime |
|
|
495
|
+
|---|---|---|---|---|
|
|
496
|
+
| [Code](#48-code) (`description:` + `js:`) | label only | statement block | test fails | No |
|
|
497
|
+
| [VERIFY](#43-verify-shorthand) + `js:` | the assertion — AI fallback intent | assertion statement | AI re-evaluates the natural-language assertion | **Yes** |
|
|
498
|
+
| [IF](#46-if_else) / [WHILE](#47-while_loop) `"js: ..."` | *(absent)* | single expression | a throw fails the test; falsy just takes the other branch / ends the loop | No |
|
|
499
|
+
| [WAIT_UNTIL](#49-wait_until-shorthand) + `js:` | the intent — label + regeneration source (absent in the legacy `"js: ..."` prefix form) | single expression | never fails — warning in the step result, test continues at timeout | No at runtime; regenerate from the intent at authoring time |
|
|
500
|
+
|
|
501
|
+
**Why only VERIFY falls back to AI:** fallback exists only where failure is detectable at runtime. An assertion *throws* when it is wrong, so the runtime knows to re-check the intent. A wait cannot distinguish "not yet" from "never", and a stale selector can turn a wait predicate truthy instantly — there is no failure signal to fall back on. For waits and conditions, the repair path is authoring-time: fix or regenerate the expression.
|
|
502
|
+
|
|
503
|
+
---
|
|
504
|
+
|
|
505
|
+
## 5. Templates
|
|
506
|
+
|
|
507
|
+
Templates extract reusable statement groups into separate YAML files.
|
|
508
|
+
|
|
509
|
+
### 5.1 Template File Format
|
|
510
|
+
|
|
511
|
+
```yaml
|
|
512
|
+
params:
|
|
513
|
+
- username
|
|
514
|
+
- password
|
|
515
|
+
statements:
|
|
516
|
+
- intent: Enter username
|
|
517
|
+
action: input_text
|
|
518
|
+
locator: "getByPlaceholder('Username')"
|
|
519
|
+
text: "<<username>>"
|
|
520
|
+
- intent: Enter password
|
|
521
|
+
action: input_text
|
|
522
|
+
locator: "getByPlaceholder('Password')"
|
|
523
|
+
text: "<<password>>"
|
|
524
|
+
- intent: Click login
|
|
525
|
+
action: click
|
|
526
|
+
locator: "getByRole('button', { name: 'Log in' })"
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
### 5.2 Using Templates
|
|
530
|
+
|
|
531
|
+
```yaml
|
|
532
|
+
statements:
|
|
533
|
+
- template: ./templates/login.yaml
|
|
534
|
+
params:
|
|
535
|
+
username: admin@test.com
|
|
536
|
+
password: "{{TEST_PASSWORD}}"
|
|
537
|
+
- VERIFY: Dashboard is visible
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
### 5.3 Template Rules
|
|
541
|
+
|
|
542
|
+
| Rule | Detail |
|
|
543
|
+
|---|---|
|
|
544
|
+
| Path resolution | Relative to the importing YAML file |
|
|
545
|
+
| Required params | All params listed in the template's `params` array must be provided |
|
|
546
|
+
| Substitution | `<<paramName>>` in template statements replaced with provided values |
|
|
547
|
+
| Nesting | Templates can reference other templates (max depth: **5**) |
|
|
548
|
+
| Circular references | Detected and rejected with an error |
|
|
549
|
+
| Inlining | Template statements are inlined — the `template:` reference itself is not a statement type |
|
|
550
|
+
| Cache invalidation | Changes to template files trigger re-transpilation of importing test files |
|
|
551
|
+
|
|
552
|
+
---
|
|
553
|
+
|
|
554
|
+
## 6. Functions
|
|
555
|
+
|
|
556
|
+
Functions let you call custom TypeScript/JavaScript code from YAML tests. Like templates, functions are a reuse mechanism — but while templates inline YAML statements at compile time, functions import and call code at runtime.
|
|
557
|
+
|
|
558
|
+
### 6.1 Syntax
|
|
559
|
+
|
|
560
|
+
```yaml
|
|
561
|
+
statements:
|
|
562
|
+
- intent: Greet the user
|
|
563
|
+
call: "helpers/utils.ts#greet_user"
|
|
564
|
+
args: [page, "hello"]
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
The `call` field is all that's needed — no `action: function` required. The transpiler infers it's a function action from the `call` key.
|
|
568
|
+
|
|
569
|
+
### 6.2 Fields
|
|
570
|
+
|
|
571
|
+
| Field | Type | Required | Description |
|
|
572
|
+
|---|---|---|---|
|
|
573
|
+
| `intent` | `string` | Yes | Human-readable intent (used for self-healing). |
|
|
574
|
+
| `call` | `string` | Yes | `filePath#exportName` reference. Bare paths (e.g. `helpers/auth.ts`) are resolved relative to the project root; explicitly-relative paths (`./helpers/auth.ts`, `../helpers/auth.ts`) are resolved relative to the YAML file's directory. Absolute paths are rejected with a runtime error. |
|
|
575
|
+
| `args` | `string[]` | No | Arguments to pass to the function. Reads like the function's call signature. |
|
|
576
|
+
|
|
577
|
+
### 6.3 Function File Format
|
|
578
|
+
|
|
579
|
+
Function names must be **snake_case** (e.g. `clear_cart`, not `clearCart`).
|
|
580
|
+
|
|
581
|
+
```typescript
|
|
582
|
+
// helpers/cart.ts
|
|
583
|
+
import { Page } from '@playwright/test';
|
|
584
|
+
|
|
585
|
+
export async function clear_cart(page: Page): Promise<void> {
|
|
586
|
+
// actual code here
|
|
587
|
+
}
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
### 6.4 Argument Value Rules
|
|
591
|
+
|
|
592
|
+
Each value in `args` is transpiled based on what it looks like:
|
|
593
|
+
|
|
594
|
+
| Value | Treatment | Example output |
|
|
595
|
+
|---|---|---|
|
|
596
|
+
| `page`, `request`, `testContext` | Passed as the Playwright/system object (unquoted) | `page` |
|
|
597
|
+
| `null`, `undefined`, `true`, `false` | Passed as JavaScript literals | `null` |
|
|
598
|
+
| Numeric strings | Passed as numbers | `42` |
|
|
599
|
+
| `$variableName` | Resolved from runtime variables | `agent.agentServices.readVariable('variableName')` |
|
|
600
|
+
| Anything else | Passed as a quoted string | `"hello"` |
|
|
601
|
+
|
|
602
|
+
### 6.5 Rules
|
|
603
|
+
|
|
604
|
+
| Rule | Detail |
|
|
605
|
+
|---|---|
|
|
606
|
+
| Path resolution | Bare paths (`helpers/auth.ts`) resolve relative to the project root; explicitly-relative paths (`./helpers/auth.ts`, `../helpers/auth.ts`) resolve relative to the YAML file's directory |
|
|
607
|
+
| Absolute paths | Rejected with a runtime error — not supported |
|
|
608
|
+
| Extension stripping | `.ts`/`.js`/`.mjs` is stripped in the generated import |
|
|
609
|
+
| Async | Functions should be `async` — they are always `await`ed |
|
|
610
|
+
| Statement type | Parsed as an `ACTION` — not a separate statement type |
|
|
611
|
+
|
|
612
|
+
---
|
|
613
|
+
|
|
614
|
+
## 7. Variables
|
|
615
|
+
|
|
616
|
+
Variables store and reuse dynamic values throughout test execution. They come from pre-defined config or are created dynamically during execution.
|
|
617
|
+
|
|
618
|
+
### 7.1 Variable Types
|
|
619
|
+
|
|
620
|
+
| Type | Scope | Description |
|
|
621
|
+
|---|---|---|
|
|
622
|
+
| Pre-defined | Per-project | Configured in `playwright.config.ts` under `use: { variables: { ... } }`. Loaded at test start. |
|
|
623
|
+
| Dynamic | Single test run | Created during execution (e.g., Extract action, `save_variable`, or natural language like "Save the order number to orderId"). Reset each run. |
|
|
624
|
+
|
|
625
|
+
### 7.2 Configuring Variables
|
|
626
|
+
|
|
627
|
+
Variables are defined in `playwright.config.ts` in the project's `use` block:
|
|
628
|
+
|
|
629
|
+
```ts
|
|
630
|
+
// playwright.config.ts
|
|
631
|
+
export default defineConfig({
|
|
632
|
+
...shiplightConfig(),
|
|
633
|
+
projects: [{
|
|
634
|
+
name: 'default',
|
|
635
|
+
use: {
|
|
636
|
+
variables: {
|
|
637
|
+
SAUCE_USER: 'standard_user',
|
|
638
|
+
SAUCE_PASS: { value: 'secret_sauce', sensitive: true },
|
|
639
|
+
},
|
|
640
|
+
},
|
|
641
|
+
}],
|
|
642
|
+
});
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
Sensitive variables (using `{ value, sensitive: true }`) are masked in logs and screenshots.
|
|
646
|
+
|
|
647
|
+
### 7.3 Using Variables in YAML
|
|
648
|
+
|
|
649
|
+
The `{{variableName}}` syntax references a variable. Variables are resolved at runtime — either from the project's pre-defined variables or from values saved during the test run.
|
|
650
|
+
|
|
651
|
+
```yaml
|
|
652
|
+
statements:
|
|
653
|
+
- intent: Enter email
|
|
654
|
+
action: input_text
|
|
655
|
+
locator: "getByPlaceholder('Email')"
|
|
656
|
+
text: "{{userEmail}}"
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
At runtime, `{{userEmail}}` is replaced with the actual value before the action executes.
|
|
660
|
+
|
|
661
|
+
### 7.4 Template Params vs Runtime Variables
|
|
662
|
+
|
|
663
|
+
- **Template params** use `<<paramName>>` syntax and are substituted at compile time during template expansion only.
|
|
664
|
+
- **Runtime variables** use `{{VAR}}` syntax and are resolved at runtime from the project's variables, parameterized test values, or values saved during the test.
|
|
665
|
+
- **Parameterized tests** use `{{VAR}}` syntax (same as runtime variables). Parameter values are set as runtime variables at the start of each test instance.
|
|
666
|
+
- The `<<param>>` syntax is reserved for template files only. In all other contexts (including parameterized tests), use `{{VAR}}`.
|
|
667
|
+
|
|
668
|
+
---
|
|
669
|
+
|
|
670
|
+
## 8. Teardown
|
|
671
|
+
|
|
672
|
+
Cleanup statements that execute in a `finally` block, even if the main test fails.
|
|
673
|
+
|
|
674
|
+
```yaml
|
|
675
|
+
goal: Create and verify user
|
|
676
|
+
statements:
|
|
677
|
+
- Create a new user named TestUser
|
|
678
|
+
- VERIFY: TestUser appears in the user list
|
|
679
|
+
teardown:
|
|
680
|
+
- Delete user TestUser
|
|
681
|
+
- VERIFY: TestUser is removed from the list
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
**Rules:**
|
|
685
|
+
- Teardown uses the same statement syntax as `statements` (DRAFT, ACTION, VERIFY, URL, STEP, IF_ELSE, WHILE_LOOP, code (`description:` + `js:`), template).
|
|
686
|
+
- Teardown always runs, regardless of test success or failure.
|
|
687
|
+
- Teardown is separate from lifecycle hooks (see [Lifecycle Hooks](#10-lifecycle-hooks)).
|
|
688
|
+
|
|
689
|
+
---
|
|
690
|
+
|
|
691
|
+
## 9. Test Suites
|
|
692
|
+
|
|
693
|
+
A suite groups multiple tests in a single file with shared configuration and lifecycle hooks. Suites transpile to a `test.describe()` block.
|
|
694
|
+
|
|
695
|
+
### 9.1 Suite Structure
|
|
696
|
+
|
|
697
|
+
```yaml
|
|
698
|
+
name: Inventory Browsing Suite
|
|
699
|
+
tags: [smoke, suite]
|
|
700
|
+
|
|
701
|
+
suite:
|
|
702
|
+
tests:
|
|
703
|
+
- name: Sort products by price
|
|
704
|
+
statements:
|
|
705
|
+
- intent: Sort by price low to high
|
|
706
|
+
action: select_dropdown_option
|
|
707
|
+
locator: "getByRole('combobox')"
|
|
708
|
+
option: "Price (low to high)"
|
|
709
|
+
- VERIFY: Products are sorted by price ascending
|
|
710
|
+
|
|
711
|
+
- name: View product details
|
|
712
|
+
statements:
|
|
713
|
+
- intent: Click the first product name
|
|
714
|
+
action: click
|
|
715
|
+
locator: "locator('.inventory_item_name').first()"
|
|
716
|
+
- VERIFY: The product detail page is displayed
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
### 9.2 Suite Keys
|
|
720
|
+
|
|
721
|
+
| Key | Type | Required | Description |
|
|
722
|
+
|---|---|---|---|
|
|
723
|
+
| `tests` | `SuiteTest[]` | Yes | Array of test definitions (at least one). |
|
|
724
|
+
| `beforeAll` | `Statement[]` | No | Runs once before all tests. See [Lifecycle Hooks](#10-lifecycle-hooks). |
|
|
725
|
+
| `afterAll` | `Statement[]` | No | Runs once after all tests. |
|
|
726
|
+
| `beforeEach` | `Statement[]` | No | Runs before each test. |
|
|
727
|
+
| `afterEach` | `Statement[]` | No | Runs after each test. |
|
|
728
|
+
|
|
729
|
+
### 9.3 Suite Test Keys
|
|
730
|
+
|
|
731
|
+
| Key | Type | Required | Description |
|
|
732
|
+
|---|---|---|---|
|
|
733
|
+
| `name` | `string` | Yes | Test name. Becomes the Playwright `test()` title. |
|
|
734
|
+
| `statements` | `Statement[]` | Yes | Ordered list of test steps. |
|
|
735
|
+
| `teardown` | `Statement[]` | No | Cleanup steps in a `finally` block for this test. |
|
|
736
|
+
| `parameters` | `ParameterSet[]` | No | Data sets for parameterized variants. See [Parameterized Tests](#11-parameterized-tests). |
|
|
737
|
+
| `timeout` | `number` | No | Per-test timeout in milliseconds. |
|
|
738
|
+
| `skip` | `boolean \| string` | No | Skip this test. `true` or a reason string. |
|
|
739
|
+
| `fail` | `boolean \| string` | No | Expected failure. `true` or a reason string. |
|
|
740
|
+
| `only` | `boolean` | No | Focus: run only this test. |
|
|
741
|
+
| `slow` | `boolean` | No | Triple the test timeout. |
|
|
742
|
+
|
|
743
|
+
### 9.4 Suite Transpilation Notes
|
|
744
|
+
|
|
745
|
+
- Suites always transpile to `test.describe.serial()` (sequential execution). For parallel tests, use separate test files.
|
|
746
|
+
- Tags go on the describe block name, not individual tests
|
|
747
|
+
- `test.use()` is placed outside the describe block
|
|
748
|
+
- Each test gets its own `test()` function with `{ page, agent }` fixtures
|
|
749
|
+
|
|
750
|
+
### 9.5 Validation Rules
|
|
751
|
+
|
|
752
|
+
- A file cannot have both `suite` and top-level `goal`/`statements`
|
|
753
|
+
- `suite.tests` must be a non-empty array
|
|
754
|
+
- Each suite test must have `name` (string) and `statements` (array)
|
|
755
|
+
|
|
756
|
+
---
|
|
757
|
+
|
|
758
|
+
## 10. Lifecycle Hooks
|
|
759
|
+
|
|
760
|
+
> **Note:** `beforeAll`/`afterAll` run without an agent. DRAFT and AI actions are silently skipped.
|
|
761
|
+
|
|
762
|
+
Hooks run setup/cleanup code around tests. They are available in both single-test and suite files.
|
|
763
|
+
|
|
764
|
+
### 10.1 Single-Test Hooks
|
|
765
|
+
|
|
766
|
+
Single-test files support `beforeEach` and `afterEach` at the top level:
|
|
767
|
+
|
|
768
|
+
```yaml
|
|
769
|
+
name: Login test
|
|
770
|
+
goal: Verify login flow
|
|
771
|
+
|
|
772
|
+
beforeEach:
|
|
773
|
+
- URL: https://app.example.com/login
|
|
774
|
+
|
|
775
|
+
afterEach:
|
|
776
|
+
- URL: https://app.example.com/logout
|
|
777
|
+
|
|
778
|
+
statements:
|
|
779
|
+
- intent: Enter credentials and submit
|
|
780
|
+
- VERIFY: dashboard is visible
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
### 10.2 Suite Hooks
|
|
784
|
+
|
|
785
|
+
Suite files support all four hooks inside the `suite` block:
|
|
786
|
+
|
|
787
|
+
```yaml
|
|
788
|
+
name: Cart Management Suite
|
|
789
|
+
tags: [e2e, hooks]
|
|
790
|
+
|
|
791
|
+
suite:
|
|
792
|
+
beforeAll:
|
|
793
|
+
- URL: /inventory.html
|
|
794
|
+
|
|
795
|
+
beforeEach:
|
|
796
|
+
- URL: /inventory.html
|
|
797
|
+
- intent: Add item to cart
|
|
798
|
+
action: click
|
|
799
|
+
locator: "locator('[data-test=\"add-to-cart-sauce-labs-backpack\"]')"
|
|
800
|
+
|
|
801
|
+
afterEach:
|
|
802
|
+
- intent: Remove item from cart
|
|
803
|
+
action: click
|
|
804
|
+
locator: "locator('[data-test=\"remove-sauce-labs-backpack\"]')"
|
|
805
|
+
|
|
806
|
+
afterAll:
|
|
807
|
+
- URL: /inventory.html
|
|
808
|
+
|
|
809
|
+
tests:
|
|
810
|
+
- name: Verify cart badge
|
|
811
|
+
statements:
|
|
812
|
+
- VERIFY: The shopping cart badge shows 1 item
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
### 10.3 Hook Fixture Scoping
|
|
816
|
+
|
|
817
|
+
| Hook | Fixture | Notes |
|
|
818
|
+
|---|---|---|
|
|
819
|
+
| `beforeEach` | `{ page, agent }` | Same page instance as the test. Full agent available. |
|
|
820
|
+
| `afterEach` | `{ page, agent }` | Same page instance as the test. Full agent available. |
|
|
821
|
+
| `beforeAll` | `{ browser }` | Worker-scoped. Creates a temporary page via `browser.newPage()`, closes it after hook completes. **No agent available.** |
|
|
822
|
+
| `afterAll` | `{ browser }` | Worker-scoped. Creates a temporary page via `browser.newPage()`, closes it after hook completes. **No agent available.** |
|
|
823
|
+
|
|
824
|
+
### 10.4 beforeAll/afterAll Limitations (noAgent Mode)
|
|
825
|
+
|
|
826
|
+
Since `beforeAll` and `afterAll` use worker-scoped fixtures without an agent, the following restrictions apply:
|
|
827
|
+
|
|
828
|
+
- **DRAFT statements** are skipped with a comment (they require the agent)
|
|
829
|
+
- **AI actions** (e.g., `verify`) are skipped with a comment
|
|
830
|
+
- **Navigation actions** (`go_to_url`, `go_back`, `go_forward`) are transpiled to direct Playwright calls (`page.goto()`, `page.goBack()`, `page.goForward()`)
|
|
831
|
+
- **DOM actions** with locators (`click`, `input_text`, `select_dropdown_option`) are transpiled to direct Playwright locator calls
|
|
832
|
+
|
|
833
|
+
### 10.5 Hook Statement Types
|
|
834
|
+
|
|
835
|
+
Hook statement arrays use the same syntax as regular `statements`. Templates are expanded in hooks. All statement types (DRAFT, ACTION, VERIFY, URL, STEP, IF_ELSE, WHILE_LOOP, code (`description:` + `js:`), template) are syntactically valid, though DRAFT and AI-based statements are skipped in `beforeAll`/`afterAll`.
|
|
836
|
+
|
|
837
|
+
---
|
|
838
|
+
|
|
839
|
+
## 11. Parameterized Tests
|
|
840
|
+
|
|
841
|
+
Parameters generate multiple test instances from data sets. Each parameter set produces a separate `test()` with its values set as runtime variables. Use `{{variableName}}` syntax in statements to reference parameter values — the same syntax used for runtime variables (see [Variables](#7-variables)).
|
|
842
|
+
|
|
843
|
+
### 11.1 Single-Test Parameters
|
|
844
|
+
|
|
845
|
+
```yaml
|
|
846
|
+
name: Search and verify product
|
|
847
|
+
tags: [e2e, parameterized]
|
|
848
|
+
|
|
849
|
+
parameters:
|
|
850
|
+
- name: backpack
|
|
851
|
+
values:
|
|
852
|
+
product_name: Sauce Labs Backpack
|
|
853
|
+
expected_price: "$29.99"
|
|
854
|
+
- name: bike light
|
|
855
|
+
values:
|
|
856
|
+
product_name: Sauce Labs Bike Light
|
|
857
|
+
expected_price: "$9.99"
|
|
858
|
+
|
|
859
|
+
statements:
|
|
860
|
+
- intent: Search for product
|
|
861
|
+
action: input_text
|
|
862
|
+
locator: "getByPlaceholder('Search')"
|
|
863
|
+
text: "{{product_name}}"
|
|
864
|
+
- VERIFY: "{{product_name}} is visible with price {{expected_price}}"
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
### 11.2 Suite Test Parameters
|
|
868
|
+
|
|
869
|
+
Individual tests within a suite can also have parameters:
|
|
870
|
+
|
|
871
|
+
```yaml
|
|
872
|
+
suite:
|
|
873
|
+
tests:
|
|
874
|
+
- name: Login with role
|
|
875
|
+
parameters:
|
|
876
|
+
- name: admin
|
|
877
|
+
values: { username: admin@test.com }
|
|
878
|
+
- name: editor
|
|
879
|
+
values: { username: editor@test.com }
|
|
880
|
+
statements:
|
|
881
|
+
- intent: "Enter {{username}}"
|
|
882
|
+
- VERIFY: logged in successfully
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
### 11.3 ParameterSet Structure
|
|
886
|
+
|
|
887
|
+
| Field | Type | Required | Description |
|
|
888
|
+
|---|---|---|---|
|
|
889
|
+
| `name` | `string` | Yes | Variant name. Appended to test title as `[name]`. |
|
|
890
|
+
| `values` | `Record<string, string>` | Yes | Key-value pairs. Keys become runtime variables referenced via `{{key}}`. |
|
|
891
|
+
|
|
892
|
+
### 11.4 How Parameters Work
|
|
893
|
+
|
|
894
|
+
- Each parameter set produces a separate test instance
|
|
895
|
+
- At the start of each test, parameter values are saved as runtime variables via `agent.agentServices.saveVariable()`
|
|
896
|
+
- `{{key}}` placeholders in statements are resolved at runtime from the variable store — the same mechanism used for pre-defined and dynamic variables
|
|
897
|
+
- Parameter variables can be overridden by `save_variable` actions during the test, and they coexist with pre-defined variables from `playwright.config.ts`
|
|
898
|
+
|
|
899
|
+
### 11.5 Validation Rules
|
|
900
|
+
|
|
901
|
+
- Each parameter set must have `name` (string) and `values` (object)
|
|
902
|
+
- `values` must be a non-empty object
|
|
903
|
+
- Parameter names should be unique within the `parameters` array
|
|
904
|
+
|
|
905
|
+
---
|
|
906
|
+
|
|
907
|
+
## 12. Complete Examples
|
|
908
|
+
|
|
909
|
+
### 12.1 Single-Test File
|
|
910
|
+
|
|
911
|
+
```yaml
|
|
912
|
+
test_case_id: 303
|
|
913
|
+
name: Checkout flow with login
|
|
914
|
+
tags: [e2e, checkout, critical]
|
|
915
|
+
|
|
916
|
+
use:
|
|
917
|
+
storageState: auth/user.json
|
|
918
|
+
viewport: { width: 1280, height: 720 }
|
|
919
|
+
|
|
920
|
+
goal: Complete checkout for authenticated user
|
|
921
|
+
|
|
922
|
+
statements:
|
|
923
|
+
# Template: reusable login flow
|
|
924
|
+
- template: ./templates/login.yaml
|
|
925
|
+
params:
|
|
926
|
+
email: "{{TEST_USER_EMAIL}}"
|
|
927
|
+
password: "{{TEST_USER_PASSWORD}}"
|
|
928
|
+
|
|
929
|
+
# Assertion
|
|
930
|
+
- VERIFY: Product catalog is visible
|
|
931
|
+
|
|
932
|
+
# DRAFT: AI resolves at runtime
|
|
933
|
+
- intent: Click on the first product
|
|
934
|
+
|
|
935
|
+
# ACTION: structured format
|
|
936
|
+
- intent: Click Add to Cart
|
|
937
|
+
action: click
|
|
938
|
+
locator: "getByRole('button', { name: 'Add to Cart' })"
|
|
939
|
+
|
|
940
|
+
# ACTION: structured format with extra params
|
|
941
|
+
- intent: Enter address
|
|
942
|
+
action: input_text
|
|
943
|
+
locator: "getByPlaceholder('Address')"
|
|
944
|
+
text: 123 Main St
|
|
945
|
+
|
|
946
|
+
# STEP: grouped actions
|
|
947
|
+
- STEP: Fill shipping info
|
|
948
|
+
statements:
|
|
949
|
+
- intent: Enter address
|
|
950
|
+
action: input_text
|
|
951
|
+
locator: "getByPlaceholder('Address')"
|
|
952
|
+
text: 123 Main St
|
|
953
|
+
- intent: Select shipping method
|
|
954
|
+
action: select_dropdown_option
|
|
955
|
+
locator: "getByRole('combobox', { name: 'Shipping' })"
|
|
956
|
+
option: Standard Shipping
|
|
957
|
+
|
|
958
|
+
# Conditional
|
|
959
|
+
- IF: promo code field is visible
|
|
960
|
+
THEN:
|
|
961
|
+
- intent: Enter promo code
|
|
962
|
+
action: input_text
|
|
963
|
+
locator: "getByPlaceholder('Promo Code')"
|
|
964
|
+
text: SAVE10
|
|
965
|
+
- intent: Click Apply
|
|
966
|
+
ELSE:
|
|
967
|
+
- VERIFY: no promo code field displayed
|
|
968
|
+
|
|
969
|
+
# Loop
|
|
970
|
+
- WHILE: there are more items to review
|
|
971
|
+
DO:
|
|
972
|
+
- intent: Scroll down
|
|
973
|
+
- VERIFY: next item is visible
|
|
974
|
+
timeout_ms: 60000
|
|
975
|
+
|
|
976
|
+
- intent: Click Place Order
|
|
977
|
+
- VERIFY: Order confirmation page is displayed
|
|
978
|
+
|
|
979
|
+
teardown:
|
|
980
|
+
- IF: Cancel Order button is visible
|
|
981
|
+
THEN:
|
|
982
|
+
- intent: Click Cancel Order
|
|
983
|
+
- intent: Click Confirm
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
### 12.2 Suite with Hooks
|
|
987
|
+
|
|
988
|
+
```yaml
|
|
989
|
+
name: Cart Management Suite
|
|
990
|
+
tags: [e2e, hooks]
|
|
991
|
+
|
|
992
|
+
suite:
|
|
993
|
+
beforeAll:
|
|
994
|
+
- URL: /inventory.html
|
|
995
|
+
|
|
996
|
+
beforeEach:
|
|
997
|
+
- URL: /inventory.html
|
|
998
|
+
- intent: Add Sauce Labs Backpack to cart
|
|
999
|
+
action: click
|
|
1000
|
+
locator: "locator('[data-test=\"add-to-cart-sauce-labs-backpack\"]')"
|
|
1001
|
+
|
|
1002
|
+
afterEach:
|
|
1003
|
+
- intent: Remove Backpack from cart if present
|
|
1004
|
+
action: click
|
|
1005
|
+
locator: "locator('[data-test=\"remove-sauce-labs-backpack\"]')"
|
|
1006
|
+
|
|
1007
|
+
afterAll:
|
|
1008
|
+
- URL: /inventory.html
|
|
1009
|
+
|
|
1010
|
+
tests:
|
|
1011
|
+
- name: Verify cart badge shows item count
|
|
1012
|
+
statements:
|
|
1013
|
+
- VERIFY: The shopping cart badge shows 1 item
|
|
1014
|
+
|
|
1015
|
+
- name: Verify remove button appears after adding to cart
|
|
1016
|
+
statements:
|
|
1017
|
+
- VERIFY: A Remove button is visible for Sauce Labs Backpack
|
|
1018
|
+
```
|
|
1019
|
+
|
|
1020
|
+
### 12.3 Parameterized Test
|
|
1021
|
+
|
|
1022
|
+
```yaml
|
|
1023
|
+
name: Search and verify product
|
|
1024
|
+
tags: [e2e, parameterized]
|
|
1025
|
+
|
|
1026
|
+
parameters:
|
|
1027
|
+
- name: backpack
|
|
1028
|
+
values:
|
|
1029
|
+
product_name: Sauce Labs Backpack
|
|
1030
|
+
expected_price: "$29.99"
|
|
1031
|
+
- name: bike light
|
|
1032
|
+
values:
|
|
1033
|
+
product_name: Sauce Labs Bike Light
|
|
1034
|
+
expected_price: "$9.99"
|
|
1035
|
+
|
|
1036
|
+
statements:
|
|
1037
|
+
- intent: Search for product
|
|
1038
|
+
action: input_text
|
|
1039
|
+
locator: "getByPlaceholder('Search')"
|
|
1040
|
+
text: "{{product_name}}"
|
|
1041
|
+
|
|
1042
|
+
- intent: Click search button
|
|
1043
|
+
action: click
|
|
1044
|
+
locator: "getByRole('button', { name: 'Search' })"
|
|
1045
|
+
|
|
1046
|
+
- VERIFY: "{{product_name}} is visible with price {{expected_price}}"
|
|
1047
|
+
```
|