Puppetry
2.0.0
2.0.0
  • Welcome Puppetry
  • Getting Started
  • Project
  • Suite
  • Group
  • Target
  • Test Case
  • Test Step
    • Page Commands
    • Page Assertions
    • Target Commands
    • Target Assertions
  • Managing Assets
  • Snippets
  • Running tests
    • Troubleshooting
  • Exporting Tests for CI
  • Template Expressions
  • Version Control
  • Testing Transactional Emails
    • Example with Restmail.net
    • Example with Mailinator
    • Example with IMAP bridge
    • Example with Google API
  • Testing Forms with Captcha
  • Command API
  • Test Application
Powered by GitBook
On this page

Was this helpful?

Testing Forms with Captcha

PreviousExample with Google APINextCommand API

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