A side-by-side comparison of Selenium, Cypress, and Playwright

This article relies on my opening keynote tackle for Front End Test Fest 2022.

In the featured picture for this text, you see a ravishing entrance finish. It’s most likely not the sort of “entrance finish” you anticipated. It’s the entrance finish of a 1974 Volkswagen Karmann Ghia. The Karmann Ghia was often called the “poor man’s Porsche.” It’s a really particular automobile. It was really a collaboration challenge between Wilhelm Karmann, a German vehicle producer, and Carrozzeria Ghia, an Italian vehicle designer. Ghia designed the physique as a murals, and Karmann put it on the tried-and-true platform of the traditional Volkswagen Beetle. When the Volkswagen executives noticed it, they couldn’t say no to mass manufacturing.

The Karmann Ghia is an ideal image of the state of internet improvement at present. We try to make lovely entrance ends with dependable platforms supporting them on the again finish. Collaboration from either side is essential to success, however what folks bear in mind most is the expertise they’ve together with your apps. My mother drove a Karmann Ghia like this when she was a young person, and to today she nonetheless talks in regards to the good occasions she had with it.

Good high quality, design, and expertise are indispensable elements of entrance ends – whether or not for traditional automobiles or for the Web. In this text, I’ll share seven main developments I see in entrance finish internet testing. While there’s a variety of cool new issues occurring, I need y’all to remember one foremost factor: instruments and applied sciences might change, however the fundamentals of testing stay the identical. Testing is interplay plus verification. Tests reveal the reality about our code and our options. We do testing as a part of improvement to collect quick suggestions for fixes and enhancements. All the developments I’ll share at present are rooted in these rules. With good testing, you can also make positive your apps will look visually excellent, identical to… you understand.

#1. End-to-end testing

Here’s our first pattern: End-to-end testing has develop into a three-way battle. For readability, after I say “end-to-end” testing, I imply black-box check automation that interacts with a reside internet app in an lively browser.

Historically, Selenium has been the preferred instrument for browser automation. The challenge has been round for over a decade, and the WebDriver protocol is a W3C customary. It is open supply, open requirements, and open governance. Selenium WebDriver has bindings for C#, Java, JavaScript, Ruby, PHP, and Python. The challenge additionally contains Selenium IDE, a record-and-playback instrument, and Selenium Grid, a scalable cluster for cross-browser testing. Selenium is alive and properly, having simply launched model 4.

Over the years, although, Selenium has obtained a variety of criticism. Selenium WebDriver is a low-level protocol. It doesn’t deal with ready routinely, main many of us to unknowingly write flaky scripts. It requires clunky setup since WebDriver executables should be individually put in. Many builders dislike Selenium as a result of coding with it requires a separate workflow or mind-set from the principle apps they’re creating.

Cypress was the reply to Selenium’s shortcomings. It aimed to be a contemporary framework with glorious developer expertise, and in a number of quick years, it shortly turned the darling check instrument for entrance finish builders. Cypress exams run within the browser side-by-side with the app below check. The syntax is tremendous concise. There’s automated ready, which means much less flakiness. There’s visible tracing. There’s API calls. It’s good. And it took an enormous chomp out of Selenium’s market share.

Cypress isn’t excellent, although. Its browser help is proscribed to Chromium-based browsers and Firefox. Cypress can be JavaScript-only, which excludes a number of communities. While Cypress is open supply, it doesn’t observe open requirements or open governance like Selenium. And, sadly, Cypress’ efficiency is gradual – equal exams run slower than Selenium.

Enter Playwright, the brand new open supply check framework from Microsoft. Playwright is the religious successor to Puppeteer. It boasts the extensive browser and language compatibility of Selenium with the refined developer expertise of Cypress. It even has a code generator to assist write exams. Plus, Playwright is quick – a number of occasions sooner than Selenium or Cypress.

Playwright remains to be a newcomer, and it doesn’t but have the footprint of the opposite instruments. Some people is perhaps cautious that it makes use of browser tasks as an alternative of inventory browsers. Nevertheless, it’s rising quick, and it might be a serious contender for the #1 title. In Applitools’ current Let The Code Speak code battles, Playwright handily beat out each Selenium and Cypress.

A side-by-side comparability of Selenium, Cypress, and Playwright

Selenium, Cypress, and Playwright are undoubtedly now the “large three” browser automation instruments for testing. A decent fourth point out could be WebdriverIO. WebdriverIO is a JavaScript-based instrument that may use WebDriver or debug protocols. It has a really massive consumer base, however it’s JavaScript-only, and it’s not as large as Cypress. There are different instruments, too. Puppeteer remains to be very talked-about however used extra for internet crawling than testing. Protractor, as soon as developed by the Angular staff, is now deprecated.

All these are good instruments to decide on (besides Protractor). They can deal with any sort of internet app that you simply’re constructing. If you need to be taught extra about them, Test Automation University has programs for every.

#2. Component testing

End-to-end testing isn’t the one sort of testing a staff can or ought to do. Component testing is on the rise as a result of elements are on the rise! Many groups now construct shareable element libraries to implement consistency of their internet design and to keep away from code duplication. Each element is sort of a “unit of consumer interface.” Not solely do they make improvement simpler, in addition they make testing simpler.

Component testing is distinct from unit testing. A unit check interacts straight with code. It calls a perform or methodology and verifies its outcomes. Since elements are inherently visible, they must be rendered within the browser for correct testing. They might need a number of behaviors, or they could even set off API calls. However, they are often examined in isolation of different elements, so individually, they don’t want full end-to-end exams. That’s why, from a entrance finish perspective, element testing is the brand new integration testing.

Storybook is a very talked-about instrument for constructing and testing elements in isolation. In Storybook, every element has a set of tales that denote how that element seems to be and behaves. While creating elements, you’ll be able to render them within the Storybook viewer. You can then manually check the element by interacting with them or altering their settings. Applitools additionally gives an SDK for routinely working visible exams towards a Storybook library.

The Storybook viewer
The Storybook viewer

Cypress can be coming into the element testing sport. On June 1, 2022, Cypress launched model 10, which included element testing help. This is a large step ahead. Before, people would want to cobble collectively their very own element check framework, often as an extension of a unit check challenge or an end-to-end check challenge. Many options simply ran automated element exams purely as Node.js processes with none browser element. Now, Cypress makes it pure to train element behaviors individually but visually.

I really like this quote from Cypress about their method to element testing:

When testing something for the net, we consider that exams ought to view and work together with the appliance in the identical approach that an precise consumer does. Anything much less, and it’s exhausting to trust that your software is doing what it’s presupposed to.

This quote hits on one thing large. So many automated exams fail to work together with apps like actual customers. They hinge on issues like IDs, CSS selectors, and XPaths. They make minimal checks like look of sure components or textual content. Pages might be fully damaged, however automated exams might nonetheless move.

#3. Visual testing

We actually need the perfect of each worlds: the simplicity and sensibility of guide testing with the pace and scalability of automated testing. Historically, this has been a painful tradeoff. Most groups battle to resolve what to automate, what to verify manually, and what to skip. I feel there may be great alternative in bridging the hole. Modern instruments ought to assist us automate human-like sensibilities into our exams, not merely hearth occasions on a web page.

That’s why visible testing has develop into indispensable for entrance finish testing. Web apps are visible encounters. Visuals are the DNA of consumer expertise. Functionality alone is inadequate. Users count on to be wowed. As app creators, we’d like to ensure these very important visuals are examined. Heaven forbid a button goes lacking or our CSS goes sideways. And since we reside in a world of steady improvement and supply, we’d like these visible checkpoints occurring constantly at scale. Real human eyes are simply too gradual.

For instance, I might have a login web page that has an authentic model (left) and a modified model (proper):

Visual comparison between versions of a login page
Visual comparability between variations of a login web page

Visual testing instruments warn you to significant adjustments and make it simple to match them side-by-side. They catch stuff you may miss. Plus, they run identical to every other automated check suite. Visual testing was powerful up to now as a result of instruments merely did pixel-to-pixel comparisons, which generated numerous noise for small adjustments and environmental variations. Now, with a instrument like Applitools Visual AI, visible comparisons precisely pinpoint the adjustments that matter.

Test automation must verify visuals nowadays. Traditional scripts work together with solely the essential bones of the web page. You might break the format and take away all styling like this, and there’s an excellent probability a standard automated check would nonetheless move:

The same login page from before, but without any CSS styling
The similar login web page from earlier than, however with none CSS styling

With visible testing strategies, you can even rethink the way you method cross-browser and cross-device testing. Instead of rerunning full exams towards each browser configuration you want, you’ll be able to run them as soon as after which merely re-render the visible snapshots they seize towards totally different browsers to confirm the visuals. You can do that even for browsers that the check framework doesn’t natively help! For instance, utilizing a platform like Applitools Ultrafast Test Cloud, you could possibly run Cypress exams towards Electron in CI after which carry out visible checks within the Cloud towards Safari and Internet Explorer, amongst different browsers. This model of cross-platform testing is quicker, extra dependable, and cheaper than conventional methods.

#4. Performance testing

Functionality isn’t the one side of high quality that issues. Performance could make or break consumer expertise. Most folks count on any given web page to load in a second or two. Back in 2016, Google found that half of all folks depart a web site if it takes longer than 3 seconds to load. As an business, we’ve put in a lot work to make the entrance finish sooner. Modern strategies like server-side rendering, hydration, and bloat discount all goal to enhance response occasions. It’s vital to check the efficiency of our pages to ensure the consumer expertise is tight.

Thankfully, efficiency testing is less complicated than ever earlier than. There’s no excuse for not testing efficiency when it’s so very important to success. There are many nice methods to get began.

The easiest method is correct in your browser. You can profile any web site with Chrome DevTools. Just proper click on the web page, choose “Inspect,” and swap to the Performance tab. Then begin the profiler and begin interacting with the web page. Chrome DevTools will seize full metrics as a visible time collection so you’ll be able to discover precisely what occurs as you work together with the web page. You may flip over to the Network tab to search for any API calls that take too lengthy. If you need to be taught extra about the sort of efficiency evaluation, Test Automation University provides a course entitled Tools and Techniques for Performance and Load Testing by Amber Race. Amber exhibits the way to get essentially the most worth out of that Performance tab.

Chrome DevTools Performance tab
Chrome DevTools Performance tab

Another nifty instrument that’s additionally accessible in Chrome DevTools is Google Lighthouse. Lighthouse is an internet site auditor. It scores how properly your web site performs for efficiency, accessibility, progressive internet apps, website positioning, and extra. It can even present suggestions for the way to enhance your scores proper inside its studies. You can run Lighthouse from the command line or as a Node module as an alternative of from Chrome DevTools as properly.

Google Lighthouse from Chrome DevTools
Google Lighthouse from Chrome DevTools

Using Chrome DevTools manually for one-off checks or exploratory testing is useful, however common testing wants automation. One actually cool technique to automate efficiency checks is utilizing Playwright, the end-to-end check framework I discussed earlier. In Playwright, you’ll be able to create a Chrome DevTools Protocol session and collect all of the metrics you need. You can do different cool issues with profiling and interception. It’s like a backdoor into the browser. Best of all, you could possibly collect these metrics along with useful testing! One framework can meet the wants of each useful and efficiency check automation.

John Hill is a trailblazer on this area. He’s presently doing this as a part of the Open MCT challenge. He’s the one who confirmed me the way to automate efficiency exams with Playwright! If you need to be taught extra, try this discuss he gave not too long ago on efficiency testing with Playwright, in addition to his js-perf-toolkit challenge on GitHub.

Below is an instance snippet I copied from js-perf-toolkit exhibiting the way to collect efficiency metrics utilizing Playwright:

const consumer = await web page.context().newCDPSession(web page);
await consumer.ship('Performance.allow'); 

await web page.goto('
await web page.click on('[aria-label="Search"]');
await web page.fill('[aria-label="Search"]', 'playwright');

await Promise.all([
    page.press('[aria-label="Search"]', 'Enter')

let perfMetrics = await consumer.ship('Performance.getMetrics');
console.log( perfMetrics.metrics );

#5. Machine studying fashions

There’s one other curve ball when testing web sites: what about machine studying fashions? For instance, everytime you store at a web based retailer, the underside of just about each product web page has an inventory of suggestions for related or complementary merchandise. For instance, after I searched Amazon for the newest Pokémon online game, Amazon really helpful different video games and toys:

Recommendation programs like this is perhaps hard-coded for small shops, however massive retailers like Amazon and Walmart use machine studying fashions to again up their suggestions. Models like this are notoriously troublesome to check. How do we all know if a suggestion is “good” or “unhealthy”? How do I do know if people who like Pokémon could be enticed to purchase a Kirby sport or a Zelda sport? Lousy suggestions are a misplaced enterprise alternative. Other fashions might have extra severe penalties, like introducing dangerous biases that have an effect on customers.

Machine studying fashions want separate approaches to testing. It is perhaps tempting to skip knowledge validation as a result of it’s tougher than fundamental useful testing, however that’s a threat not price taking. To do testing proper, separate the useful correctness of the frontend from the validity of information given to it. For instance, we might present mocked knowledge for product suggestions in order that exams would have constant outcomes for verifying visuals. Then, we might check the advice system aside from the UI to ensure its solutions appear right. Separating these testing considerations makes every sort of check extra useful in determining bugs. It additionally makes machine studying fashions sooner to check, since testers or scripts don’t must navigate a UI simply to train them.

If you need to be taught extra about testing machine studying programs, Carlos Kidman created a wonderful course all about it on Test Automation University named Intro to Testing Machine Learning Models. In his course, Carlos exhibits the way to check fashions for adversarial assaults, behavioral elements, and unfair biases.

#6. JavaScript

Now, the subsequent pattern I see will most likely be controversial to a lot of you on the market: JavaScript isn’t all the pieces. Historically, JavaScript has been the solely language for entrance finish internet improvement. As a outcome, a JavaScript monoculture has developed across the entrance finish ecosystem. There’s nothing inherently unsuitable with that, however I see that altering within the coming years – and I don’t imply TypeScript.

In current years, frustrations with single-page functions (SPAs) and client-heavy entrance ends have spurred a server-side renaissance. In addition to JavaScript frameworks that help SSR, traditional server-side tasks like Django, Rails, and Laravel are alive and kicking. Folks in these communities do JavaScript once they should, however they love exploring alternate options. For instance, HTMX is a framework that gives hypertext directives for a lot of dynamic actions that might in any other case be coded straight in JavaScript. I might use any of these traditional internet frameworks with HTMX and virtually fully keep away from JavaScript code. That makes it simpler for programmers to make cool issues occur on the entrance finish while not having to navigate a overseas ecosystem.

Below is an instance snippet of HTML code with HTMX attributes for posting a click on and exhibiting the response:

  <script src="
  <!-- have a button POST a click on by way of AJAX -->
  <button hx-post="/clicked" hx-swap="outerHTML">
    Click Me

WebAssembly, or “Wasm” can be right here. WebAssembly is basically an meeting language for browsers. Code written in higher-level languages will be compiled down into WebAssembly code and run on the browser. All main browsers now help WebAssembly to some extent. That means JavaScript now not holds a monopoly on the browser.

I don’t know if any language will ever dethrone JavaScript within the browser, however I predict that browsers will develop into multilingual platforms by WebAssembly within the coming years. For instance, at PyCon 2022, Anaconda introduced PyScript, a framework for working Python code within the browser. Blazor permits C# code to run in-browser. Emscripten compiles C/C++ applications to WebAssembly. Other languages like Ruby and Rust even have WebAssembly help.

Regardless of what occurs inside the browser, black-box testing instruments and frameworks exterior the browser can use any language. Tools like Playwright and Selenium help languages aside from JavaScript. That brings many extra folks to the desk. Testers shouldn’t be compelled to be taught JavaScript simply to automate some exams once they already know one other language. This is occurring at present, and I don’t count on it to alter.

#7. Autonomous testing

Finally, there may be yet one more pattern I need to share, and this one is extra in regards to the future than the current: autonomous testing is coming. Ironically, at present’s automated testing remains to be manually-intensive. Someone wants to determine options, write down the check steps, develop the scripts, and preserve them once they inevitably break. Visual testing makes verification autonomous as a result of assertions don’t want specific code, however determining the precise interactions to train options remains to be a tough drawback.

I feel the subsequent large development for testing and automation will likely be autonomous testing: instruments that autonomously have a look at an app, determine what exams ought to be run, after which run these exams routinely. The key to creating this work will likely be machine studying algorithms that may be taught the context of the apps they aim for testing. Human testers might want to work along with these instruments to make them really efficient. For instance, one sort of instrument might be a check suggestion engine that proposes exams for an app, and the human tester might decide those to run.

Autonomous testing will tremendously simplify testing. It will make builders and testers way more productive. As an business, we aren’t there but, nevertheless it’s coming, and I feel it’s coming quickly. I delivered a keynote tackle on this subject at Future of Testing: Frameworks 2022:


There’s numerous thrilling stuff occurring on this planet of the entrance finish. As I stated earlier than, instruments and applied sciences might change, however fundamentals stay the identical. Each of those developments is rooted in tried-and-true rules of testing. They remind us that software program high quality is a multifaceted problem, and the perfect technique is the one that gives essentially the most worth in your challenge.

So, what do you suppose? Did I hit all the foremost entrance finish developments? Did I miss something? Let me know within the feedback!

Source link