Automated Testing Via Testkey

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

mtcaptcha-auto-test-screenshot.png

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:
  <script>
    mtcaptcha.enableTestMode(“<TestKey>”); 
  </script>

  • Than enter the text ‘11111111’ into the captcha widget text form
  • (entering any other string eg ‘22222222’ will result in verification failure)

Method 2:

  • Set the <TestKey> via the ‘enableTestMode javascript config param
  <script>
     var mtcaptchaConfig = {
           “sitekey”:           “<SiteKey>”,
           “enableTestMode” :   “<TestKey>”
     };
     ...
  </script>
  • Then enter the text ‘11111111’ into the captcha widget text form
  • (entering any other string eg ‘22222222’ will result in verification failure)

Where Can I Find The Testkey?

The TestKey for each site can be found in the Admin Portal along with the SiteKey and PrivateKey. Usually with the prefix ‘MTPrivQA-’. Note: The TestKey should be kept secret.


Check If Verifiedtoken Is Result Of Automated Testing

The captcha will create a VerifiedToken once solved using a TestKey, the same as if a user solved the captcha manually.

To check if a VerifiedToken is the result of using the TestKey, the decoded token information (JSON) will have the corresponding TokenInfo.code of 301 and codeDesc ‘valid-test:captcha-solved-via-testkey’.  CheckToken API Response:

  {
    "success": true,
    "tokeninfo": {
      "code": 301,
      "codeDesc": "valid-test:captcha-solved-via-testkey",
      ...
    }
  }

See our Developers Guide - Validate Token -  for more information on VerifiedToken, CheckToken API, and TokenInfo 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 loaded 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.