@testdriverai/agent 7.11.229-canary → 7.11.231-test

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.
Files changed (100) hide show
  1. package/docs/_data/examples-manifest.json +16 -16
  2. package/docs/_scripts/generate-examples.js +38 -45
  3. package/docs/agent.mdx +174 -93
  4. package/docs/assert.mdx +73 -269
  5. package/docs/aws-setup.mdx +196 -314
  6. package/docs/bring-your-own-machine.mdx +139 -206
  7. package/docs/cache.mdx +144 -151
  8. package/docs/caching.mdx +99 -89
  9. package/docs/captcha.mdx +126 -111
  10. package/docs/ci-cd.mdx +154 -543
  11. package/docs/click.mdx +74 -229
  12. package/docs/client.mdx +177 -231
  13. package/docs/copilot/auto-healing.mdx +86 -370
  14. package/docs/copilot/running-tests.mdx +121 -930
  15. package/docs/customizing-devices.mdx +74 -251
  16. package/docs/dashcam.mdx +72 -405
  17. package/docs/debugging-with-screenshots.mdx +105 -371
  18. package/docs/docs.json +75 -18
  19. package/docs/double-click.mdx +48 -68
  20. package/docs/errors.mdx +102 -176
  21. package/docs/events.mdx +170 -327
  22. package/docs/examples/{hover-text-with-description.mdx → add-to-cart.mdx} +30 -35
  23. package/docs/examples/assert.mdx +28 -41
  24. package/docs/examples/click-button.mdx +71 -0
  25. package/docs/examples/{hover-image.mdx → click-icon.mdx} +32 -28
  26. package/docs/examples/element-not-found.mdx +27 -26
  27. package/docs/examples/findall-coffee-icons.mdx +28 -32
  28. package/docs/examples/installer.mdx +61 -25
  29. package/docs/examples/launch-vscode-linux.mdx +28 -51
  30. package/docs/examples/navigate-and-scroll.mdx +82 -0
  31. package/docs/examples/parse.mdx +24 -28
  32. package/docs/examples/press-keys.mdx +28 -25
  33. package/docs/examples/scroll.mdx +25 -27
  34. package/docs/examples/type.mdx +26 -21
  35. package/docs/exec.mdx +92 -256
  36. package/docs/extract.mdx +69 -170
  37. package/docs/find.mdx +140 -736
  38. package/docs/focus-application.mdx +69 -246
  39. package/docs/generating-tests.mdx +103 -137
  40. package/docs/guide/best-practices-polling.mdx +65 -141
  41. package/docs/hosted.mdx +80 -144
  42. package/docs/hover.mdx +62 -235
  43. package/docs/locating-elements.mdx +74 -369
  44. package/docs/making-assertions.mdx +116 -74
  45. package/docs/mcp-setup.mdx +80 -63
  46. package/docs/mouse-down.mdx +48 -125
  47. package/docs/mouse-up.mdx +47 -129
  48. package/docs/options.mdx +75 -48
  49. package/docs/parse.mdx +95 -184
  50. package/docs/performing-actions.mdx +104 -94
  51. package/docs/press-keys.mdx +59 -299
  52. package/docs/provision.mdx +137 -182
  53. package/docs/quickstart-claude.mdx +85 -0
  54. package/docs/quickstart-github.mdx +62 -32
  55. package/docs/quickstart-manual.mdx +60 -33
  56. package/docs/quickstart-vscode.mdx +97 -0
  57. package/docs/quickstart.mdx +25 -9
  58. package/docs/redraw.mdx +101 -165
  59. package/docs/reusable-code.mdx +97 -200
  60. package/docs/right-click.mdx +47 -89
  61. package/docs/screenshot.mdx +47 -201
  62. package/docs/screenshots.mdx +87 -137
  63. package/docs/scroll.mdx +71 -154
  64. package/docs/secrets.mdx +96 -91
  65. package/docs/self-hosted.mdx +83 -142
  66. package/docs/snippets/enterprise.mdx +15 -0
  67. package/docs/styles.css +68 -0
  68. package/docs/test-results-json.mdx +167 -204
  69. package/docs/type.mdx +56 -304
  70. package/docs/variables.mdx +121 -81
  71. package/docs/wait.mdx +33 -31
  72. package/docs/what-is-testdriver.mdx +80 -32
  73. package/examples/{hover-text-with-description.test.mjs → add-to-cart.test.mjs} +4 -5
  74. package/examples/assert.test.mjs +3 -20
  75. package/examples/{hover-text.test.mjs → click-button.test.mjs} +3 -4
  76. package/examples/{hover-image.test.mjs → click-icon.test.mjs} +5 -6
  77. package/examples/element-not-found.test.mjs +3 -5
  78. package/examples/findall-coffee-icons.test.mjs +3 -3
  79. package/examples/installer.test.mjs +1 -1
  80. package/examples/launch-vscode-linux.test.mjs +6 -33
  81. package/examples/{scroll-keyboard.test.mjs → navigate-and-scroll.test.mjs} +4 -5
  82. package/examples/parse.test.mjs +1 -2
  83. package/examples/press-keys.test.mjs +4 -4
  84. package/examples/scroll.test.mjs +3 -6
  85. package/examples/type.test.mjs +5 -2
  86. package/lib/provision.js +6 -2
  87. package/package.json +1 -1
  88. package/sdk.d.ts +4 -2
  89. package/sdk.js +1 -1
  90. package/docs/claude-mcp-plugin.mdx +0 -244
  91. package/docs/elements.mdx +0 -606
  92. package/docs/examples/ai.mdx +0 -78
  93. package/docs/examples/captcha-api.mdx +0 -92
  94. package/docs/examples/chrome-extension.mdx +0 -156
  95. package/docs/examples/drag-and-drop.mdx +0 -100
  96. package/docs/examples/formatted-logging.mdx +0 -74
  97. package/docs/examples/hover-text.mdx +0 -70
  98. package/docs/examples/match-image.mdx +0 -97
  99. package/docs/examples/scroll-keyboard.mdx +0 -80
  100. package/docs/examples/scroll-until-text.mdx +0 -109
