Puppetry
3.2.2
3.2.2
  • Welcome Puppetry
  • Getting Started
  • Project
  • Suite
  • Group
  • Target
    • Simple Target
    • iFrame Target
    • ShadowDOM Target
    • Chained Target
    • Shared Target
  • Test Case
  • Test Step / Action
    • Page Commands
    • Page Assertions
    • Target Commands
    • Target Assertions
  • Managing Records
  • Snippets
  • Running tests
    • Interactive Mode
    • Troubleshooting
  • Test Report
  • Export
    • Exporting as Jest Project (CI-friendly)
    • Exporting as Test Specification
  • Settings
  • Template Expressions
  • Testing Techniques
    • Testing Dynamic Content
    • Exhaustive Testing
    • Performance Testing
    • Visual Regression Testing
    • Testing Shadow DOM
    • Testing Google Analytics tracking code
    • Testing Chrome Extensions
    • Testing REST API
    • Mocking HTTP/S Requests
    • Testing Transactional Emails
      • Example with Restmail.net
      • Example with Mailinator
      • Example with IMAP bridge
      • Example with Google API
    • Testing Forms with Captcha
  • Version Control
  • Tips and Tricks
    • Embrace the Power of CSS
  • Command API
  • Test Application
Powered by GitBook
On this page

Was this helpful?

  1. Testing Techniques

Testing Forms with Captcha

PreviousExample with Google APINextVersion Control

Last updated 5 years ago

Was this helpful?

The whole point of Captcha (e.g. ) to ensure the forms filled out by a human. So we cannot simply bypass it with automating tests. However we can still test the forms if we persuade the application under test that we are a trusted source. For example, the application uses a token-based authentication. From Puppetry side by using page.runjs command we can login under a test account and provide to the application the received token as certificate. The application checks if the token valid and disable Captcha for the session (obviously not on the production environment). Let's say we feed to page.runjs the following function:

const rsp = await fetch( "https://rest-api-sandbox.local/api/v1/login", {
    method: 'POST',         
    body: JSON.stringify({
      email: process.env.QA_EMAIL
      password: process.env.QA_PASSWORD
    })
});
ENV.SESSION_TOKEN = rsp.json().token;

As you can see define a dynamic template variable as ENV.<VARIABLE NAME>. The same way template variables can be accessed in the code .

Next we can use page.setCookie command to pass the retrieved token to the app server:

The application server validates the token if any available in TRUSTED_CLIENT_TOKEN cookie and disables the captcha for the session.

Recaptcha