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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

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.

Alexander Moskovkin user avatar by
Alexander Moskovkin
·
Sep. 29, 17 · Tutorial
Like (3)
Save
Tweet
Share
17.60K 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.

Popular on DZone

  • Choosing the Best Cloud Provider for Hosting DevOps Tools
  • Using JSON Web Encryption (JWE)
  • Unleashing the Power of JavaScript Modules: A Beginner’s Guide
  • Unlocking the Power of Polymorphism in JavaScript: A Deep Dive

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: