Solve CAPTCHAs in Cypress tests with DeathByCaptcha

Solve CAPTCHAs in Cypress tests with DeathByCaptcha

Posted on 2026-11-27 | 3 min read | Category: captcha-automation | By DeathByCaptcha Engineering Team

CAPTCHA Automation


Solve CAPTCHAs in Cypress tests with DeathByCaptcha

A Cypress suite that stops at a login or a checkout form is not a failed test, it is a test that never ran. The fix is a task that asks DeathByCaptcha for the answer and hands it to the page before the assertion.

Where the solve happens

Cypress runs its tests in the browser, but tasks run in Node. That is the whole design of this example: the official client is loaded in the task, so

  • the credentials never reach the browser or the test bundle;
  • the token is returned to the test instead of printed, which keeps it out of the command log and out of the output of a CI job;
  • one task serves every spec, and the browser side stays a five-line command.

Nothing is installed by Cypress. The example is a folder you copy.

Files

File What it is
examples/cypress/deathbycaptcha.tasks.js the tasks: dbcBalance, dbcSolveImage, dbcSolveRecaptchaV2, dbcSolveRecaptchaV3, dbcSolveTurnstile
examples/cypress/cypress.config.js a sample project that registers them
examples/cypress/cypress/support/commands.js the cy.dbc* commands
examples/cypress/cypress/e2e/recaptcha_v2.cy.js a spec that solves and submits

Setup

npm install deathbycaptcha-lib   # the official Node client
export DBC_USERNAME=your_username
export DBC_PASSWORD=your_password
# or: export DBC_AUTHTOKEN=your_authtoken

Register the tasks once, in your cypress.config.js:

const { defineConfig } = require('cypress');
const { createDbcTasks } = require('./deathbycaptcha.tasks');

module.exports = defineConfig({
  e2e: {
    supportFile: 'cypress/support/e2e.js',
    setupNodeEvents(on) {
      on('task', createDbcTasks());
    },
  },
});

The commands

Command Type Returns
cy.dbcSolveRecaptchaV2(sitekey, pageurl) 4 the token
cy.dbcSolveRecaptchaV3(sitekey, pageurl, { action, minScore }) 5 the token
cy.dbcSolveTurnstile(sitekey, pageurl) 12 the token
cy.dbcSolveImage(imagePath) 0 the text to type
cy.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 sample spec does

  1. Visits Google's reCAPTCHA demo — the vendor's own page, not a third party's production site.
  2. Reads data-sitekey from the page instead of typing it in.
  3. cy.dbcSolveRecaptchaV2(sitekey, pageurl) asks for a token.
  4. Writes it into #g-recaptcha-response and calls the widget's own callback.
  5. Submits and asserts .recaptcha-success.

Those are the same five steps as the Playwright and Puppeteer samples in this repository, so a team can compare the three before choosing one.

The rule that catches people out

A token answer is valid only from the exit IP that solved it. If the page your test drives leaves through a proxy, the solve has to leave through that same proxy — pass proxy and proxytype in the parameters. Without them the token is solved from your runner's address and the site rejects it, which looks like a DeathByCaptcha failure and is not one.

An image CAPTCHA has no such constraint: the picture is taken from the browser, not from the network.

Limits

  • Test what you are allowed to automate. These tests are for your own pages — staging, a demo, a checkout you own. See RESPONSIBLE_USE.md.
  • reCAPTCHA v3 needs the action and the min_score the 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 log the token. The tasks return their value and never print it, and the sample does not call cy.log with it. Keep that when you extend them.

Tests

npm run test:unit                                    # task tests, no network
DBC_USERNAME=... DBC_PASSWORD=... npm run test:integration:cypress

The integration test runs the real spec against the live API and skips itself when the credentials are not in the environment. It also fails if the output of the run carries anything that looks like a token.

Next steps

  • Tasks, commands and spec: https://github.com/deathbycaptcha/deathbycaptcha-api-client-nodejs
  • API documentation: https://deathbycaptcha.com/api

Common pitfalls

  • Using a CAPTCHA solving service for illegitimate purposes instead of legitimate automation and testing.
  • Hard-coding credentials or API keys in client-side code that users can inspect.
  • Sending the wrong CAPTCHA type parameter, which returns incorrect or empty responses.
  • Failing to poll for the solution status and not handling timeouts gracefully.
  • Scaling automation without monitoring error rates, response times, and CAPTCHA type coverage.
DBC
Written by DeathByCaptcha Engineering Team
DeathByCaptcha engineers build and operate the CAPTCHA solving technology behind this site. Articles are written by our technical team and checked for accuracy before publishing.
Reviewed by DeathByCaptcha Editorial Team

Get your API key — start solving

Free to try · No credit card · Python, Node.js, Java, C# SDKs

Get your API key


Status: OK

Servers are fully operational with faster than average response time.
  • Average solving time
  • 8 seconds - Normal CAPTCHAs (1 min. ago)
  • 3 seconds - reCAPTCHA V2, V3 (1 min. ago)
  • 11 seconds - others (1 min. ago)
Chrome and Firefox logos
Browser extensions available

Updates

  1. Nov 19: RESOLVED - Crypto payments are now fully operational again through the Hekelet payment processor.
  2. May 13: Crypto payments got better! You can now purchase your CAPTCHAs using cryptocurrency through the Hekelet payment processor at https://deathbycaptcha.com/user-pay and receive an extra 20% FREE CAPTCHA credit with every package purchased this way.
  3. Apr 15: GitHub Updates: We’ve upgraded our libraries, expanded sample code, enhanced documentation, and added support for C++ and Go, making integration smoother than ever. Explore what’s new at github.com/deathbycaptcha!

  4. Previous updates…

Support

Our system is designed to be completely user-friendly and easy-to-use. Should you have any trouble with it, simply email us at DBC technical support emailcom, and a support agent will get back to you as soon as possible.

Live Support

Available Monday to Friday (10am to 4pm EST) Live support image. Link to live support page