Solve CAPTCHAs in WebdriverIO tests with DeathByCaptcha
A WebdriverIO suite that stops at a protected form is not a failed test, it is a test that never ran. The fix is a command that asks DeathByCaptcha for the answer and gives it to the page.
Where the solve happens
WebdriverIO runs the specs in a worker process, not in the browser. That is the whole design of this example: the official client is loaded in the worker, so
- the credentials never reach the page or the session;
- the token is returned to the spec instead of printed, which keeps it out of the log and out of a CI job's output;
- one service serves every spec.
Nothing is published as an npm package. The example is a folder you copy.
Files
| File | What it is |
|---|---|
examples/webdriverio/deathbycaptcha.solve.js |
the solvers: promises over the official client, testable without a browser |
examples/webdriverio/deathbycaptcha.service.js |
the service that turns them into commands |
examples/webdriverio/wdio.conf.js |
a configuration that registers it |
examples/webdriverio/specs/recaptcha_v2.spec.js |
a spec that solves and submits |
Setup
npm install deathbycaptcha-lib @wdio/cli @wdio/local-runner @wdio/mocha-framework @wdio/spec-reporter
export DBC_USERNAME=your_username
export DBC_PASSWORD=your_password
# or: export DBC_AUTHTOKEN=your_authtoken
Register the service in wdio.conf.js:
const DeathByCaptchaService = require('./deathbycaptcha.service').default;
exports.config = {
services: [[DeathByCaptchaService, {}]],
};
Pass the class, not a path: the launcher resolves a string such as
'./deathbycaptcha.service.js' as an npm package (@wdio/...-service)
and fails to start.
The commands
| Command | Type | Returns |
|---|---|---|
browser.dbcSolveRecaptchaV2(sitekey, pageurl) |
4 | the token |
browser.dbcSolveRecaptchaV3(sitekey, pageurl, { action, minScore }) |
5 | the token |
browser.dbcSolveTurnstile(sitekey, pageurl) |
12 | the token |
browser.dbcSolveImage(imagePath) |
0 | the text to type |
browser.dbcBalance() |
— | balance in US cents |
sitekey and pageurl have to be the ones of the page under test: the
service answers a token for the pair it is given, and the site rejects it
for any other. An optional timeout in seconds goes as the third
argument; an empty value keeps the client's own default.
What the spec does
- Visits Google's reCAPTCHA demo — the vendor's own page, not a third party's production site.
- Reads the
data-sitekeyfrom the page instead of typing it in. browser.dbcSolveRecaptchaV2(sitekey, pageurl)asks for a token.- Writes it into
#g-recaptcha-responseand calls the widget's callback — the same walk as the Playwright, Puppeteer and Cypress samples in the repository, so a team can compare the four. - Submits and waits for
.recaptcha-success.
npx wdio run examples/webdriverio/wdio.conf.js # headless by default
WDIO_HEADED=true npx wdio run examples/webdriverio/wdio.conf.js
The log trap
The configuration runs at logLevel: 'warn' on purpose. At info
level the driver prints the RESULT of every command it sends, and the
result of the injection is the token — a test log that leaks the very
thing it just bought. The integration test asserts that no token-shaped
string appears in the output, so a regression here fails the build.
Version
The example runs on WebdriverIO v9. Version 10 needs Node 22 or
newer (undici uses zstd), and this repository supports Node 20; v9
runs on both.
The rule that catches people out
A token answer is valid only from the exit IP that solved it. The solve
runs on the machine that runs the test, so a solve and the request it is
pasted into leave from the same machine — unless your test drives a page
through a proxy, in which case pass the same proxy and proxytype in
the parameters.
Limits
- QA on your own pages. These tests are for flows you are allowed to
automate — staging, a demo, a page you own. See
RESPONSIBLE_USE.md. - reCAPTCHA v3 needs the
actionand themin_scorethe site expects; a mismatch is a token the site refuses. - Images need a file: take the screenshot in the test and pass the path.
- Never print the token: the commands return it as a value and nothing else should echo it.
Tests
npm run test:unit # solver tests, no network
DBC_USERNAME=... DBC_PASSWORD=... npm run test:integration:webdriverio
The unit tests replace the client with a fake. The integration test runs the real spec in Chrome against the live API, checks that it passed and fails if anything in the output looks like a token. It skips itself when the credentials are not in the environment.
Next steps
- Service, commands and spec: https://github.com/deathbycaptcha/deathbycaptcha-api-client-nodejs
- API documentation: https://deathbycaptcha.com/api

English
Spanish
Russian
Chinese
French
Hindi
Arabic
Bengali
Indonesian
Portuguese
com, 