Test Automation Tools: TestCafe

I recently wrote a blog post on Cypress.io as a non-Selenium-based automation tool using the JavaScript test framework running on and in the browser. Today, I will review another awesome non-Selenium JavaScript E2E (End-to-End) testing framework which is now one of my favourite testing frameworks to work with.

What is TestCafe

TestCafe is a pure node.js tool for automating end-to-end web testing. With TestCafe, you can write tests in JavaScript and TypeScript, which is pretty logical considering that a tool used for web testing should make it possible tor write tests using one of the core technologies of the web (JavaScript).  

TestCafe is a free and open-source tool. TestCafe doesn’t require browser plugins and it uses a URL rewriting proxy called Hammerhead that emulates commands using the DOM API and injects JavaScript into the browser. This proxy rewrites all properties of the appropriate JavaScript objects that contain a URL value to simulate user action in the application under test. This allows it to support multiple browsers without any browser drivers.

 

What makes TestCafe special

So that makes TestCafe so special? There are plenty of Selenium alternatives out there, Cypress.io being one of them. Here are eight reasons as to why TestCafe might also become your new favourite test framework. 

 

TestCafe is easy to install

Sure installing applications is never really that difficult, especially with the proper documentation to guide you. TestCafe says it takes “1 minute to set up.”

Installing TestCafe is easy

  • First, make sure you have Node.js version 4.x or higher installed.
  • Run: npm init inside the new directory.
  • After this, we need to add TestCafe library in the project
npm install -g testcafe

And that’s all, now you can start testing. Sound easy right? Yes, it is.

 

No need for any external plugins

TestCafe does not require any external plugins to run tests on different browsers (it can automatically detect any popular browsers installed on the local computer which makes it easier for the testers to eliminate the effort of setting up plugins.

 

TestCafe allows cross-browser testing

TestCafe is designed to support most modern browsers, you can find the officially supported browsers here. At the time of writing, these officially supported browsers are:

  • Google Chrome: Stable, Beta, Dev and Canary
  • Internet Explorer (11+)
  • Microsoft Edge
  • Mozilla Firefox
  • Safari
  • Google Chrome mobile
  • Safari mobile

 

Parallel Testing

TestCafe can run your tests on the same browser instance multiple times concurrently or on several browser instances at once. This can also be done on remote browsers, more about that later. This practice can significantly decrease your testing time, another reason to love TestCafe.

 

Built-in waiting mechanisms

When dealing with waiting, using Selenium can be a nightmare for the automation testers. Testers must then always try to achieve better sync by using a mechanism provided by the Automation API, but as evident from experience this approach is not the best solution.

To overcome this problem TestCafe has built-in automatic waiting mechanisms so that it does not need a dedicated API to wait for page elements to appear or redirects to happen. So now you can perform the required assertions immediately after the test action is executed in synchronous functional testing. This is a built-in mechanism that lot of testers have been…. waiting…. for.

See what I did there?

Example:

import { Selector } from 'testcafe';

fixture `My fixture`

   .page `https://devexpress.github.io/testcafe/example`;

const nameInput = Selector(‘#developer-name’);

const submitButton = Selector(‘#submit-button’);

test(‘My test’, async t => {

   await t

       .typeText(nameInput, ‘Peter Parker’) // Waits for `#developer-name`

       .click(submitButton); // Waits for ‘#submit-button’

});

Source

 

Write tests with your favourite selectors

Along with a set of general-purpose selectors based on CSS selectors or client JS code, TestCafe provides you with multiple plugs selectors for popular front-end frameworks.

 

Test on remote computers and mobile devices

You can run TestCafe on remote browser on any machine:

testcafe remote tests/test.js
 

Then you will get a URL, open this URL on your remote machine and that will be displayed TestCafe remote test.js

You can also run the test on any mobile device in the local network by using:

testcafe remote tests/test.js --qr-code

TestCafe will output the QR-code to the console. Scan the QR-code with a mobile device that has network access to the TestCafe machine and open the link. TestCafe will start tests in the mobile browser.

Pretty awesome, right? Check this video will explain more about that.

But that’s not all, they also support testing in cloud-based services (BrowserStack, Saucelabs, etc.) by using TestCafe browser provider. Also even if the mobile device and the cloud service are not available to you, no problem, you can run tests in mobile emulators.
testcafe "chrome:emulation:device=iphone X" tests/sample-fixture.js

 

TestCafe reports

TestCafe allows you to generate various kinds of reports to output the running test using its built-in reporter. You can also create a custom reporter that will output information in your own format and style. For this purpose, you can use the TestCafe reporter generator. The generator will scaffold out a reporter plugin so that you only need to write a few lines of code. The reports listed below can be created:
  • spec (used by default)
  • list
  • minimal
  • XUnit
  • JSON

Conclusion 

Setting up End-to-End testing is no longer an extremely difficult challenge. TestCafe makes it simple and enjoyable. It’s easy to use, and it’s easy to learn. The community grows bigger and TestCafe already has a wide range of plugins that extend its functionality. All of this points to the fact that if you are a manual tester, try starting with TestCafe and you will quickly progress to becoming a junior technical tester. This is my experience and a little glimpse of what can be achieved with TestCafe. TestCafe is already quite a mature tool for web testing. While there is enough here to make a good argument for choosing TestCafe over other option, I have, in fact, I have only begun to scratch the surface of its functionality. Give it a go and stay tuned for more of our Test Automation Tool reviews. 

Calliope.pro

While on the topic of test automation tools, our DevOps tool for test results monitoring is the perfect compliment for your TA practices. Its tool and framework agnostic meaning that it supports most major test frameworks. Calliope is created by testers, for testers so you can help your test results tell as story and shorten feedback cycles.
A glimpse at the calliope reporting tool
Calliope.pro is the one location for your development team to share, compare, and monitor test results to quickly and clearly understand the health of the code and identify regressions. Give Calliope.pro a try, for free, today and discover the power of collaboration.

Tags

top