A captcha and automated tests are at odds by design.
Three approaches work well:
Mock the verification in your backend
In test mode let your verify function return true without calling the API.
Everything else stays identical.
This is the recommended approach.
PHP
if (getenv('APP_ENV') === 'test') {
$ok = true;
} else {
$ok = cdp_captcha_verify($_POST['cdp-captcha-solution'] ?? '');
}Let the browser solve it
Headless browsers (Playwright, Puppeteer, Selenium) can run the Web Worker.
Wait for the complete event or for the hidden field to be filled, then submit.
Use the lowest difficulty on a test sitekey to keep runs fast.
JavaScript
await page.waitForFunction(() =>
document.querySelector('.cdp-captcha').getAttribute('data-state') === 'completed');
await page.click('button[type=submit]');Allow-list the test runner
If end-to-end tests run against production, skip the check for the known addresses of your test runner, or accept a secret value in the form that only your tests know.
Keep such bypasses out of the client code.
