Which one is the best test automation tool?
Tags: testing, testingtools, automation, testautomation
Published: 2021-11-01 18:20:50

This post was inspired by a slightly naughty response (by the context) I received in a discussion on LinkedIn, when I said that Cypress alone is not by far the best tool for API testing:

> There is no better tool, but the one that meets the Project's needs." (free translation)

Yes, there is a better tool to solve your problem. And there's a better one to solve mine!

Below, I will mention 3 tools that we decided to be the best for each case, and briefly explain how the decision process was.

## Puppeteer

**Problem**: We were building a backend tool, but it needed a browser to authenticate. Yes, there was no API for this and even CLI authentication needed to login via browser to get the credentials, which were displayed on terminal.

We were building a web application, and we needed to build a custom `window.fetch` object to pass as a parameter for a third-party library that we needed to use.

One week later, we still couldn't log in without using the browser. So we decided to test it from the browser anyway.

**Tools**: The pre-conditions was to be JavaScript tool, so Cypress, Playwright, Puppeteer and Selenium were options.

Selenium was the first to be discarded due to the need for a webdriver, unnecessary complexity and risk of incompatibilities just to log in and click a few buttons. Also, we will need to intercept requests, and Selenium does not do it natively.

Cypress and Playwright are very complete solutions for the case. Both would fit perfect, especially Cypress, as I have a certain experience on it, but could be an overkill. So, Puppeteer left.

I've never used Puppeteer before, but it's the "rawest" and lightest solution, also allows a greater flexibility. We can run it purely with Node or integrate it with any test runner we want. We chose Jest for the reason that will be explained later.

**Best tool**: Puppeteer

## Cypress

**Problem**: QAs being the only ones responsible for test automation, because Selenium with Ruby and HTTParty was used  for web/API automations, in a separate repository, but both front and backend developed in JavaScript.

We wanted more Devs-QAs integration.

**Tools**: Any JavaScript-based, like Cypress, Playwright, Nightwatch, WebdriverIO...

Cypress was chosen as the company's new stack due to its popularity growth, which allows a greater exchange of knowledge and more easy to find answers, easy installation/configuration (one command and everything is ready to go), and for being extremely friendly to all seniority. Also, an increasing number of QAs are using Cypress, which would make it easier to hire.

In addition, Cypress is an "all-in-one" tool: unit, API, component, E2E and many more built-in or via plugins functionalities.

Test code together with development code, get help from (some) devs, ease of CI, ease of mocks. As Chrome browser had more than 80% of customers usage, Cypress responded perfectly.

**Best tool**: Cypress.

## Jest
**Problem**: even though Cypress was being used for front automation, we needed a tool just to do some GETs and check the response against JSON Schemas. We were building a static website and these requests were to get the content from the headless CMS.

Cypress would be a heavy tool for the above work, as we wanted to run the contract tests as the first tests in the pipeline.

**Tools**: Cypress, Mocha, Axios, Supertest, Chai.http, Jest.

Yes, there are plenty of other JavaScript tools to test API, but we've decided to limit the options a bit.

I really wanted to use Supertest or Chai.http in conjunction (or not) with Mocha, as this is an extremely lightweight combination.

The front was already using Axios to make requests to the CMS so a tool was already decided. Left to decide between Mocha and Jest.

React had already been decided as the stack for the frontend development, so nothing better than using Jest. Also, another Dev was already using Jest (justifying the choice said in Puppeteer section). In order not to have each project with a different tool, let's go with Jest!

And to confirm the choice, the Cypress initialization alone took longer than all the Jest contract tests...

**Best tool**: Jest (+ Axios and AJV)

With these three cases, we see that there is always ONE better tool to solve your problem, even if it is not THE best tool.

How do you choose your best test automation tool? Comment here!