package/docs/captcha.mdx CHANGED
@@ -1,159 +1,174 @@
1
1
  ---
2
2
  title: "captcha()"
3
3
  sidebarTitle: "captcha"
4
- description: "Solve captchas using 2captcha service"
4
+ description: "Solve a reCAPTCHA, hCaptcha, or Cloudflare Turnstile on the page with the 2captcha service."
5
5
  icon: "shield-check"
6
6
  ---
7
7
 
8
- # Captcha Solving
9
-
10
- TestDriver can solve captchas automatically during your tests. It uses the 2captcha service. This feature works on **Linux** sandboxes and **Windows** sandboxes.
11
-
12
- ## Quick Start
13
-
8
+ Solve a captcha on the current page so your test can get past it. TestDriver uses the [2captcha](https://2captcha.com) solving service, so you need a 2captcha account and API key.
14
9
 
15
10
  ```javascript
16
- const result = await testdriver.captcha({
17
- apiKey: process.env.TWOCAPTCHA_API_KEY,
18
- });
19
-
20
- console.log(result.success); // true
21
- console.log(result.token); // The solved captcha token
11
+ const result = await testdriver.captcha({ apiKey: process.env.TWOCAPTCHA_API_KEY });
22
12
  ```
23
13
 
24
- That is all. TestDriver does these automatically:
25
- - Finds the captcha type on the page
26
- - Gets the sitekey
27
- - Solves the captcha with 2captcha
28
- - Puts the token into the page
29
- - Starts the callbacks
14
+ With no other options, `captcha()`:
30
15
 
31
- ## Supported Captcha Types
16
+ - Finds the captcha on the page and reads its sitekey.
17
+ - Sends it to 2captcha and waits for the solution.
18
+ - Puts the token into the page and calls the page's captcha callbacks.
19
+ - Clicks the form's submit button.
32
20
 
33
- | Type | Auto-Detected | Notes |
34
- |------|---------------|-------|
35
- | reCAPTCHA v2 | ✅ | Including invisible |
36
- | reCAPTCHA v3 | ✅ | Action is auto-detected |
37
- | hCaptcha | ✅ | |
38
- | Cloudflare Turnstile | ✅ | |
21
+ It works on Linux and Windows sandboxes, in Chrome opened with [`provision.chrome()`](/provision#chrome-options).
39
22
 
40
- ## Getting a 2captcha API Key
23
+ ## Signature
41
24
 
42
- 1. Sign up at [2captcha.com](https://2captcha.com)
43
- 2. Add funds to your account
44
- 3. Copy your API key from the dashboard
45
-
46
- ## Configuration Options
47
-
48
- ```javascript
49
- const result = await testdriver.captcha({
50
- // Required
51
- apiKey: '2CAPTCHA_API_KEY',
52
-
53
- // Optional - usually auto-detected
54
- sitekey: '6Le...', // Override auto-detected sitekey
55
- type: 'recaptcha_v3', // Override auto-detected type
56
- action: 'submit', // reCAPTCHA v3 action
57
-
58
- // Timing
59
- timeout: 120000, // Max wait time (default: 120s)
60
- pollInterval: 5000, // Poll interval (default: 5s)
61
- });
25
+ ```typescript
26
+ testdriver.captcha(options: CaptchaOptions): Promise<CaptchaResult>
62
27
  ```
63
28
 
64
- ## Full Example
65
-
66
- ```javascript
67
- import { describe, expect, it } from "vitest";
68
- import { TestDriver } from "testdriver";
69
-
70
- describe("Checkout flow", () => {
71
- it("should complete checkout with captcha", async (context) => {
29
+ ## Parameters
30
+
31
+ <ParamField path="options" type="CaptchaOptions" required>
32
+ <Expandable title="properties">
33
+ <ParamField path="apiKey" type="string" required>
34
+ Your 2captcha API key. `captcha()` throws if it's missing.
35
+ </ParamField>
36
+ <ParamField path="sitekey" type="string">
37
+ The captcha's sitekey. When you leave it out, TestDriver finds the captcha and its type on the page. When you set it, also set `type`.
38
+ </ParamField>
39
+ <ParamField path="type" type="string" default="recaptcha_v3">
40
+ `'recaptcha_v2'`, `'recaptcha_v3'`, `'hcaptcha'`, or `'turnstile'`. Only used when you set `sitekey`. Otherwise the detected type is used.
41
+ </ParamField>
42
+ <ParamField path="action" type="string" default="verify">
43
+ The reCAPTCHA v3 action. Detected from the page when possible.
44
+ </ParamField>
45
+ <ParamField path="autoSubmit" type="boolean" default="true">
46
+ Click the form's submit button after the captcha is solved.
47
+ </ParamField>
48
+ <ParamField path="timeout" type="number" default="120000">
49
+ How long to wait for 2captcha's solution, in milliseconds.
50
+ </ParamField>
51
+ <ParamField path="pollInterval" type="number" default="5000">
52
+ How often to check 2captcha for the solution, in milliseconds.
53
+ </ParamField>
54
+ </Expandable>
55
+ </ParamField>
56
+
57
+ ### Captchas it detects
58
+
59
+ | Captcha | Detected from |
60
+ | --- | --- |
61
+ | reCAPTCHA v2, including invisible | The `g-recaptcha` element |
62
+ | reCAPTCHA v3 | `grecaptcha.execute()` or the `render=` script parameter, including the action |
63
+ | hCaptcha | The `h-captcha` element |
64
+ | Cloudflare Turnstile | The `cf-turnstile` element |
65
+
66
+ ## Returns
67
+
68
+ <ResponseField name="CaptchaResult" type="object">
69
+ <Expandable title="properties">
70
+ <ResponseField name="success" type="boolean">
71
+ Whether the captcha was solved.
72
+ </ResponseField>
73
+ <ResponseField name="token" type="string | null">
74
+ The solved token.
75
+ </ResponseField>
76
+ <ResponseField name="message" type="string">
77
+ `"Captcha solved successfully"` or `"Captcha solving failed"`.
78
+ </ResponseField>
79
+ <ResponseField name="output" type="string">
80
+ The solver's full log, for debugging.
81
+ </ResponseField>
82
+ </Expandable>
83
+ </ResponseField>
84
+
85
+ ## Errors
86
+
87
+ `captcha()` throws when:
88
+
89
+ - `apiKey` is missing.
90
+ - No captcha is found on the page and you didn't set `sitekey`. The message is `Could not auto-detect captcha. Please provide sitekey manually.`
91
+ - The solver reports an error, for example a 2captcha error or a timeout. The message starts with `[captcha]`.
92
+
93
+ ## Examples
94
+
95
+ ### Solve a captcha before submitting a form
96
+
97
+ ```javascript tests/signup.test.mjs
98
+ import { describe, expect, it } from 'vitest';
99
+ import { TestDriver } from 'testdriverai/vitest/hooks';
100
+
101
+ describe('Signup', () => {
102
+ it('gets past the captcha', async (context) => {
72
103
  const testdriver = TestDriver(context);
104
+ await testdriver.provision.chrome({ url: 'https://example.com/signup' });
73
105
 
74
- // Navigate to checkout page
75
- await testdriver.provision.chrome({
76
- url: 'https://example.com/checkout',
77
- });
78
-
79
- // Fill out form
80
- await testdriver.type({ text: 'John Doe', selector: '#name' });
81
- await testdriver.type({ text: 'john@example.com', selector: '#email' });
82
-
83
- // Solve the captcha
84
- const result = await testdriver.captcha({
85
- apiKey: process.env.TWOCAPTCHA_API_KEY,
86
- });
106
+ await testdriver.find('Email input field').click();
107
+ await testdriver.type('user@example.com');
87
108
 
109
+ // Solves the captcha, then clicks the form's submit button
110
+ const result = await testdriver.captcha({ apiKey: process.env.TWOCAPTCHA_API_KEY });
88
111
  expect(result.success).toBe(true);
89
112
 
90
- // Submit the form
91
- await testdriver.click({ selector: '#submit' });
92
-
93
- // Verify success
94
- await testdriver.find({ text: 'Order confirmed' });
95
- }, 180000);
113
+ await testdriver.assert('a confirmation message is shown');
114
+ });
96
115
  });
97
116
  ```
98
117
 
99
- ## Environment Variables
100
-
101
- You can set your API key as an environment variable:
118
+ ### Submit the form yourself
102
119
 
103
- ```bash
104
- export TWOCAPTCHA_API_KEY=your_api_key_here
120
+ ```javascript
121
+ await testdriver.captcha({ apiKey: process.env.TWOCAPTCHA_API_KEY, autoSubmit: false });
122
+ await testdriver.find('Create account button').click();
105
123
  ```
106
124
 
107
- Then use it in your tests:
125
+ ### Set the sitekey and type
108
126
 
109
127
  ```javascript
110
- const result = await testdriver.captcha({
128
+ await testdriver.captcha({
111
129
  apiKey: process.env.TWOCAPTCHA_API_KEY,
130
+ sitekey: '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI',
131
+ type: 'recaptcha_v2',
112
132
  });
113
133
  ```
114
134
 
115
- ### GitHub Actions
135
+ ## Set up the API key
116
136
 
117
- Add the key to your repository secrets and expose it in your workflow:
137
+ Sign up at [2captcha.com](https://2captcha.com), add funds, and copy your API key. Keep it out of your test code: put it in `.env` locally, and in a secret in CI.
118
138
 
119
- ```yaml
120
- - name: Run Tests
121
- run: vitest run
139
+ ```bash .env
140
+ TWOCAPTCHA_API_KEY=your_2captcha_key
141
+ ```
142
+
143
+ ```yaml .github/workflows/testdriver.yml
144
+ - name: Run TestDriver tests
145
+ run: npx vitest run
122
146
  env:
123
147
  TWOCAPTCHA_API_KEY: ${{ secrets.TWOCAPTCHA_API_KEY }}
124
148
  ```
125
149
 
126
- ## How It Works
127
-
128
- 1. **Detection**: Scans the page for captcha elements (`data-sitekey`, script tags, etc.)
129
- 2. **Submit**: Sends the captcha challenge to 2captcha's solving service
130
- 3. **Poll**: Waits for human solvers to complete the captcha
131
- 4. **Inject**: Injects the solved token into the page's hidden fields
132
- 5. **Callback**: Triggers any JavaScript callbacks the page expects
133
-
134
150
  ## Troubleshooting
135
151
 
136
- ### "Could not auto-detect captcha"
152
+ <AccordionGroup>
153
+ <Accordion title="Could not auto-detect captcha">
154
+
155
+ The captcha wasn't on the page when `captcha()` ran. Wait for it to load first, for example with `find()` and a `timeout`. If it still isn't detected, pass `sitekey` and `type`.
137
156
 
138
- The captcha element wasn't found on the page. Try:
139
- - Waiting for the page to fully load before calling `captcha()`
140
- - Providing the `sitekey` and `type` manually
157
+ </Accordion>
158
+ <Accordion title="The solve times out">
141
159
 
142
- ### Timeout errors
160
+ 2captcha's workers usually take 10 to 30 seconds. Raise `timeout`, and check that your 2captcha account has funds.
143
161
 
144
- Captcha solving typically takes 10-30 seconds. If you're getting timeouts:
145
- - Increase the `timeout` option
146
- - Check your 2captcha balance
147
- - Verify the captcha type is correct
162
+ </Accordion>
163
+ <Accordion title="The site rejects the token">
148
164
 
149
- ### Token not working
165
+ Check that `type` matches the captcha on the page. For reCAPTCHA v3, check that `action` matches the action the site uses.
150
166
 
151
- Some sites validate tokens immediately. Make sure:
152
- - The token is injected before form submission
153
- - The captcha type matches what the site expects
154
- - For reCAPTCHA v3, the `action` parameter matches the site's expected action
167
+ </Accordion>
168
+ </AccordionGroup>
155
169
 
156
- ## Requirements
170
+ ## Related
157
171
 
158
- - Chrome must be launched with remote debugging enabled (automatic on all sandboxes)
159
- - A valid 2captcha API key with sufficient balance
172
+ - [Launch apps](/provision): open Chrome before solving
173
+ - [Secrets](/secrets): keep API keys out of your tests
174
+ - [type()](/type) and [find()](/find): fill in the rest of the form