How Do I Run Automated Tests With MTCaptcha?

mtcaptcha-auto-test-screenshot.png

MTCaptcha supports automated browser UI/UX testing via tools like Selenium,  without having to disable the captcha plugin.  

There are two methods to enable automation test scripts to consistently solve the captcha:

Method 1:

  • Call javascript function mtcaptcha.enableTestMode with the TestKey, once the MTCaptcha plugin is loaded. eg:
  •   mtcaptcha.enableTestMode(“<TestKey>”);
  • Than enter the text string ‘1111111111’ into the captcha text form
  • (entering any other string eg ‘2222222222’ will result in verification failure)

Method 2:

  • Set the TestKey within MTCaptcha’s javascript initialization config object, before importing/loading the MTCaptcha plugin, eg
 var mtcaptchaConfig = {
         “sitekey”:           “<SiteKey>”,
         “enableTestMode” :   “<TestKey>”
   };
  • Enter the text string ‘11111111’ into the captcha text form  
  • (entering any other string eg ‘22222222’ will result in verification failure)
  • The TestKey for each site can be found in the Admin Portal along with the SiteKey and PrivateKey. Usually with the prefix ‘MTPrivQA-’. This key should be kept secrete.
  • The captcha plugin will generate a Verified Token once solved via a TestKey, the same as if a user solved the captcha manually.
  • To check if a Verified Token is the result of using the TestKey, the decoded token information (JSON) will have the corresponding code (301) and codeDesc ‘valid-test:captcha-solved-via-testkey’.
  {
    "success": true,
    "tokeninfo": {
      "code": 301,
      "codeDesc": "valid-test:captcha-solved-via-testkey",
      ...
    }
  }

See our Developers Guide for more information on MTCaptcha JavaScript APIs, and Token Codes

NOTE:

The purpose of this feature is to support automated unit tests for user interface and interactions. It is not intended to support long running load or performance tests. The captcha may temporarily block test server IP(s) if it is load tested for long periods of time.

REFERENCES

   Stack Overflow: How to call a JavaScript function from within Selenium

   Stack Overflow: Selenium : Call javascript function on page.