A recaptcha test that proves something, and the ones that only go green
Most reCAPTCHA problems I get asked about turn out not to be captcha problems. They are tests that pass for the wrong reason: a green pipeline, a production form that keeps rejecting real people, and nobody able to say which of the two changed. Separating the two is mostly a matter of deciding what you actually mean by a recaptcha test. Three different things people call "testing the captcha"…
Many "reCAPTCHA test" issues turn out to be false positives, often due to quirks like a green pipeline, a production form rejecting real users, or an unclear definition of what constitutes a "reCAPTCHA test". There are three ways people refer to testing reCAPTCHA: rendering the widget, confirming the existence of the g-recaptcha element, or verifying that the grecaptcha.render function doesn't throw an error.
These checks happen quickly, without affecting the backend and work offline. However, the real test is whether the verification process works for an actual person who completes the challenge. This includes the backend posting a token to Google's siteverify endpoint and observing the result. While Level 1 and Level 2 of this process should be included in every commit, Level 3 should be run separately during releases.
Mixing these levels can cause false positives - the suite may appear green while the signup form remains broken. Google provides fixed test keys for reCAPTCHA v2, but these should never be used in production as they bypass the warning banner and allow bots to pass through undetected. Using these keys in staging is acceptable since localhost isn't typically on the key's allowed domain list. reCAPTCHA v3 does not have test keys, so relying on scores is not advisable.
Instead, focus on deterministic aspects like token presence in the hidden field, successful siteverify responses, and proper form rejection when the token field is empty or missing. Turnstile provides dummy keys for testing that cover both passing and failing scenarios, along with specific secrets for validation errors. When testing, it's crucial to write negative tests before any token minting occurs.
These tests should check scenarios like missing token fields, empty strings, and duplicate submissions. Additionally, tests should account for token lifetimes and ensure they are verified only once. Finally, for a complete test, a genuine token needs to be obtained through an API or staging server call, covering edge cases like domain mismatches, invisible v3 tokens, and widget placement within third-party iframes.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.