TestCafe: An e2e Testing Tool That Doesn’t Use Selenium

DZone 's Guide to

TestCafe: An e2e Testing Tool That Doesn’t Use Selenium

See how easy it is to run e2e testing written in JavaScript with TestCafe, an open source Node.js tool, and no need for Selenium.

· DevOps Zone ·
Free Resource

Selenium WebDriver is one of the most well-known tools for e2e testing. And for a reason: a huge community, lots of frameworks, and supported languages. All these let one use Selenium in almost any project.

But there is a limitation: it takes a decent amount of time to set it up on a new project. Plus, you rarely use a “pure” Selenium. In most cases, a bunch of plugins and frameworks are required, so sometimes it’s too expensive timewise. This becomes even more noticeable when you need to scale the testing environment.

But what if you don’t want to invest a lot of time into the setup of an e2e testing environment?

Alternative Way

Many popular e2e testing solutions are Selenium-based, for lots of reasons. They extend its basic capabilities but also inherit the need to spend time on WebDriver setup.

We took a different path: we created TestCafe, a tool that does not use Selenium at all. We had to implement all functionality from scratch. But at the same time, it has untied our hands. Now TestCafe takes about a minute to set up and start testing.

How It Works

TestCafe uses a URL-rewriting proxy instead of WebDriver. This proxy injects the driver script that emulates user actions into the tested page. This way TestCafe can do everything required for the testing: it can emulate user actions, authentication, run its own scripts & etc. And for the tested page, it looks like there's a real user interacting with it. It doesn't experience any direct scripts interference. Here's a brief scheme of what the proxy does.

How URL-rewriting proxy works

Given that, you don’t need to install any additional tools. Run this command and you are ready to go:

npm install -g testcafe

Now you can write your first test and run it. Go to the Getting Started part of the documentation to see how.

Installing TestCafe and running a test

Main Features

TestCafe itself is an open source Node.js tool operated via command line or JavaScript API. Сomplete functionality for e2e testing is provided out of the box. 

As for the environment, it can run on Windows, MacOS, and Linux. Supports desktop, mobile, remote and cloud browsers (UI or headless).

Tests are written in JavaScript, supporting latest features including ES2017 (for example, async/await). And since v0.16.0 TestCafe supports TypeScript, for those who prefer a strongly typed language.

Then there are also various plugins for some extra spark. They provide framework-specific selectors, alternative reporters and etc. They're installed with a single command and don't require any further setup. For example, to add React selectors do this:

npm install -g testcafe-react-selectors

What Else Is There?

TestCafe also has some features that would be hard (or impossible) to implement on top of Selenium.

One of these features is an isolated test environment. Tests start with clean storage and cookies, and can use the User Roles mechanism. This allows you to run tests under different user accounts and isolate user authentication from the tests. Thus you can avoid a lot of boilerplate code and work in the same browser without the risk of state interference.

Another feature is an automatic waiting mechanism. It waits until the page and its elements are loaded and runs the test immediately after. This makes the tests less flaky and more reliable without any extra coding.

You can also run tests on remote devices, which don’t have an instance of TestCafe installed. It can be useful when you need to demonstrate a bug to a colleague or quickly run a test on a mobile device.


Sure, it would be much easier to use Selenium under the hood. But we decided to build a new tool without any legacy. If you’ve been looking for WebDriver alternatives, give TestCafe a try. And tweet us with #TestCafe tag, we’d love to hear what you think of it.

Follow us on Twitter or Facebook for product news and web dev related stuff. We post several times a week. And feel free to ask questions on our forum.

automated testing, devops, javascript, node.js, testing, typescript, web dev

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}