testdriverai 6.0.30-canary.ff65ed2.0 → 6.0.31-canary.b5e0ecb.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,8 +1,8 @@
|
|
|
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
|
|
|
@@ -15,21 +15,25 @@ icon: "masks-theater"
|
|
|
15
15
|
- [Perform actions](#performing-actions-with-testdriver-act) with a prompt
|
|
16
16
|
- Test with an [automated agent](#agentic-tests-with-test-agent)
|
|
17
17
|
|
|
18
|
-
We'll be incrementally converting Playwright's example test from
|
|
18
|
+
We'll be incrementally converting Playwright's example test from the sample code:
|
|
19
19
|
|
|
20
|
-
```typescript
|
|
20
|
+
```typescript tests/example.spec.ts icon=square-js
|
|
21
21
|
// Before
|
|
22
|
-
test("get started link", async ({ page
|
|
22
|
+
test("get started link", async ({ page }) => {
|
|
23
23
|
await page.goto("https://playwright.dev/");
|
|
24
|
-
await
|
|
25
|
-
await expect(
|
|
24
|
+
await page.getByRole("link", { name: "Get started" }).click();
|
|
25
|
+
await expect(
|
|
26
|
+
page.getByRole("heading", { name: "Installation" }),
|
|
27
|
+
).toBeVisible();
|
|
26
28
|
});
|
|
27
29
|
```
|
|
28
30
|
|
|
29
|
-
To using natural language:
|
|
31
|
+
To using natural language with TestDriver:
|
|
30
32
|
|
|
31
|
-
```typescript
|
|
33
|
+
```typescript tests/example.spec.ts icon=square-js
|
|
32
34
|
// After
|
|
35
|
+
import { test } from "@testdriver.ai/playwright";
|
|
36
|
+
|
|
33
37
|
test.describe("get started link", () => {
|
|
34
38
|
test.beforeEach(async ({ page }) => page.goto("https://playwright.dev/"));
|
|
35
39
|
test.agent(`
|
|
@@ -43,21 +47,12 @@ test.describe("get started link", () => {
|
|
|
43
47
|
|
|
44
48
|
<Steps>
|
|
45
49
|
<Step title="Create a TestDriver Account">
|
|
46
|
-
You will need a [TestDriver Pro](https://app.testdriver.ai/team) account (
|
|
47
|
-
|
|
48
|
-
<Card
|
|
49
|
-
title="Sign Up for TestDriver"
|
|
50
|
-
icon="user-plus"
|
|
51
|
-
href="https://app.testdriver.ai/team"
|
|
52
|
-
arrow
|
|
53
|
-
horizontal
|
|
54
|
-
/>
|
|
55
|
-
|
|
50
|
+
You will need a [TestDriver Pro](https://app.testdriver.ai/team) account (\$20/month) to get an API key.
|
|
51
|
+
<Card title="Sign Up for TestDriver" icon="user-plus" horizontal href="https://app.testdriver.ai/team" />
|
|
56
52
|
</Step>
|
|
57
53
|
<Step title="Set up your environment">
|
|
58
|
-
|
|
59
54
|
Copy your API key from [the TestDriver dashboard](https://app.testdriver.ai/team), and set it as an environment variable.
|
|
60
|
-
|
|
55
|
+
|
|
61
56
|
<Tabs>
|
|
62
57
|
<Tab title="macOS / Linux">
|
|
63
58
|
```bash Export an environment variable on macOS or Linux systems
|
|
@@ -65,11 +60,12 @@ test.describe("get started link", () => {
|
|
|
65
60
|
```
|
|
66
61
|
</Tab>
|
|
67
62
|
<Tab title="Windows">
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
63
|
+
```powershell Export an environment variable in PowerShell
|
|
64
|
+
setx TD_API_KEY "your_api_key_here"
|
|
65
|
+
```
|
|
71
66
|
</Tab>
|
|
72
67
|
</Tabs>
|
|
68
|
+
|
|
73
69
|
</Step>
|
|
74
70
|
</Steps>
|
|
75
71
|
|
|
@@ -77,14 +73,12 @@ test.describe("get started link", () => {
|
|
|
77
73
|
|
|
78
74
|
<Steps>
|
|
79
75
|
<Step title="Initialize Playwright">
|
|
80
|
-
|
|
81
76
|
<Info>
|
|
82
77
|
This is a condensed version of [Playwright's Installation Instructions](https://playwright.dev/docs/intro).
|
|
83
78
|
|
|
84
79
|
**If you're new to Playwright, you should follow their guide first.**
|
|
85
80
|
</Info>
|
|
86
|
-
|
|
87
|
-
In an new folder or existing run:
|
|
81
|
+
In a new folder or an existing, run:
|
|
88
82
|
|
|
89
83
|
<Tabs>
|
|
90
84
|
<Tab title="npm">
|
|
@@ -103,7 +97,6 @@ test.describe("get started link", () => {
|
|
|
103
97
|
```
|
|
104
98
|
</Tab>
|
|
105
99
|
</Tabs>
|
|
106
|
-
|
|
107
100
|
Select the following options when prompted:
|
|
108
101
|
|
|
109
102
|
```console
|
|
@@ -143,9 +136,7 @@ test.describe("get started link", () => {
|
|
|
143
136
|
## Setup `@testdriver.ai/playwright`
|
|
144
137
|
|
|
145
138
|
<Steps>
|
|
146
|
-
|
|
147
139
|
<Step title="Install TestDriver">
|
|
148
|
-
|
|
149
140
|
`@testdriver.ai/playwright` as a backwards-compatible wrapper around `@playwright/test`:
|
|
150
141
|
|
|
151
142
|
<Tabs>
|
|
@@ -167,9 +158,7 @@ test.describe("get started link", () => {
|
|
|
167
158
|
</Tabs>
|
|
168
159
|
|
|
169
160
|
</Step>
|
|
170
|
-
|
|
171
161
|
<Step title="Run Playwright">
|
|
172
|
-
|
|
173
162
|
Before we start using TestDriver in our tests, run Playwright in [UI Mode](https://playwright.dev/docs/test-ui-mode):
|
|
174
163
|
|
|
175
164
|
<Tabs>
|
|
@@ -189,22 +178,19 @@ test.describe("get started link", () => {
|
|
|
189
178
|
```
|
|
190
179
|
</Tab>
|
|
191
180
|
</Tabs>
|
|
192
|
-
|
|
193
181
|

|
|
194
182
|
|
|
195
183
|
Clicking the ▶️ button should successfully run the tests in the UI,
|
|
196
184
|
just as they did before with `playwright test` in the CLI.
|
|
197
185
|
|
|
198
186
|
</Step>
|
|
199
|
-
|
|
200
187
|
<Step title="Import TestDriver">
|
|
201
|
-
|
|
202
188
|
For the sake of simplicity, we'll be working with one test file for now.
|
|
203
189
|
|
|
204
190
|
Open `tests/example.spec.ts` in your editor & rename the `@playwright/test`
|
|
205
191
|
import to `@testdriver.ai/playwright`:
|
|
206
192
|
|
|
207
|
-
```typescript
|
|
193
|
+
```typescript tests/example.spec.ts icon=square-js
|
|
208
194
|
import { test, expect } from '@playwright/test'; // [!code --]
|
|
209
195
|
import { test, expect } from '@testdriver.ai/playwright'; // [!code ++]
|
|
210
196
|
```
|
|
@@ -216,7 +202,6 @@ test.describe("get started link", () => {
|
|
|
216
202
|
</Tip>
|
|
217
203
|
|
|
218
204
|
</Step>
|
|
219
|
-
|
|
220
205
|
</Steps>
|
|
221
206
|
|
|
222
207
|
## Usage
|
|
@@ -231,7 +216,7 @@ or even having an [agent](#agentic-tests-with-test-agent) test for you!
|
|
|
231
216
|
|
|
232
217
|
Replace `toBeVisible` with `toMatchPrompt` to assert that the element is visible on the screen:
|
|
233
218
|
|
|
234
|
-
```typescript
|
|
219
|
+
```typescript tests/example.spec.ts icon=square-js
|
|
235
220
|
// [!code --:2]
|
|
236
221
|
// Expects page to have a heading with the name of Installation.
|
|
237
222
|
await expect(page.getByRole("heading", { name: "Installation" })).toBeVisible();
|
|
@@ -255,7 +240,7 @@ TestDriver can replace `data-testid`s, `getByRole`, and CSS selectors with natur
|
|
|
255
240
|
|
|
256
241
|
First, update your test to get access to the `testdriver` fixture:
|
|
257
242
|
|
|
258
|
-
```typescript
|
|
243
|
+
```typescript tests/example.spec.ts icon=square-js
|
|
259
244
|
// [!code --]
|
|
260
245
|
test('get started link', async ({ page, }) => {
|
|
261
246
|
// [!code ++]
|
|
@@ -264,7 +249,7 @@ test('get started link', async ({ page, testdriver }) => {
|
|
|
264
249
|
|
|
265
250
|
Then, replace `getByRole` with `testdriver.locate`:
|
|
266
251
|
|
|
267
|
-
```typescript
|
|
252
|
+
```typescript tests/example.spec.ts icon=square-js
|
|
268
253
|
test('get started link', async ({ page, testdriver }) => {
|
|
269
254
|
await page.goto('https://playwright.dev/');
|
|
270
255
|
|
|
@@ -283,7 +268,7 @@ Now, our test uses natural language to both describe & locate the element.
|
|
|
283
268
|
<Tip>
|
|
284
269
|
In the example above, you can still use Playwright to assert that the element is indeed a link for accessibility:
|
|
285
270
|
|
|
286
|
-
```typescript
|
|
271
|
+
```typescript tests/example.spec.ts icon=square-js
|
|
287
272
|
const link = await testdriver(page).locate("Get started link");
|
|
288
273
|
// [!code ++]
|
|
289
274
|
expect(link).toHaveRole("link");
|
|
@@ -298,7 +283,7 @@ This way you can write user-centric tests _and_ validate the implementation.
|
|
|
298
283
|
|
|
299
284
|
We can combine `locate` and `click` from the previous example into one line with `testdriver.act`:
|
|
300
285
|
|
|
301
|
-
```typescript
|
|
286
|
+
```typescript tests/example.spec.ts icon=square-js
|
|
302
287
|
test("get started link", async ({ page, testdriver }) => {
|
|
303
288
|
await page.goto("https://playwright.dev/");
|
|
304
289
|
|
|
@@ -318,7 +303,7 @@ Now the test uses the page the way a user would!
|
|
|
318
303
|
|
|
319
304
|
TestDriver can automatically perform the entire test for you with an AI agent:
|
|
320
305
|
|
|
321
|
-
```typescript
|
|
306
|
+
```typescript tests/example.spec.ts icon=square-js
|
|
322
307
|
// [!code --:6]
|
|
323
308
|
test("get started link", async ({ page, testdriver }) => {
|
|
324
309
|
await page.goto("https://playwright.dev/");
|
|
@@ -340,9 +325,7 @@ Instead of writing the test implementation, we've used [`test.describe`](https:/
|
|
|
340
325
|
but replaced the `test` itself with `test.agent`.
|
|
341
326
|
|
|
342
327
|
<Tip>
|
|
343
|
-
Use
|
|
344
|
-
[`test.beforEach`](https://playwright.dev/docs/api/class-test#test-after-each)
|
|
345
|
-
to prepare the page for the agent (e.g.
|
|
328
|
+
Use `test.beforeEach` to prepare the page for the agent (e.g.
|
|
346
329
|
[`page.goto`](https://playwright.dev/docs/api/class-page#page-goto), calling
|
|
347
330
|
an API to create a user). Use
|
|
348
331
|
[`test.afterEach`](https://playwright.dev/docs/api/class-test#test-after-each)
|