DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Frame Buffer Hashing for Visual Regression on Embedded Devices
  • How to Interpret the Number of Spring ApplicationContexts in Integration Tests
  • Why Your Test Automation Is Always Behind the Code And the Architecture That Fixes It
  • Good Data, Bad Metric: A Mutation Testing Pattern for Analytics Engineering

Trending

  • Spring Boot Done Right: Lessons From a 400-Module Codebase
  • Comparing Top Gen AI Frameworks for Java in 2026
  • Bringing Intelligence Closer to the Source: Why Real-Time Processing is the Heart of Edge AI
  • Integrating AI-Driven Decision-Making in Agile Frameworks: A Deep Dive into Real-World Applications and Challenges
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. TestCafe: An e2e Testing Tool That Doesn’t Use Selenium

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.

By 
Alexander Moskovkin user avatar
Alexander Moskovkin
·
Sep. 29, 17 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
18.7K Views

Join the DZone community and get the full member experience.

Join For Free

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.

Conclusion

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.

Testing

Opinions expressed by DZone contributors are their own.

Related

  • Frame Buffer Hashing for Visual Regression on Embedded Devices
  • How to Interpret the Number of Spring ApplicationContexts in Integration Tests
  • Why Your Test Automation Is Always Behind the Code And the Architecture That Fixes It
  • Good Data, Bad Metric: A Mutation Testing Pattern for Analytics Engineering

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook