What should you use instead of Protractor for test automation of Angular sites?
If you are using Protractor for test automation of Angular sites, I have bad and good news for you.
First, the bad news.
Protractor will be retired at the end of 2022 as it became incompatible with the latest version of the Selenium WebDriver framework.
Protractor is built on top of the Selenium WebDriver bindings for Node.JS and unfortunately the latest version of these bindings introduced changes that are difficult to use in Protractor.
Read the announcement here.
If you have lots of UI tests built with Protractor, this is obviously not good news.
Which one should you use?
The good news is that there are quite a few libraries that you can use.
The “retirement” announcement presents a few options for Protractor:
Let’s discuss the options one by one.
I do not know what TestCafe is so will ignore it for now.
Puppeteer is not a good option because the team that built it left Google for Microsoft so they work on a different library named Playwright. The Puppeteer project can be probably considered as done.
This lefts us with 3 options:
Playwright is the new Puppeteer. It is a pretty good library which does not depend on Selenium WebDriver. It basically implements the same functionality in a different way.
It does a lot of good things for UI automation:
- works in all browsers compared to Puppeteer which worked only in Chrome
- uses auto waits to make tests more reliable
- intercepts network activity
- can run multi-page emulation scenarios
With so many good things, maybe this is the winner?
Playwright is still very new and with lots of bugs that need to be fixed. If there is something that I personally want in my projects, this is a stable UI automation library which Playwright is not yet.
What’s next? Yes, Cypress.
Cypress, like Playwright, has a new architecture that is completely independent from Selenium WebDriver.
It has lots of great features such as:
- tests get executed automatically while you write them
- uses automatic waits for making tests more stable
- takes screenshots while the tests run
- takes videos automatically
- it is developer friendly
- great API
One downside is that Cypress is also very new.
Another downside is related to maintaining your existing code. If you structured your project to use page object classes, this may prevent you from writing the best Cypress tests. Why not? Because page objects are considered an anti-pattern by the Cypress team. Instead of using page objects, they suggest using methods of the Cypress API directly in the tests. The tests will be longer, more difficult to read and maintain.
Migrating the existing Protractor solution to Cypress will probably be the same with rewriting it from scratch.
This leaves us with WebDriver.IO.
WebDriver.IO is a mobile and browser test automation framework for Node.js.
It can run either on the Selenium WebDriver protocol or on the Chrome DevTools protocol.
It is extendable and very rich in features.
It supports page objects.
It is supported and developed by Sauce Labs, one of the biggest cloud grids for test automation.
It is also around for about 5 years which means great stability.
What should you use then?
I think that WebDriver.IO is probably the best solution at this moment especially when considering the migration of the existing code that depends on Protractor.
Cypress is probably as good as WebDriver.IO but the migration process will be much more difficult.
Playwright is not mature yet.