testdriverai 7.3.4 → 7.3.6
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/.github/workflows/acceptance-linux-scheduled.yaml +1 -1
- package/.github/workflows/acceptance.yaml +38 -1
- package/.github/workflows/windows-self-hosted.yaml +9 -1
- package/CHANGELOG.md +8 -0
- package/docs/_data/examples-manifest.json +105 -0
- package/docs/_data/examples-manifest.schema.json +41 -0
- package/docs/_scripts/extract-example-urls.js +165 -0
- package/docs/_scripts/generate-examples.js +534 -0
- package/docs/docs.json +242 -212
- package/docs/v7/aws-setup.mdx +1 -1
- package/docs/v7/examples/ai.mdx +72 -0
- package/docs/v7/examples/assert.mdx +72 -0
- package/docs/v7/examples/captcha-api.mdx +92 -0
- package/docs/v7/examples/chrome-extension.mdx +132 -0
- package/docs/v7/examples/drag-and-drop.mdx +100 -0
- package/docs/v7/examples/element-not-found.mdx +67 -0
- package/docs/v7/examples/hover-image.mdx +94 -0
- package/docs/v7/examples/hover-text.mdx +69 -0
- package/docs/v7/examples/installer.mdx +91 -0
- package/docs/v7/examples/launch-vscode-linux.mdx +101 -0
- package/docs/v7/examples/match-image.mdx +96 -0
- package/docs/v7/examples/press-keys.mdx +92 -0
- package/docs/v7/examples/scroll-keyboard.mdx +79 -0
- package/docs/v7/examples/scroll-until-image.mdx +81 -0
- package/docs/v7/examples/scroll-until-text.mdx +109 -0
- package/docs/v7/examples/scroll.mdx +81 -0
- package/docs/v7/examples/type.mdx +92 -0
- package/docs/v7/examples/windows-installer.mdx +89 -0
- package/examples/ai.test.mjs +2 -1
- package/examples/assert.test.mjs +2 -2
- package/examples/captcha-api.test.mjs +3 -2
- package/examples/chrome-extension.test.mjs +3 -2
- package/examples/config.mjs +5 -0
- package/examples/drag-and-drop.test.mjs +2 -1
- package/examples/element-not-found.test.mjs +2 -1
- package/examples/exec-output.test.mjs +2 -1
- package/examples/exec-pwsh.test.mjs +2 -1
- package/examples/focus-window.test.mjs +2 -1
- package/examples/formatted-logging.test.mjs +2 -1
- package/examples/hover-image.test.mjs +2 -1
- package/examples/hover-text-with-description.test.mjs +2 -1
- package/examples/hover-text.test.mjs +2 -1
- package/examples/installer.test.mjs +3 -2
- package/examples/launch-vscode-linux.test.mjs +3 -2
- package/examples/match-image.test.mjs +2 -1
- package/examples/no-provision.test.mjs +2 -3
- package/examples/press-keys.test.mjs +7 -13
- package/examples/prompt.test.mjs +2 -1
- package/examples/scroll-keyboard.test.mjs +2 -1
- package/examples/scroll-until-image.test.mjs +2 -1
- package/examples/scroll-until-text.test.mjs +2 -1
- package/examples/scroll.test.mjs +2 -1
- package/examples/type.test.mjs +3 -2
- package/examples/windows-installer.test.mjs +2 -1
- package/interfaces/vitest-plugin.mjs +50 -18
- package/package.json +3 -1
- package/sdk.js +49 -38
- package/vitest.config.mjs +1 -1
- package/docs/v7/examples.mdx +0 -5
- package/jsconfig.json +0 -26
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Launching VS Code Example"
|
|
3
|
+
sidebarTitle: "Launch VS Code"
|
|
4
|
+
description: "Example test demonstrating how to launch VS Code and install extensions on Linux."
|
|
5
|
+
icon: "play"
|
|
6
|
+
mode: "wide"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Demo Test Run
|
|
10
|
+
|
|
11
|
+
Watch this test execute in a real sandbox environment:
|
|
12
|
+
|
|
13
|
+
{/* launch-vscode-linux.test.mjs output */}
|
|
14
|
+
<iframe
|
|
15
|
+
src="https://testdriver-api.onrender.com/api/v1/testdriver/testcase/698b7cb811cc20acdd4ac83e/replay"
|
|
16
|
+
width="100%"
|
|
17
|
+
height="390"
|
|
18
|
+
style={{ border: "1px solid #333", borderRadius: "8px" }}
|
|
19
|
+
allow="fullscreen"
|
|
20
|
+
/>
|
|
21
|
+
|
|
22
|
+
## Source Code
|
|
23
|
+
|
|
24
|
+
```javascript title="launch-vscode-linux.test.mjs" {13,27-29}
|
|
25
|
+
/**
|
|
26
|
+
* TestDriver SDK - Launch VS Code Test
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { describe, expect, it } from "vitest";
|
|
30
|
+
import { TestDriver } from "../lib/vitest/hooks.mjs";
|
|
31
|
+
|
|
32
|
+
const isLinux = (process.env.TD_OS || "linux") === "linux";
|
|
33
|
+
|
|
34
|
+
describe("Launch VS Code on Linux", () => {
|
|
35
|
+
it.skipIf(!isLinux)(
|
|
36
|
+
"should launch VS Code on Debian/Ubuntu",
|
|
37
|
+
async (context) => {
|
|
38
|
+
const testdriver = TestDriver(context, { ip: context.ip || process.env.TD_IP });
|
|
39
|
+
|
|
40
|
+
// provision.vscode() automatically calls ready() and starts dashcam
|
|
41
|
+
await testdriver.provision.vscode();
|
|
42
|
+
|
|
43
|
+
// Wait for VS Code to launch (polls every 5s until found or timeout)
|
|
44
|
+
const vsCodeWindow = await testdriver.find(
|
|
45
|
+
"Visual Studio Code window",
|
|
46
|
+
{ timeout: 60000 }
|
|
47
|
+
);
|
|
48
|
+
expect(vsCodeWindow.found()).toBeTruthy();
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
it.skipIf(!isLinux)(
|
|
53
|
+
"should install and use a VS Code extension",
|
|
54
|
+
async (context) => {
|
|
55
|
+
const testdriver = TestDriver(context, { ip: context.ip || process.env.TD_IP });
|
|
56
|
+
|
|
57
|
+
// Launch VS Code with the Prettier extension installed
|
|
58
|
+
await testdriver.provision.vscode({
|
|
59
|
+
extensions: ["esbenp.prettier-vscode"],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const vsCodeWindow = await testdriver.find(
|
|
63
|
+
"Visual Studio Code window",
|
|
64
|
+
{ timeout: 60000 }
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
expect(vsCodeWindow.found()).toBeTruthy();
|
|
68
|
+
|
|
69
|
+
// Open the extensions panel to verify Prettier is installed
|
|
70
|
+
await testdriver.pressKeys(["ctrl", "shift", "x"]);
|
|
71
|
+
|
|
72
|
+
// Wait for extensions panel to open
|
|
73
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
74
|
+
|
|
75
|
+
// Assert that Prettier extension is visible in the installed extensions
|
|
76
|
+
const prettierVisible = await testdriver.assert(
|
|
77
|
+
"Prettier extension is visible in the extensions panel or sidebar",
|
|
78
|
+
);
|
|
79
|
+
expect(prettierVisible).toBeTruthy();
|
|
80
|
+
},
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Running This Example
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Clone the TestDriver repository
|
|
89
|
+
git clone https://github.com/testdriverai/testdriverai
|
|
90
|
+
|
|
91
|
+
# Install dependencies
|
|
92
|
+
cd testdriverai
|
|
93
|
+
npm install
|
|
94
|
+
|
|
95
|
+
# Run this specific example
|
|
96
|
+
npx vitest run examples/launch-vscode-linux.test.mjs
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
<Note>
|
|
100
|
+
Make sure you have `TD_API_KEY` set in your environment. Get one at [testdriver.ai](https://testdriver.ai).
|
|
101
|
+
</Note>
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Matching an Image By Pixel"
|
|
3
|
+
sidebarTitle: "Pixel Based Match"
|
|
4
|
+
description: "Example test demonstrating pixel-based image matching to locate UI elements."
|
|
5
|
+
icon: "image"
|
|
6
|
+
mode: "wide"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Demo Test Run
|
|
10
|
+
|
|
11
|
+
Watch this test execute in a real sandbox environment:
|
|
12
|
+
|
|
13
|
+
{/* match-image.test.mjs output */}
|
|
14
|
+
<iframe
|
|
15
|
+
src="https://testdriver-api.onrender.com/api/v1/testdriver/testcase/698b7bd7297b1f49cee2a560/replay"
|
|
16
|
+
width="100%"
|
|
17
|
+
height="390"
|
|
18
|
+
style={{ border: "1px solid #333", borderRadius: "8px" }}
|
|
19
|
+
allow="fullscreen"
|
|
20
|
+
/>
|
|
21
|
+
|
|
22
|
+
## Source Code
|
|
23
|
+
|
|
24
|
+
```javascript title="match-image.test.mjs" {42}
|
|
25
|
+
/**
|
|
26
|
+
* TestDriver SDK - Match Image Test
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import path, { dirname } from "path";
|
|
30
|
+
import { fileURLToPath } from "url";
|
|
31
|
+
import { describe, expect, it } from "vitest";
|
|
32
|
+
import { TestDriver } from "../lib/vitest/hooks.mjs";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Perform login flow for SauceLabs demo app
|
|
36
|
+
* @param {TestDriver} client - TestDriver client
|
|
37
|
+
* @param {string} username - Username (default: 'standard_user')
|
|
38
|
+
*/
|
|
39
|
+
async function performLogin(client, username = "standard_user") {
|
|
40
|
+
await client.focusApplication("Google Chrome");
|
|
41
|
+
const password = await client.extract("the password");
|
|
42
|
+
const usernameField = await client.find(
|
|
43
|
+
"username input",
|
|
44
|
+
);
|
|
45
|
+
await usernameField.click();
|
|
46
|
+
await client.type(username);
|
|
47
|
+
await client.pressKeys(["tab"]);
|
|
48
|
+
await client.type(password, { secret: true });
|
|
49
|
+
await client.pressKeys(["tab"]);
|
|
50
|
+
await client.pressKeys(["enter"]);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Get the directory of the current module
|
|
54
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
55
|
+
const __dirname = dirname(__filename);
|
|
56
|
+
|
|
57
|
+
describe("Match Image Test", () => {
|
|
58
|
+
it.skip("should match shopping cart image and verify empty cart", async (context) => {
|
|
59
|
+
const testdriver = TestDriver(context, { ip: context.ip || process.env.TD_IP, headless: true });
|
|
60
|
+
await testdriver.provision.chrome({ url: 'http://testdriver-sandbox.vercel.app/login' });
|
|
61
|
+
|
|
62
|
+
//
|
|
63
|
+
// Perform login first
|
|
64
|
+
await performLogin(testdriver);
|
|
65
|
+
|
|
66
|
+
// Match and click the shopping cart icon
|
|
67
|
+
const cartImagePath = path.resolve(
|
|
68
|
+
__dirname,
|
|
69
|
+
"../../_testdriver/acceptance/screenshots/cart.png",
|
|
70
|
+
);
|
|
71
|
+
await testdriver.matchImage(cartImagePath, "click");
|
|
72
|
+
|
|
73
|
+
// Assert that you see an empty shopping cart
|
|
74
|
+
const result = await testdriver.assert("Your cart is empty");
|
|
75
|
+
expect(result).toBeTruthy();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Running This Example
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Clone the TestDriver repository
|
|
84
|
+
git clone https://github.com/testdriverai/testdriverai
|
|
85
|
+
|
|
86
|
+
# Install dependencies
|
|
87
|
+
cd testdriverai
|
|
88
|
+
npm install
|
|
89
|
+
|
|
90
|
+
# Run this specific example
|
|
91
|
+
npx vitest run examples/match-image.test.mjs
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
<Note>
|
|
95
|
+
Make sure you have `TD_API_KEY` set in your environment. Get one at [testdriver.ai](https://testdriver.ai).
|
|
96
|
+
</Note>
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Pressing Keys Test"
|
|
3
|
+
sidebarTitle: "Pressing Keys"
|
|
4
|
+
description: "Example test demonstrating keyboard shortcuts and key combinations for browser navigation."
|
|
5
|
+
icon: "keyboard"
|
|
6
|
+
mode: "wide"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Demo Test Run
|
|
10
|
+
|
|
11
|
+
Watch this test execute in a real sandbox environment:
|
|
12
|
+
|
|
13
|
+
{/* press-keys.test.mjs output */}
|
|
14
|
+
<iframe
|
|
15
|
+
src="https://testdriver-api.onrender.com/api/v1/testdriver/testcase/698b7cf911cc20acdd4ac84a/replay"
|
|
16
|
+
width="100%"
|
|
17
|
+
height="390"
|
|
18
|
+
style={{ border: "1px solid #333", borderRadius: "8px" }}
|
|
19
|
+
allow="fullscreen"
|
|
20
|
+
/>
|
|
21
|
+
|
|
22
|
+
## Source Code
|
|
23
|
+
|
|
24
|
+
```javascript title="press-keys.test.mjs" {17,24,36}
|
|
25
|
+
/**
|
|
26
|
+
* TestDriver SDK - Press Keys Test
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { describe, expect, it } from "vitest";
|
|
30
|
+
import { TestDriver } from "../lib/vitest/hooks.mjs";
|
|
31
|
+
|
|
32
|
+
describe("Press Keys Test", () => {
|
|
33
|
+
it("should create tabs and navigate using keyboard shortcuts", async (context) => {
|
|
34
|
+
const testdriver = TestDriver(context, { ip: context.ip || process.env.TD_IP, headless: true });
|
|
35
|
+
await testdriver.provision.chrome({ url: 'http://testdriver-sandbox.vercel.app/login' });
|
|
36
|
+
|
|
37
|
+
const signInButton = await testdriver.find(
|
|
38
|
+
"Sign In, black button below the password field",
|
|
39
|
+
);
|
|
40
|
+
await signInButton.click();
|
|
41
|
+
|
|
42
|
+
// Open new tab
|
|
43
|
+
await testdriver.pressKeys(["ctrl", "t"]);
|
|
44
|
+
|
|
45
|
+
// Poll for "Learn more" to appear
|
|
46
|
+
let learnMore = await testdriver.find("Learn more");
|
|
47
|
+
for (let i = 0; i < 10; i++) {
|
|
48
|
+
learnMore = await learnMore.find();
|
|
49
|
+
if (learnMore.found()) break;
|
|
50
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Open DevTools
|
|
54
|
+
await testdriver.pressKeys(["ctrl", "shift", "i"]);
|
|
55
|
+
|
|
56
|
+
// Poll for "Elements" to appear
|
|
57
|
+
let elements = await testdriver.find("Elements");
|
|
58
|
+
for (let i = 0; i < 10; i++) {
|
|
59
|
+
elements = await elements.find();
|
|
60
|
+
if (elements.found()) break;
|
|
61
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Open another tab and navigate
|
|
65
|
+
await testdriver.pressKeys(["ctrl", "t"]);
|
|
66
|
+
await testdriver.type("google.com");
|
|
67
|
+
await testdriver.pressKeys(["enter"]);
|
|
68
|
+
|
|
69
|
+
// Assert Google appears
|
|
70
|
+
const result = await testdriver.assert("google appears");
|
|
71
|
+
expect(result).toBeTruthy();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Running This Example
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Clone the TestDriver repository
|
|
80
|
+
git clone https://github.com/testdriverai/testdriverai
|
|
81
|
+
|
|
82
|
+
# Install dependencies
|
|
83
|
+
cd testdriverai
|
|
84
|
+
npm install
|
|
85
|
+
|
|
86
|
+
# Run this specific example
|
|
87
|
+
npx vitest run examples/press-keys.test.mjs
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
<Note>
|
|
91
|
+
Make sure you have `TD_API_KEY` set in your environment. Get one at [testdriver.ai](https://testdriver.ai).
|
|
92
|
+
</Note>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Scrolling with Keyboard Test"
|
|
3
|
+
sidebarTitle: "Scrolling with Keyboard"
|
|
4
|
+
description: "Example test demonstrating page scrolling using keyboard-based scroll controls."
|
|
5
|
+
icon: "scroll"
|
|
6
|
+
mode: "wide"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Demo Test Run
|
|
10
|
+
|
|
11
|
+
Watch this test execute in a real sandbox environment:
|
|
12
|
+
|
|
13
|
+
{/* scroll-keyboard.test.mjs output */}
|
|
14
|
+
<iframe
|
|
15
|
+
src="https://testdriver-api.onrender.com/api/v1/testdriver/testcase/698b7d92297b1f49cee2a5b2/replay"
|
|
16
|
+
width="100%"
|
|
17
|
+
height="390"
|
|
18
|
+
style={{ border: "1px solid #333", borderRadius: "8px" }}
|
|
19
|
+
allow="fullscreen"
|
|
20
|
+
/>
|
|
21
|
+
|
|
22
|
+
## Source Code
|
|
23
|
+
|
|
24
|
+
```javascript title="scroll-keyboard.test.mjs" {26}
|
|
25
|
+
/**
|
|
26
|
+
* TestDriver SDK - Scroll Keyboard Test
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { describe, expect, it } from "vitest";
|
|
30
|
+
import { TestDriver } from "../lib/vitest/hooks.mjs";
|
|
31
|
+
|
|
32
|
+
describe("Scroll Keyboard Test", () => {
|
|
33
|
+
it("should navigate to webhamster.com and scroll with keyboard", async (context) => {
|
|
34
|
+
const testdriver = TestDriver(context, { ip: context.ip || process.env.TD_IP, headless: true });
|
|
35
|
+
await testdriver.provision.chrome({ url: 'http://testdriver-sandbox.vercel.app/login' });
|
|
36
|
+
|
|
37
|
+
//
|
|
38
|
+
// Navigate to https://www.webhamster.com/
|
|
39
|
+
await testdriver.focusApplication("Google Chrome");
|
|
40
|
+
const urlBar = await testdriver.find(
|
|
41
|
+
"testdriver-sandbox.vercel.app/login, the URL in the omnibox showing the current page",
|
|
42
|
+
);
|
|
43
|
+
await urlBar.click();
|
|
44
|
+
await testdriver.pressKeys(["ctrl", "a"]);
|
|
45
|
+
await testdriver.type("https://www.webhamster.com/");
|
|
46
|
+
await testdriver.pressKeys(["enter"]);
|
|
47
|
+
|
|
48
|
+
// Scroll down with keyboard 1000 pixels
|
|
49
|
+
const heading = await testdriver.find(
|
|
50
|
+
"The Hamster Dance, large heading at top of page",
|
|
51
|
+
);
|
|
52
|
+
await heading.click();
|
|
53
|
+
await testdriver.scroll("down", { amount: 1000 });
|
|
54
|
+
|
|
55
|
+
// Assert the page is scrolled down
|
|
56
|
+
const result = await testdriver.assert("The text 'The Hamster Dance' is not visible on the webpage content. It's ok if it's visible in the tab title.");
|
|
57
|
+
|
|
58
|
+
expect(result).toBeTruthy();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Running This Example
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# Clone the TestDriver repository
|
|
67
|
+
git clone https://github.com/testdriverai/testdriverai
|
|
68
|
+
|
|
69
|
+
# Install dependencies
|
|
70
|
+
cd testdriverai
|
|
71
|
+
npm install
|
|
72
|
+
|
|
73
|
+
# Run this specific example
|
|
74
|
+
npx vitest run examples/scroll-keyboard.test.mjs
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
<Note>
|
|
78
|
+
Make sure you have `TD_API_KEY` set in your environment. Get one at [testdriver.ai](https://testdriver.ai).
|
|
79
|
+
</Note>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Scroll Until Image Test"
|
|
3
|
+
sidebarTitle: "Scroll Until Image"
|
|
4
|
+
description: "Example test demonstrating how to scroll a page until a specific image becomes visible."
|
|
5
|
+
icon: "scroll"
|
|
6
|
+
mode: "wide"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Demo Test Run
|
|
10
|
+
|
|
11
|
+
Watch this test execute in a real sandbox environment:
|
|
12
|
+
|
|
13
|
+
{/* scroll-until-image.test.mjs output */}
|
|
14
|
+
<iframe
|
|
15
|
+
src="https://testdriver-api.onrender.com/api/v1/testdriver/testcase/698b7d76297b1f49cee2a5b0/replay"
|
|
16
|
+
width="100%"
|
|
17
|
+
height="390"
|
|
18
|
+
style={{ border: "1px solid #333", borderRadius: "8px" }}
|
|
19
|
+
allow="fullscreen"
|
|
20
|
+
/>
|
|
21
|
+
|
|
22
|
+
## Source Code
|
|
23
|
+
|
|
24
|
+
```javascript title="scroll-until-image.test.mjs" {26}
|
|
25
|
+
/**
|
|
26
|
+
* TestDriver SDK - Scroll Until Image Test
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { describe, expect, it } from "vitest";
|
|
30
|
+
import { TestDriver } from "../lib/vitest/hooks.mjs";
|
|
31
|
+
|
|
32
|
+
describe("Scroll Until Image Test", () => {
|
|
33
|
+
it.skip("should scroll until brown colored house image appears", async (context) => {
|
|
34
|
+
const testdriver = TestDriver(context, { ip: context.ip || process.env.TD_IP, headless: true });
|
|
35
|
+
await testdriver.provision.chrome({ url: 'http://testdriver-sandbox.vercel.app/login' });
|
|
36
|
+
|
|
37
|
+
//
|
|
38
|
+
// Navigate to Wikipedia page
|
|
39
|
+
await testdriver.pressKeys(["ctrl", "l"]);
|
|
40
|
+
await testdriver.type("https://en.wikipedia.org/wiki/Leonardo_da_Vinci");
|
|
41
|
+
await testdriver.pressKeys(["enter"]);
|
|
42
|
+
|
|
43
|
+
// sleep for 5 seconds
|
|
44
|
+
await new Promise((r) => setTimeout(r, 5000));
|
|
45
|
+
|
|
46
|
+
// Click on heading
|
|
47
|
+
const heading = await testdriver.find(
|
|
48
|
+
"Leonardo Da Vinci, the page heading",
|
|
49
|
+
0,
|
|
50
|
+
);
|
|
51
|
+
await heading.click();
|
|
52
|
+
|
|
53
|
+
// Scroll until image appears
|
|
54
|
+
await testdriver.scrollUntilImage("a brown colored house", "down", 10000);
|
|
55
|
+
|
|
56
|
+
// Assert image of brown colored house appears on screen
|
|
57
|
+
const result = await testdriver.assert(
|
|
58
|
+
"image of brown colored house appears on screen",
|
|
59
|
+
);
|
|
60
|
+
expect(result).toBeTruthy();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Running This Example
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# Clone the TestDriver repository
|
|
69
|
+
git clone https://github.com/testdriverai/testdriverai
|
|
70
|
+
|
|
71
|
+
# Install dependencies
|
|
72
|
+
cd testdriverai
|
|
73
|
+
npm install
|
|
74
|
+
|
|
75
|
+
# Run this specific example
|
|
76
|
+
npx vitest run examples/scroll-until-image.test.mjs
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
<Note>
|
|
80
|
+
Make sure you have `TD_API_KEY` set in your environment. Get one at [testdriver.ai](https://testdriver.ai).
|
|
81
|
+
</Note>
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Scroll Until Text Test"
|
|
3
|
+
sidebarTitle: "Scroll Until Text"
|
|
4
|
+
description: "Example test demonstrating how to scroll a page until specific text becomes visible."
|
|
5
|
+
icon: "scroll"
|
|
6
|
+
mode: "wide"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Demo Test Run
|
|
10
|
+
|
|
11
|
+
Watch this test execute in a real sandbox environment:
|
|
12
|
+
|
|
13
|
+
{/* scroll-until-text.test.mjs output */}
|
|
14
|
+
<iframe
|
|
15
|
+
src="https://testdriver-api.onrender.com/api/v1/testdriver/testcase/698b7c4d4f24dc8fa701f5ba/replay"
|
|
16
|
+
width="100%"
|
|
17
|
+
height="390"
|
|
18
|
+
style={{ border: "1px solid #333", borderRadius: "8px" }}
|
|
19
|
+
allow="fullscreen"
|
|
20
|
+
/>
|
|
21
|
+
|
|
22
|
+
## Source Code
|
|
23
|
+
|
|
24
|
+
```javascript title="scroll-until-text.test.mjs" {41-51}
|
|
25
|
+
/**
|
|
26
|
+
* TestDriver SDK - Scroll Until Text Test
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { describe, expect, it } from "vitest";
|
|
30
|
+
import { TestDriver } from "../lib/vitest/hooks.mjs";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Perform login flow for SauceLabs demo app
|
|
34
|
+
* @param {TestDriver} client - TestDriver client
|
|
35
|
+
* @param {string} username - Username (default: 'standard_user')
|
|
36
|
+
*/
|
|
37
|
+
async function performLogin(client, username = "standard_user") {
|
|
38
|
+
await client.focusApplication("Google Chrome");
|
|
39
|
+
const password = await client.extract("the password");
|
|
40
|
+
const usernameField = await client.find(
|
|
41
|
+
"username input",
|
|
42
|
+
);
|
|
43
|
+
await usernameField.click();
|
|
44
|
+
await client.type(username);
|
|
45
|
+
await client.pressKeys(["tab"]);
|
|
46
|
+
await client.type(password, { secret: true });
|
|
47
|
+
await client.pressKeys(["tab"]);
|
|
48
|
+
await client.pressKeys(["enter"]);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
describe("Scroll Until Text Test", () => {
|
|
52
|
+
it('should scroll until "testdriver socks" appears', async (context) => {
|
|
53
|
+
const testdriver = TestDriver(context, { ip: context.ip || process.env.TD_IP, headless: true });
|
|
54
|
+
await testdriver.provision.chrome({ url: 'http://testdriver-sandbox.vercel.app/login' });
|
|
55
|
+
|
|
56
|
+
//
|
|
57
|
+
// Perform login first
|
|
58
|
+
await performLogin(testdriver);
|
|
59
|
+
|
|
60
|
+
// Scroll until text appears
|
|
61
|
+
await testdriver.focusApplication("Google Chrome");
|
|
62
|
+
|
|
63
|
+
await testdriver.find('TestDriver.ai Sandbox heading').click();
|
|
64
|
+
|
|
65
|
+
// Scroll until text appears
|
|
66
|
+
let found = false;
|
|
67
|
+
let scrollCount = 0;
|
|
68
|
+
const maxScrolls = 10;
|
|
69
|
+
|
|
70
|
+
while (!found && scrollCount < maxScrolls) {
|
|
71
|
+
const findResult = await testdriver.find("testdriver socks product text is fully visible");
|
|
72
|
+
|
|
73
|
+
if (findResult.found()) {
|
|
74
|
+
found = true;
|
|
75
|
+
} else {
|
|
76
|
+
await testdriver.scroll();
|
|
77
|
+
scrollCount++;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!found) {
|
|
82
|
+
throw new Error(`Failed to find "testdriver socks" after ${maxScrolls} scrolls`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Assert testdriver socks appears on screen
|
|
86
|
+
await testdriver.focusApplication("Google Chrome");
|
|
87
|
+
const result = await testdriver.assert("TestDriver Socks appears on screen");
|
|
88
|
+
expect(result).toBeTruthy();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Running This Example
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# Clone the TestDriver repository
|
|
97
|
+
git clone https://github.com/testdriverai/testdriverai
|
|
98
|
+
|
|
99
|
+
# Install dependencies
|
|
100
|
+
cd testdriverai
|
|
101
|
+
npm install
|
|
102
|
+
|
|
103
|
+
# Run this specific example
|
|
104
|
+
npx vitest run examples/scroll-until-text.test.mjs
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
<Note>
|
|
108
|
+
Make sure you have `TD_API_KEY` set in your environment. Get one at [testdriver.ai](https://testdriver.ai).
|
|
109
|
+
</Note>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Scrolling Test Example"
|
|
3
|
+
sidebarTitle: "Scrolling"
|
|
4
|
+
description: "Example test demonstrating page scrolling with configurable direction and scroll amount."
|
|
5
|
+
icon: "scroll"
|
|
6
|
+
mode: "wide"
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Demo Test Run
|
|
10
|
+
|
|
11
|
+
Watch this test execute in a real sandbox environment:
|
|
12
|
+
|
|
13
|
+
{/* scroll.test.mjs output */}
|
|
14
|
+
<iframe
|
|
15
|
+
src="https://testdriver-api.onrender.com/api/v1/testdriver/testcase/698b7d39297b1f49cee2a5a7/replay"
|
|
16
|
+
width="100%"
|
|
17
|
+
height="390"
|
|
18
|
+
style={{ border: "1px solid #333", borderRadius: "8px" }}
|
|
19
|
+
allow="fullscreen"
|
|
20
|
+
/>
|
|
21
|
+
|
|
22
|
+
## Source Code
|
|
23
|
+
|
|
24
|
+
```javascript title="scroll.test.mjs" {29}
|
|
25
|
+
/**
|
|
26
|
+
* TestDriver SDK - Scroll Test
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { describe, expect, it } from "vitest";
|
|
30
|
+
import { TestDriver } from "../lib/vitest/hooks.mjs";
|
|
31
|
+
|
|
32
|
+
describe("Scroll Test", () => {
|
|
33
|
+
it("should navigate and scroll down the page", async (context) => {
|
|
34
|
+
const testdriver = TestDriver(context, { ip: context.ip || process.env.TD_IP, headless: true });
|
|
35
|
+
await testdriver.provision.chrome({ url: 'http://testdriver-sandbox.vercel.app/login' });
|
|
36
|
+
|
|
37
|
+
// Give Chrome a moment to fully render the UI
|
|
38
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
39
|
+
|
|
40
|
+
// Navigate to webhamster.com - just look for the domain, not the full path
|
|
41
|
+
const urlBar = await testdriver.find(
|
|
42
|
+
"testdriver-sandbox.vercel.app, the URL in the address bar",
|
|
43
|
+
);
|
|
44
|
+
await urlBar.click();
|
|
45
|
+
await testdriver.pressKeys(["ctrl", "a"]);
|
|
46
|
+
await testdriver.type("https://www.webhamster.com/");
|
|
47
|
+
await testdriver.pressKeys(["enter"]);
|
|
48
|
+
|
|
49
|
+
// Wait for page to load and click heading
|
|
50
|
+
const heading = await testdriver.find(
|
|
51
|
+
"The Hamster Dance, large heading at top of page",
|
|
52
|
+
);
|
|
53
|
+
await heading.click();
|
|
54
|
+
|
|
55
|
+
// Scroll down
|
|
56
|
+
await testdriver.scroll("down", { amount: 1000 });
|
|
57
|
+
|
|
58
|
+
// Assert page is scrolled
|
|
59
|
+
const result = await testdriver.assert("The text 'The Hamster Dance' is not visible on the webpage content. It's ok if it's visible in the tab title.");
|
|
60
|
+
expect(result).toBeTruthy();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Running This Example
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# Clone the TestDriver repository
|
|
69
|
+
git clone https://github.com/testdriverai/testdriverai
|
|
70
|
+
|
|
71
|
+
# Install dependencies
|
|
72
|
+
cd testdriverai
|
|
73
|
+
npm install
|
|
74
|
+
|
|
75
|
+
# Run this specific example
|
|
76
|
+
npx vitest run examples/scroll.test.mjs
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
<Note>
|
|
80
|
+
Make sure you have `TD_API_KEY` set in your environment. Get one at [testdriver.ai](https://testdriver.ai).
|
|
81
|
+
</Note>
|