Rohan Bhatkande
Rohan Bhatkande

Reputation: 61

How to bypass captcha in Cypress tool

I am trying to create a simple test script of verifying validation message of the sign up page but because of captcha my script is running into the errors. How to bypass it? I am using Cypress version 10, the latest one.

I tried to disable the chrome websecurity to false but still it is not being disabled.

Upvotes: 6

Views: 9751

Answers (1)

Daniel
Daniel

Reputation: 35724

If it was possible to bypass the captcha with a client-side script, it would become useless.

When you're working on an integration test and are mocking all API interactions, you can mock that one too. If it's an e2e test you need to either disable it or be able to pass a valid answer.

There's a couple options available

The simplest might be to use the captcha test keys. info: https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha.-what-should-i-do

For reCAPTCHA v3, create a separate key for testing environments. Scores may not be accurate as reCAPTCHA v3 relies on seeing real traffic.

For reCAPTCHA v2, use the following test keys. You will always get No CAPTCHA and all verification requests will pass.

Site key: 6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
Secret key: 6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe

Note that that will need to be implemented on the server still and would only be possible to run on a testing server and not production.

You can also setup the test server to make sure that the CAPTCHA does not render or that the server bypasses the validation either altogether when it is in test mode, or when provided with a shared secret. The later strategy could be used in production environment though it would make the system vulnerable to bypass if the key was somehow exposed.

Upvotes: 5

Related Questions