testdriverai 6.0.29 → 6.0.30-canary.0fed7bc.0

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.
@@ -1,11 +1,13 @@
1
1
  ---
2
- title: Get Started with TestDriver & Playwright
3
- sidebarTitle: Playwright
4
- tag: NEW
5
- description: In this guide, you'll setup your TestDriver account, create a new Playwright project, and leverage TestDriver's AI to convert tests to natural language.
2
+ title: "Get Started with TestDriver & Playwright"
3
+ sidebarTitle: "Playwright"
4
+ tag: "NEW"
5
+ description: "In this guide, you'll setup your TestDriver account, create a new Playwright project, and leverage TestDriver's AI to convert tests to natural language."
6
6
  icon: "masks-theater"
7
7
  ---
8
8
 
9
+ ## Overview
10
+
9
11
  `@testdriver.ai/playwright` is a backwards-compatible wrapper around `@playwright/test` that uses TestDriver's Vision AI to:
10
12
 
11
13
  - Make [natural language assertions](#assertions-with-expect-tomatchprompt)
@@ -13,25 +15,43 @@ icon: "masks-theater"
13
15
  - [Perform actions](#performing-actions-with-testdriver-act) with a prompt
14
16
  - Test with an [automated agent](#agentic-tests-with-test-agent)
15
17
 
18
+ We'll be incrementally converting Playwright's example test from the sample code:
19
+
20
+ ```typescript tests/example.spec.ts icon=square-js
21
+ // Before
22
+ test("get started link", async ({ page, testdriver }) => {
23
+ await page.goto("https://playwright.dev/");
24
+ await testdriver(page).act("Click the 'Get started' link");
25
+ await expect(page).toMatchPrompt("'Installation' heading is visible");
26
+ });
27
+ ```
28
+
29
+ To using natural language with TestDriver:
30
+
31
+ ```typescript tests/example.spec.ts icon=square-js
32
+ // After
33
+ test.describe("get started link", () => {
34
+ test.beforeEach(async ({ page }) => page.goto("https://playwright.dev/"));
35
+ test.agent(`
36
+ - Click the 'Get started' link
37
+ - Verify the 'Installation' heading is visible
38
+ `);
39
+ });
40
+ ```
41
+
16
42
  ## Prerequisites
17
43
 
18
44
  <Steps>
19
45
  <Step title="Create a TestDriver Account">
20
- You will need a [TestDriver Pro](https://app.testdriver.ai/team) account ($20/month) to get an API key.
21
-
22
- <Card
23
- title="Sign Up for TestDriver"
24
- icon="user-plus"
25
- href="https://app.testdriver.ai/team"
26
- arrow
27
- horizontal
28
- />
46
+ You will need a [TestDriver Pro](https://app.testdriver.ai/team) account (\$20/month) to get an API key.
29
47
 
48
+ <Card title="Sign Up for TestDriver" icon="user-plus" horizontal href="https://app.testdriver.ai/team">
49
+
50
+ </Card>
30
51
  </Step>
31
52
  <Step title="Set up your environment">
32
-
33
53
  Copy your API key from [the TestDriver dashboard](https://app.testdriver.ai/team), and set it as an environment variable.
34
-
54
+
35
55
  <Tabs>
36
56
  <Tab title="macOS / Linux">
37
57
  ```bash Export an environment variable on macOS or Linux systems
@@ -39,9 +59,9 @@ icon: "masks-theater"
39
59
  ```
40
60
  </Tab>
41
61
  <Tab title="Windows">
42
- ```powershell Export an environment variable in PowerShell
43
- setx TD_API_KEY "your_api_key_here"
44
- ```
62
+ ```powershell Export an environment variable in PowerShell
63
+ setx TD_API_KEY "your_api_key_here"
64
+ ```
45
65
  </Tab>
46
66
  </Tabs>
47
67
  </Step>
@@ -51,13 +71,11 @@ icon: "masks-theater"
51
71
 
52
72
  <Steps>
53
73
  <Step title="Initialize Playwright">
54
-
55
74
  <Info>
56
75
  This is a condensed version of [Playwright's Installation Instructions](https://playwright.dev/docs/intro).
57
76
 
58
77
  **If you're new to Playwright, you should follow their guide first.**
59
78
  </Info>
60
-
61
79
  In an new folder or existing run:
62
80
 
63
81
  <Tabs>
@@ -77,7 +95,6 @@ icon: "masks-theater"
77
95
  ```
78
96
  </Tab>
79
97
  </Tabs>
80
-
81
98
  Select the following options when prompted:
82
99
 
83
100
  ```console
@@ -110,16 +127,13 @@ icon: "masks-theater"
110
127
  ```
111
128
  </Tab>
112
129
  </Tabs>
113
-
114
130
  </Step>
115
131
  </Steps>
116
132
 
117
133
  ## Setup `@testdriver.ai/playwright`
118
134
 
119
135
  <Steps>
120
-
121
136
  <Step title="Install TestDriver">
122
-
123
137
  `@testdriver.ai/playwright` as a backwards-compatible wrapper around `@playwright/test`:
124
138
 
125
139
  <Tabs>
@@ -139,11 +153,8 @@ icon: "masks-theater"
139
153
  ```
140
154
  </Tab>
141
155
  </Tabs>
142
-
143
156
  </Step>
144
-
145
157
  <Step title="Run Playwright">
146
-
147
158
  Before we start using TestDriver in our tests, run Playwright in [UI Mode](https://playwright.dev/docs/test-ui-mode):
148
159
 
149
160
  <Tabs>
@@ -163,22 +174,18 @@ icon: "masks-theater"
163
174
  ```
164
175
  </Tab>
165
176
  </Tabs>
166
-
167
177
  ![Playwright UI Mode](https://playwright.dev/assets/ideal-img/ui-mode.4e54d6b.3598.png)
168
178
 
169
179
  Clicking the ▶️ button should successfully run the tests in the UI,
170
180
  just as they did before with `playwright test` in the CLI.
171
-
172
181
  </Step>
173
-
174
182
  <Step title="Import TestDriver">
175
-
176
183
  For the sake of simplicity, we'll be working with one test file for now.
177
184
 
178
185
  Open `tests/example.spec.ts` in your editor & rename the `@playwright/test`
179
186
  import to `@testdriver.ai/playwright`:
180
187
 
181
- ```typescript icon="square-js" title="tests/example.spec.ts"
188
+ ```typescript tests/example.spec.ts icon=square-js
182
189
  import { test, expect } from '@playwright/test'; // [!code --]
183
190
  import { test, expect } from '@testdriver.ai/playwright'; // [!code ++]
184
191
  ```
@@ -188,9 +195,7 @@ icon: "masks-theater"
188
195
  <Tip>
189
196
  Click the <Icon icon="eye" /> button to automatically re-run tests on save.
190
197
  </Tip>
191
-
192
198
  </Step>
193
-
194
199
  </Steps>
195
200
 
196
201
  ## Usage
@@ -205,7 +210,7 @@ or even having an [agent](#agentic-tests-with-test-agent) test for you!
205
210
 
206
211
  Replace `toBeVisible` with `toMatchPrompt` to assert that the element is visible on the screen:
207
212
 
208
- ```typescript icon="square-js" title="tests/example.spec.ts"
213
+ ```typescript tests/example.spec.ts icon=square-js
209
214
  // [!code --:2]
210
215
  // Expects page to have a heading with the name of Installation.
211
216
  await expect(page.getByRole("heading", { name: "Installation" })).toBeVisible();
@@ -229,7 +234,7 @@ TestDriver can replace `data-testid`s, `getByRole`, and CSS selectors with natur
229
234
 
230
235
  First, update your test to get access to the `testdriver` fixture:
231
236
 
232
- ```typescript icon="square-js" title="tests/example.spec.ts"
237
+ ```typescript tests/example.spec.ts icon=square-js
233
238
  // [!code --]
234
239
  test('get started link', async ({ page, }) => {
235
240
  // [!code ++]
@@ -238,7 +243,7 @@ test('get started link', async ({ page, testdriver }) => {
238
243
 
239
244
  Then, replace `getByRole` with `testdriver.locate`:
240
245
 
241
- ```typescript icon="square-js" title="tests/example.spec.ts"
246
+ ```typescript tests/example.spec.ts icon=square-js
242
247
  test('get started link', async ({ page, testdriver }) => {
243
248
  await page.goto('https://playwright.dev/');
244
249
 
@@ -257,22 +262,21 @@ Now, our test uses natural language to both describe & locate the element.
257
262
  <Tip>
258
263
  In the example above, you can still use Playwright to assert that the element is indeed a link for accessibility:
259
264
 
260
- ```typescript icon="square-js" title="tests/example.spec.ts"
261
- const link = await testdriver(page).locate("Get started link");
262
- // [!code ++]
263
- expect(link).toHaveRole("link");
264
- await link.click();
265
- ```
266
-
267
- This way you can write user-centric tests _and_ validate the implementation.
265
+ ```typescript tests/example.spec.ts icon=square-js
266
+ const link = await testdriver(page).locate("Get started link");
267
+ // [!code ++]
268
+ expect(link).toHaveRole("link");
269
+ await link.click();
270
+ ```
268
271
 
272
+ This way you can write user-centric tests _and_ validate the implementation.
269
273
  </Tip>
270
274
 
271
275
  ### Performing actions with `testdriver.act`
272
276
 
273
277
  We can combine `locate` and `click` from the previous example into one line with `testdriver.act`:
274
278
 
275
- ```typescript icon="square-js" title="tests/example.spec.ts"
279
+ ```typescript tests/example.spec.ts icon=square-js
276
280
  test("get started link", async ({ page, testdriver }) => {
277
281
  await page.goto("https://playwright.dev/");
278
282
 
@@ -292,7 +296,7 @@ Now the test uses the page the way a user would!
292
296
 
293
297
  TestDriver can automatically perform the entire test for you with an AI agent:
294
298
 
295
- ```typescript icon="square-js" title="tests/example.spec.ts"
299
+ ```typescript tests/example.spec.ts icon=square-js
296
300
  // [!code --:6]
297
301
  test("get started link", async ({ page, testdriver }) => {
298
302
  await page.goto("https://playwright.dev/");
@@ -314,10 +318,7 @@ Instead of writing the test implementation, we've used [`test.describe`](https:/
314
318
  but replaced the `test` itself with `test.agent`.
315
319
 
316
320
  <Tip>
317
- Use
318
- [`test.beforEach`](https://playwright.dev/docs/api/class-test#test-after-each)
319
- to prepare the page for the agent (e.g.
320
- [`page.goto`](https://playwright.dev/docs/api/class-page#page-goto), calling
321
+ Use `test.beforeEach` to prepare the page for the agent (e.g. [`page.goto`](https://playwright.dev/docs/api/class-page#page-goto), calling
321
322
  an API to create a user). Use
322
323
  [`test.afterEach`](https://playwright.dev/docs/api/class-test#test-after-each)
323
324
  to clean up after the agent (e.g. `page.close`) or perform additional logic
@@ -326,4 +327,4 @@ but replaced the `test` itself with `test.agent`.
326
327
 
327
328
  ## Conclusion
328
329
 
329
- With `@testdriver.ai/playwright`, you can use as much or as little of Playwright's _or_ TestDriver's API as you need to validate correctness. It's up to you!
330
+ With `@testdriver.ai/playwright`, you can use as much or as little of Playwright's _or_ TestDriver's API as you need to validate correctness. It's up to you!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testdriverai",
3
- "version": "6.0.29",
3
+ "version": "6.0.30-canary.0fed7bc.0",
4
4
  "description": "Next generation autonomous AI agent for end-to-end testing of web & desktop",
5
5
  "main": "index.js",
6
6
  "bin": {