Back to insights

End-to-end testing an application with integrated captcha

Last updated on October 28, 2024

End-to-end testing an application with integrated captcha

In this article, we explain how you can test your application with E2E tests, even if it is protected by a captcha.

What are E2E tests?

End-to-end tests are a test method in which the system is tested as a whole from the customer's perspective. This helps developers to find errors from the user's perspective at an early stage. For this reason, E2E tests are very often carried out in the various test phases before a release. Popular tools for this type of testing currently include Playwright, Selenium and Cypress.

What are the problems with E2E tests and captchas?

Due to ever shorter release cycles, it is important to minimise the manual testing effort for E2E tests. The majority of tests should therefore be automated. These take control of a selected browser and test the application from the customer's perspective.

And here we come to a common problem with captchas. These are there to protect your application from bots that act in a similar way to your E2E tools. Therefore, you often have no choice but to remove the captcha during the test stage. However, there is always a risk that problems will occur during live integration, as the interaction between the form and captcha, for example, could not be tested.

What solution does CaptchaFox provide?

In order to successfully test your application with the integrated captcha, CaptchaFox offers you a test key for this case, which you can find in our documentation. This test key can only be used in combination with a specific secret key on your backend.

To be able to use this as effectively as possible, it is advisable to work with different environments. In our example below, we show you how you can do this in an Angular application.

Example using Angular

To create different environments, you can use Angular's CLI and execute the following command to create application environments. In Angular, application environments are configurations that allow you to define different settings (such as API URLs or debug flags) for different environments (e.g. development, production). They are typically saved in separate files and selected during the build process depending on the target environment.

Terminal
ng generate environments

You should now find the following folder structure in your project:

Project
project
└───app
│   │   app.component.html
│   │   app.component.ts
└───environment
    │   environment.ts
    │   environment.development.ts
    │   environment.staging.ts

In the newly generated environment.ts, you can now add all the environment variables that you need for your live environment, such as the site key for CaptchaFox that you generated in the portal.

environment.ts
export const environment = {
  production: true,
  apiUrl: 'your-website.url'
  captchaFox: 'your-sitekey'
};

Next, you can define the environment variables for your test stage. To do this, open the environment.staging.ts file and add the environment variables here too. Make sure that you use the variables that you need for the tests. In our example, it looks like this:

environment.staging.ts
export const environment = {
  production: false,
  apiUrl: 'your-website.url'
  captchaFox: 'sk_11111111000000001111111100000000'
};

You can also use the test key used here for your tests. You can also find it in our documentation. By using this sitekey, the captcha for the end-to-end test will always return a successful response.

To build your application in the test environment, simply execute the following command:

Terminal
ng build --configuration=staging

With the received Sitekey, you can now test your application in different development environments by including the captcha in your preferred environment and checking the functionality accordingly. This allows you to validate the behaviour of the application in both the development and production environments.

If you want to dive deeper into the integration, you can read the official documentation.

About CaptchaFox

CaptchaFox is a GDPR-compliant solution based in Germany that protects websites and applications from automated abuse, such as bots and spam. Its distinctive, multi-layered approach utilises risk signals and cryptographic challenges to facilitate a robust verification process. CaptchaFox enables customers to be onboarded in a matter of minutes, requires no ongoing management and provides enterprises with long-lasting protection.

To learn more about CaptchaFox, talk to us or start integrating our solution with a free trial.

Fight bots and protect your users' data.

Don't give fraudsters and spammers a chance and protect your website with CaptchaFox today.

Device protection