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?
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.
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.
As for the environment, it can run on Windows, MacOS, and Linux. Supports desktop, mobile, remote and cloud browsers (UI or headless).
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.