testdriverai 6.0.30 → 6.0.31
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.
|
@@ -19,10 +19,12 @@ We'll be incrementally converting Playwright's example test from the sample code
|
|
|
19
19
|
|
|
20
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
|
|
|
@@ -30,6 +32,8 @@ To using natural language with TestDriver:
|
|
|
30
32
|
|
|
31
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(`
|
|
@@ -44,10 +48,7 @@ test.describe("get started link", () => {
|
|
|
44
48
|
<Steps>
|
|
45
49
|
<Step title="Create a TestDriver Account">
|
|
46
50
|
You will need a [TestDriver Pro](https://app.testdriver.ai/team) account (\$20/month) to get an API key.
|
|
47
|
-
|
|
48
|
-
<Card title="Sign Up for TestDriver" icon="user-plus" horizontal href="https://app.testdriver.ai/team">
|
|
49
|
-
|
|
50
|
-
</Card>
|
|
51
|
+
<Card title="Sign Up for TestDriver" icon="user-plus" horizontal href="https://app.testdriver.ai/team" />
|
|
51
52
|
</Step>
|
|
52
53
|
<Step title="Set up your environment">
|
|
53
54
|
Copy your API key from [the TestDriver dashboard](https://app.testdriver.ai/team), and set it as an environment variable.
|
|
@@ -64,6 +65,7 @@ test.describe("get started link", () => {
|
|
|
64
65
|
```
|
|
65
66
|
</Tab>
|
|
66
67
|
</Tabs>
|
|
68
|
+
|
|
67
69
|
</Step>
|
|
68
70
|
</Steps>
|
|
69
71
|
|
|
@@ -76,7 +78,7 @@ test.describe("get started link", () => {
|
|
|
76
78
|
|
|
77
79
|
**If you're new to Playwright, you should follow their guide first.**
|
|
78
80
|
</Info>
|
|
79
|
-
In
|
|
81
|
+
In a new folder or an existing, run:
|
|
80
82
|
|
|
81
83
|
<Tabs>
|
|
82
84
|
<Tab title="npm">
|
|
@@ -127,6 +129,7 @@ test.describe("get started link", () => {
|
|
|
127
129
|
```
|
|
128
130
|
</Tab>
|
|
129
131
|
</Tabs>
|
|
132
|
+
|
|
130
133
|
</Step>
|
|
131
134
|
</Steps>
|
|
132
135
|
|
|
@@ -153,6 +156,7 @@ test.describe("get started link", () => {
|
|
|
153
156
|
```
|
|
154
157
|
</Tab>
|
|
155
158
|
</Tabs>
|
|
159
|
+
|
|
156
160
|
</Step>
|
|
157
161
|
<Step title="Run Playwright">
|
|
158
162
|
Before we start using TestDriver in our tests, run Playwright in [UI Mode](https://playwright.dev/docs/test-ui-mode):
|
|
@@ -178,6 +182,7 @@ test.describe("get started link", () => {
|
|
|
178
182
|
|
|
179
183
|
Clicking the ▶️ button should successfully run the tests in the UI,
|
|
180
184
|
just as they did before with `playwright test` in the CLI.
|
|
185
|
+
|
|
181
186
|
</Step>
|
|
182
187
|
<Step title="Import TestDriver">
|
|
183
188
|
For the sake of simplicity, we'll be working with one test file for now.
|
|
@@ -195,6 +200,7 @@ test.describe("get started link", () => {
|
|
|
195
200
|
<Tip>
|
|
196
201
|
Click the <Icon icon="eye" /> button to automatically re-run tests on save.
|
|
197
202
|
</Tip>
|
|
203
|
+
|
|
198
204
|
</Step>
|
|
199
205
|
</Steps>
|
|
200
206
|
|
|
@@ -262,14 +268,15 @@ Now, our test uses natural language to both describe & locate the element.
|
|
|
262
268
|
<Tip>
|
|
263
269
|
In the example above, you can still use Playwright to assert that the element is indeed a link for accessibility:
|
|
264
270
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
+
```typescript tests/example.spec.ts icon=square-js
|
|
272
|
+
const link = await testdriver(page).locate("Get started link");
|
|
273
|
+
// [!code ++]
|
|
274
|
+
expect(link).toHaveRole("link");
|
|
275
|
+
await link.click();
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
This way you can write user-centric tests _and_ validate the implementation.
|
|
271
279
|
|
|
272
|
-
This way you can write user-centric tests _and_ validate the implementation.
|
|
273
280
|
</Tip>
|
|
274
281
|
|
|
275
282
|
### Performing actions with `testdriver.act`
|
|
@@ -318,7 +325,8 @@ Instead of writing the test implementation, we've used [`test.describe`](https:/
|
|
|
318
325
|
but replaced the `test` itself with `test.agent`.
|
|
319
326
|
|
|
320
327
|
<Tip>
|
|
321
|
-
Use `test.beforeEach` to prepare the page for the agent (e.g.
|
|
328
|
+
Use `test.beforeEach` to prepare the page for the agent (e.g.
|
|
329
|
+
[`page.goto`](https://playwright.dev/docs/api/class-page#page-goto), calling
|
|
322
330
|
an API to create a user). Use
|
|
323
331
|
[`test.afterEach`](https://playwright.dev/docs/api/class-test#test-after-each)
|
|
324
332
|
to clean up after the agent (e.g. `page.close`) or perform additional logic
|
|
@@ -327,4 +335,4 @@ but replaced the `test` itself with `test.agent`.
|
|
|
327
335
|
|
|
328
336
|
## Conclusion
|
|
329
337
|
|
|
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!
|
|
338
|
+
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!
|