5

We have a site that uses the CAPTCHA and CAPTCHA After modules to protect forms from invalid submissions. We're doing some functional and BDD testing using Behat and the tests are sometimes triggering the CAPTCHA After thresholds, causing the CAPTCHA to be displayed. Is there an easy way to bypass the CAPTCHA, when performing tests?

I realize that we can probably override the CAPTCHA After threshold settings in the database, if the tests are running on the same machine. However, it would be nice to also be able to run the tests from a different machine than the web server hosting the site. I think that something like an IP whitelist might work, but I haven't found anything along those lines yet. Before we start coding something like that, anyone have a better idea?

Thanks!

1

Using the API Driver you can, as you say, modify CAPTCHA After threshold and restore it at the end of test, but you need to execute tests in the same machine.

If you want to do it form another machine you have to set up a way to alter that variable from outside. You can define a hook menu that alters that variable, in a dev module that will not be enabled in production site. You can also set up a drush remote command that modifies the threshold in th remote machine and restores and the end of the test. You can add this drush command in the script that lauchhes behat tests or even inside behat in a behat hook.

| improve this answer | |
1

I realize this thread is almost two years old, but in the event someone finds this, you should be able to disable captcha in settings.php files. For example if you are running site locally, local.settings.php, or if CI, something like travis.settings.php (or whatever you use).

For each place captcha is used, you would have an entry for the config setting ie. for login form:

$config['captcha.captcha_point.user_login_form']['status'] = FALSE;

If you are unsure of the setting, on whatever page you want to remove CAPTCHA you should be able to inspect the global $config[] and find the relevant setting set to TRUE. Setting it back to false in the relevant settings.php should remove captcha entirely.

Be careful that you do not accidentally put it in a settings.php that is used by your live site, or you will disable CAPTCHA!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.