Even simple web applications will benefit from integration testing. But as your app grows in complexity, testing becomes essential to ensure your users have a great experience.
Whether you want to develop e2e tests for deployment, production tests for monitoring, visual regression tests, or more, this article will help you get started in no time. Using Playwright and BrowserCat, not only will your tests run reliably, but they’ll run quickly and cheaply as well.
Set up you test environment
Let’s kick things off by setting up a new project. If you already have an existing project where you want to include tests, skip this first step and jump to the next.
Next, we will install the necessary dependencies, including the @playwright/testlibrary. It’s bar none the best automated testing library around, and it supports multiple languages as well.
That’s it. Now let’s write some tests!
Create your first test
Depending on the testing strategy you want to deploy, you may want to organize your test files differently. But for now, let’s keep things simple. A tests directory will do just fine.
Open tests/pricing.spec.ts in your text editor. Let’s do a quick sanity check to make sure everything is working as expected…
Let’s run our test and see what happens…
If you see 1 passed, great! Otherwise take a deeper look at the previous instructions and make sure you didn’t miss anything.
Now let’s test something a bit more complicated…
Testing behavior and feedback
We’ll start by testing BrowserCat’s dynamic pricing slider behaves as expected. This example will demonstrate different ways of interacting with the browser and the DOM.
Let’s run our test again. You should again expect a passing result. If not, take a look at the code and see if you can figure out what’s going on. Here’s some resources:
Still having trouble? Contact us. We’re happy to help!
Running your tests
Now that you’ve got a working test, you’re ready to start making use of it. The challenge is that running a test in your CI/CD pipeline or from a production server requires downloading and hosting a headless browser. Now only is this a pain to set up, but it’s also incredibly slow.
Most CI/CD containers and web servers are very light, and it’s challenging to parallelize your tests so that they run in a reasonable timeframe. Some users’ deployment tests used to take over an hour (!!!) to run.
This is where BrowserCat comes in. Rather than hosting the browsers yourself, you can connect to BrowserCat’s fleet on demand. This allows you to fully parallelize your tests, only paying for the browsers when you’re actually using them.