testdriverai 7.2.56 → 7.2.58
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/.env.example +2 -0
- package/.github/workflows/acceptance-windows-scheduled.yaml +29 -28
- package/.github/workflows/acceptance.yaml +54 -52
- package/.github/workflows/publish.yaml +59 -43
- package/.github/workflows/testdriver.yml +157 -156
- package/.github/workflows/windows-self-hosted.yaml +60 -46
- package/CHANGELOG.md +10 -0
- package/docs/docs.json +1 -0
- package/docs/v7/captcha.mdx +160 -0
- package/examples/captcha-api.test.mjs +50 -0
- package/lib/captcha/solver.js +296 -0
- package/lib/core/Dashcam.js +135 -95
- package/lib/vitest/hooks.mjs +175 -126
- package/lib/vitest/setup-aws.mjs +69 -46
- package/package.json +1 -1
- package/sdk.d.ts +67 -20
- package/sdk.js +733 -402
- package/test/captcha-solver.test.mjs +70 -0
- package/test/chrome-remote-debugging.test.mjs +66 -0
- package/vitest.config.mjs +10 -6
|
@@ -2,168 +2,169 @@ name: TestDriver.ai Tests
|
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
push:
|
|
5
|
-
branches: [
|
|
5
|
+
branches: [main, master]
|
|
6
6
|
pull_request:
|
|
7
|
-
branches: [
|
|
7
|
+
branches: [main, master]
|
|
8
8
|
|
|
9
9
|
jobs:
|
|
10
10
|
test:
|
|
11
11
|
runs-on: ubuntu-latest
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
permissions:
|
|
14
14
|
contents: read
|
|
15
|
-
pull-requests: write
|
|
15
|
+
pull-requests: write # Required to post comments on PRs
|
|
16
16
|
|
|
17
17
|
steps:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Setup Node.js
|
|
21
|
+
uses: actions/setup-node@v4
|
|
22
|
+
with:
|
|
23
|
+
node-version: "20"
|
|
24
|
+
cache: "npm"
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: npm ci
|
|
28
|
+
|
|
29
|
+
- name: Run TestDriver.ai tests
|
|
30
|
+
env:
|
|
31
|
+
TD_API_KEY: ${{ secrets.TD_API_KEY }}
|
|
32
|
+
TWOCAPTCHA_API_KEY: ${{ secrets.TWOCAPTCHA_API_KEY }}
|
|
33
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
34
|
+
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
35
|
+
run: npx vitest run
|
|
36
|
+
|
|
37
|
+
- name: Upload test results
|
|
38
|
+
if: always()
|
|
39
|
+
uses: actions/upload-artifact@v4
|
|
40
|
+
with:
|
|
41
|
+
name: test-results
|
|
42
|
+
path: test-results/
|
|
43
|
+
retention-days: 30
|
|
44
|
+
|
|
45
|
+
# Init command test - only runs on PRs, not on main/master
|
|
46
|
+
- name: Create test directory for init
|
|
47
|
+
if: github.event_name == 'pull_request'
|
|
48
|
+
run: |
|
|
49
|
+
mkdir -p /tmp/test-init-project
|
|
50
|
+
cd /tmp/test-init-project
|
|
51
|
+
|
|
52
|
+
- name: Run init command (skip prompts)
|
|
53
|
+
if: github.event_name == 'pull_request'
|
|
54
|
+
working-directory: /tmp/test-init-project
|
|
55
|
+
run: |
|
|
56
|
+
# Create .env with API key first to skip the prompt
|
|
57
|
+
echo "TD_API_KEY=${{ secrets.TD_API_KEY }}" > .env
|
|
58
|
+
|
|
59
|
+
# Run init command using the CLI from the repo
|
|
60
|
+
node ${{ github.workspace }}/bin/testdriverai.js init
|
|
61
|
+
env:
|
|
62
|
+
TD_API_KEY: ${{ secrets.TD_API_KEY }}
|
|
63
|
+
|
|
64
|
+
- name: Verify project structure
|
|
65
|
+
if: github.event_name == 'pull_request'
|
|
66
|
+
working-directory: /tmp/test-init-project
|
|
67
|
+
run: |
|
|
68
|
+
echo "Checking generated files..."
|
|
69
|
+
|
|
70
|
+
# Check for package.json
|
|
71
|
+
if [ ! -f "package.json" ]; then
|
|
72
|
+
echo "❌ package.json not found"
|
|
73
|
+
exit 1
|
|
74
|
+
fi
|
|
75
|
+
echo "✓ package.json exists"
|
|
76
|
+
|
|
77
|
+
# Check for vitest config
|
|
78
|
+
if [ ! -f "vitest.config.js" ]; then
|
|
79
|
+
echo "❌ vitest.config.js not found"
|
|
80
|
+
exit 1
|
|
81
|
+
fi
|
|
82
|
+
echo "✓ vitest.config.js exists"
|
|
83
|
+
|
|
84
|
+
# Check for test file
|
|
85
|
+
if [ ! -f "tests/example.test.js" ]; then
|
|
86
|
+
echo "❌ tests/example.test.js not found"
|
|
87
|
+
exit 1
|
|
88
|
+
fi
|
|
89
|
+
echo "✓ tests/example.test.js exists"
|
|
90
|
+
|
|
91
|
+
# Check for .env file
|
|
92
|
+
if [ ! -f ".env" ]; then
|
|
93
|
+
echo "❌ .env not found"
|
|
94
|
+
exit 1
|
|
95
|
+
fi
|
|
96
|
+
echo "✓ .env exists"
|
|
97
|
+
|
|
98
|
+
# Check for .gitignore
|
|
99
|
+
if [ ! -f ".gitignore" ]; then
|
|
100
|
+
echo "❌ .gitignore not found"
|
|
101
|
+
exit 1
|
|
102
|
+
fi
|
|
103
|
+
echo "✓ .gitignore exists"
|
|
104
|
+
|
|
105
|
+
# Check for GitHub workflow
|
|
106
|
+
if [ ! -f ".github/workflows/testdriver.yml" ]; then
|
|
107
|
+
echo "❌ .github/workflows/testdriver.yml not found"
|
|
108
|
+
exit 1
|
|
109
|
+
fi
|
|
110
|
+
echo "✓ .github/workflows/testdriver.yml exists"
|
|
111
|
+
|
|
112
|
+
- name: Verify vitest config contents
|
|
113
|
+
if: github.event_name == 'pull_request'
|
|
114
|
+
working-directory: /tmp/test-init-project
|
|
115
|
+
run: |
|
|
116
|
+
echo "Checking vitest.config.js contents..."
|
|
117
|
+
|
|
118
|
+
# Check for TestDriver reporter
|
|
119
|
+
if ! grep -q "TestDriver()" vitest.config.js; then
|
|
120
|
+
echo "❌ TestDriver reporter not found in vitest.config.js"
|
|
121
|
+
cat vitest.config.js
|
|
122
|
+
exit 1
|
|
123
|
+
fi
|
|
124
|
+
echo "✓ TestDriver reporter is configured"
|
|
125
|
+
|
|
126
|
+
# Check for setupFiles
|
|
127
|
+
if ! grep -q "setupFiles.*testdriverai/vitest/setup" vitest.config.js; then
|
|
128
|
+
echo "❌ setupFiles not configured correctly"
|
|
129
|
+
cat vitest.config.js
|
|
130
|
+
exit 1
|
|
131
|
+
fi
|
|
132
|
+
echo "✓ setupFiles is configured"
|
|
133
|
+
|
|
134
|
+
- name: Verify test file contents
|
|
135
|
+
if: github.event_name == 'pull_request'
|
|
136
|
+
working-directory: /tmp/test-init-project
|
|
137
|
+
run: |
|
|
138
|
+
echo "Checking test file contents..."
|
|
139
|
+
|
|
140
|
+
# Check for .provision usage
|
|
141
|
+
if ! grep -q "\.provision\.chrome" tests/example.test.js; then
|
|
142
|
+
echo "❌ Test does not use .provision.chrome"
|
|
143
|
+
cat tests/example.test.js
|
|
144
|
+
exit 1
|
|
145
|
+
fi
|
|
146
|
+
echo "✓ Test uses .provision.chrome"
|
|
147
|
+
|
|
148
|
+
# Check for TestDriver import
|
|
149
|
+
if ! grep -q "from 'testdriverai/vitest/hooks'" tests/example.test.js; then
|
|
150
|
+
echo "❌ Test does not import from testdriverai/vitest/hooks"
|
|
151
|
+
cat tests/example.test.js
|
|
152
|
+
exit 1
|
|
153
|
+
fi
|
|
154
|
+
echo "✓ Test imports TestDriver from vitest/hooks"
|
|
155
|
+
|
|
156
|
+
- name: Run the generated test
|
|
157
|
+
if: github.event_name == 'pull_request'
|
|
158
|
+
working-directory: /tmp/test-init-project
|
|
159
|
+
run: npm test
|
|
160
|
+
env:
|
|
161
|
+
TD_API_KEY: ${{ secrets.TD_API_KEY }}
|
|
162
|
+
|
|
163
|
+
- name: Upload init test results
|
|
164
|
+
if: always() && github.event_name == 'pull_request'
|
|
165
|
+
uses: actions/upload-artifact@v4
|
|
166
|
+
with:
|
|
167
|
+
name: test-init-results
|
|
168
|
+
path: /tmp/test-init-project/test-results/
|
|
169
|
+
retention-days: 7
|
|
170
|
+
if-no-files-found: warn
|
|
@@ -4,13 +4,15 @@ on:
|
|
|
4
4
|
workflow_call:
|
|
5
5
|
inputs:
|
|
6
6
|
test_pattern:
|
|
7
|
-
description:
|
|
7
|
+
description: "Test file pattern to run"
|
|
8
8
|
required: false
|
|
9
9
|
type: string
|
|
10
|
-
default:
|
|
10
|
+
default: "examples/*.test.mjs"
|
|
11
11
|
secrets:
|
|
12
12
|
TD_API_KEY:
|
|
13
13
|
required: true
|
|
14
|
+
TWOCAPTCHA_API_KEY:
|
|
15
|
+
required: true
|
|
14
16
|
TD_WEBSITE:
|
|
15
17
|
required: false
|
|
16
18
|
AWS_ACCESS_KEY_ID:
|
|
@@ -21,48 +23,60 @@ on:
|
|
|
21
23
|
jobs:
|
|
22
24
|
test:
|
|
23
25
|
runs-on: ubuntu-latest
|
|
24
|
-
|
|
26
|
+
|
|
25
27
|
steps:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
28
|
+
- name: Checkout repository
|
|
29
|
+
uses: actions/checkout@v4
|
|
30
|
+
with:
|
|
31
|
+
fetch-depth: 0
|
|
32
|
+
|
|
33
|
+
- name: Set up Node.js
|
|
34
|
+
uses: actions/setup-node@v4
|
|
35
|
+
with:
|
|
36
|
+
node-version: "20"
|
|
37
|
+
cache: "npm"
|
|
38
|
+
|
|
39
|
+
- name: Install dependencies
|
|
40
|
+
run: npm ci
|
|
41
|
+
|
|
42
|
+
- name: Debug Environment
|
|
43
|
+
run: |
|
|
44
|
+
echo "Checking environment variables..."
|
|
45
|
+
if [ -n "${{ secrets.TWOCAPTCHA_API_KEY }}" ]; then
|
|
46
|
+
echo "TWOCAPTCHA_API_KEY is set (length: ${#TWOCAPTCHA_API_KEY})"
|
|
47
|
+
else
|
|
48
|
+
echo "TWOCAPTCHA_API_KEY is NOT set"
|
|
49
|
+
fi
|
|
50
|
+
env:
|
|
51
|
+
TWOCAPTCHA_API_KEY: ${{ secrets.TWOCAPTCHA_API_KEY }}
|
|
52
|
+
|
|
53
|
+
- name: Run Windows tests with self-hosted instances
|
|
54
|
+
run: npx vitest run ${{ inputs.test_pattern }}
|
|
55
|
+
env:
|
|
56
|
+
TD_API_KEY: ${{ secrets.TD_API_KEY }}
|
|
57
|
+
TWOCAPTCHA_API_KEY: ${{ secrets.TWOCAPTCHA_API_KEY }}
|
|
58
|
+
TD_WEBSITE: ${{ secrets.TD_WEBSITE }}
|
|
59
|
+
TD_OS: windows
|
|
60
|
+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
61
|
+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
62
|
+
AWS_REGION: us-east-2
|
|
63
|
+
AWS_LAUNCH_TEMPLATE_ID: lt-0ef9bf26a945fb442
|
|
64
|
+
AMI_ID: ami-0dd5fa241273a7d50
|
|
65
|
+
RESOLUTION: 1920x1080
|
|
66
|
+
|
|
67
|
+
- name: Upload test results
|
|
68
|
+
if: always()
|
|
69
|
+
uses: actions/upload-artifact@v4
|
|
70
|
+
with:
|
|
71
|
+
name: test-results-windows
|
|
72
|
+
path: test-report.junit.xml
|
|
73
|
+
retention-days: 30
|
|
74
|
+
|
|
75
|
+
- name: Upload TestDriver AI CLI logs
|
|
76
|
+
if: always()
|
|
77
|
+
uses: actions/upload-artifact@v4
|
|
78
|
+
with:
|
|
79
|
+
name: testdriverai-cli-logs-windows
|
|
80
|
+
path: /tmp/testdriverai-cli-*.log
|
|
81
|
+
if-no-files-found: warn
|
|
82
|
+
retention-days: 30
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
## [7.2.58](https://github.com/testdriverai/testdriverai/compare/v6.1.8...v7.2.58) (2026-01-27)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Reverts
|
|
5
|
+
|
|
6
|
+
* Revert "list dashcam version g" ([5037571](https://github.com/testdriverai/testdriverai/commit/5037571440c33f8966104874c542c6c57a809510))
|
|
7
|
+
* Revert "update discord invite" ([b5a9b99](https://github.com/testdriverai/testdriverai/commit/b5a9b9955cf2b0b07fd0ebeb6abf65f89cd3d5a8))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
package/docs/docs.json
CHANGED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "captcha()"
|
|
3
|
+
sidebarTitle: "captcha"
|
|
4
|
+
description: "Solve captchas using 2captcha service"
|
|
5
|
+
icon: "shield-check"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Captcha Solving
|
|
9
|
+
|
|
10
|
+
TestDriver can automatically solve captchas during your tests using the 2captcha service. This feature works on both **Linux** and **Windows** sandboxes.
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
```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
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
That's it! TestDriver will automatically:
|
|
25
|
+
- Detect the captcha type on the page
|
|
26
|
+
- Extract the sitekey
|
|
27
|
+
- Solve the captcha via 2captcha
|
|
28
|
+
- Inject the token into the page
|
|
29
|
+
- Trigger any callbacks
|
|
30
|
+
|
|
31
|
+
## Supported Captcha Types
|
|
32
|
+
|
|
33
|
+
| Type | Auto-Detected | Notes |
|
|
34
|
+
|------|---------------|-------|
|
|
35
|
+
| reCAPTCHA v2 | ✅ | Including invisible |
|
|
36
|
+
| reCAPTCHA v3 | ✅ | Action is auto-detected |
|
|
37
|
+
| hCaptcha | ✅ | |
|
|
38
|
+
| Cloudflare Turnstile | ✅ | |
|
|
39
|
+
|
|
40
|
+
## Getting a 2captcha API Key
|
|
41
|
+
|
|
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
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
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) => {
|
|
72
|
+
const testdriver = TestDriver(context);
|
|
73
|
+
|
|
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
|
+
});
|
|
87
|
+
|
|
88
|
+
expect(result.success).toBe(true);
|
|
89
|
+
|
|
90
|
+
// Submit the form
|
|
91
|
+
await testdriver.click({ selector: '#submit' });
|
|
92
|
+
|
|
93
|
+
// Verify success
|
|
94
|
+
await testdriver.find({ text: 'Order confirmed' });
|
|
95
|
+
}, 180000);
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Environment Variables
|
|
100
|
+
|
|
101
|
+
You can set your API key as an environment variable:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
export TWOCAPTCHA_API_KEY=your_api_key_here
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Then use it in your tests:
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
```javascript
|
|
111
|
+
const result = await testdriver.captcha({
|
|
112
|
+
apiKey: process.env.TWOCAPTCHA_API_KEY,
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### GitHub Actions
|
|
117
|
+
|
|
118
|
+
Add the key to your repository secrets and expose it in your workflow:
|
|
119
|
+
|
|
120
|
+
```yaml
|
|
121
|
+
- name: Run Tests
|
|
122
|
+
run: npm test
|
|
123
|
+
env:
|
|
124
|
+
TWOCAPTCHA_API_KEY: ${{ secrets.TWOCAPTCHA_API_KEY }}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## How It Works
|
|
128
|
+
|
|
129
|
+
1. **Detection**: Scans the page for captcha elements (`data-sitekey`, script tags, etc.)
|
|
130
|
+
2. **Submit**: Sends the captcha challenge to 2captcha's solving service
|
|
131
|
+
3. **Poll**: Waits for human solvers to complete the captcha
|
|
132
|
+
4. **Inject**: Injects the solved token into the page's hidden fields
|
|
133
|
+
5. **Callback**: Triggers any JavaScript callbacks the page expects
|
|
134
|
+
|
|
135
|
+
## Troubleshooting
|
|
136
|
+
|
|
137
|
+
### "Could not auto-detect captcha"
|
|
138
|
+
|
|
139
|
+
The captcha element wasn't found on the page. Try:
|
|
140
|
+
- Waiting for the page to fully load before calling `captcha()`
|
|
141
|
+
- Providing the `sitekey` and `type` manually
|
|
142
|
+
|
|
143
|
+
### Timeout errors
|
|
144
|
+
|
|
145
|
+
Captcha solving typically takes 10-30 seconds. If you're getting timeouts:
|
|
146
|
+
- Increase the `timeout` option
|
|
147
|
+
- Check your 2captcha balance
|
|
148
|
+
- Verify the captcha type is correct
|
|
149
|
+
|
|
150
|
+
### Token not working
|
|
151
|
+
|
|
152
|
+
Some sites validate tokens immediately. Make sure:
|
|
153
|
+
- The token is injected before form submission
|
|
154
|
+
- The captcha type matches what the site expects
|
|
155
|
+
- For reCAPTCHA v3, the `action` parameter matches the site's expected action
|
|
156
|
+
|
|
157
|
+
## Requirements
|
|
158
|
+
|
|
159
|
+
- Chrome must be launched with remote debugging enabled (automatic on all sandboxes)
|
|
160
|
+
- A valid 2captcha API key with sufficient balance
|