Cypress vs Selenium WebDriver Comparison by Example
Tags: selenium, cypress, javascript, automation
Published: 2022-09-16 21:17:08

_This article is one of the “Bad Test Automation Frameworks/Tools” series._

I started this article 10 months ago, it was sitting in my drafts and just noticed it today. After my three articles on Cypress,

* [Why Cypress Sucks for Real Test Automation?](https://zhiminzhan.medium.com/why-cypress-sucks-for-real-test-automation-f79525ea5844) and [Part 2: Limitations](https://zhiminzhan.medium.com/why-cypress-sucks-for-real-test-automation-part-2-limitations-53c1914acd0d)
* [Why JavaScript Is Not a Suitable Language for Real Web Test Automation?”](https://zhiminzhan.medium.com/why-javascript-is-not-a-suitable-language-for-real-web-test-automation-3a87eb4b0b50)

I thought there is no need to talk about Cypress, which, IMO, is doomed to fail (for reasons, read the above). So far, every Cypress test automation (that I am aware of) failed badly, often embarrassingly. I noticed a trend though, after failures, [fake automated testers](https://zhiminzhan.medium.com/fake-end-to-end-test-automation-clarified-1269ca704a0) blamed Cypress and then switched to another JS framework Playwright, just like earlier some of them switched to Cypress from the hyped (_and now deprecated_) [Protractor](https://zhiminzhan.medium.com/protractor-another-automation-framework-i-rightly-avoided-is-being-deprecated-aaf702241f43). Playwright is not good either, maybe slightly better than Cypress, then failed again. The best is still raw Selenium WebDriver in Ruby.

> _The article [An IT Graduate’s frustration with a Fake ‘Senior Test Automation Engineer’](https://zhiminzhan.medium.com/an-it-graduates-frustration-with-a-fake-senior-test-automation-engineer-8b0075954394) tells an interesting and real story of an intern (my mentee, freshly out of Uni) who silenced one fake senior test automation engineer with indisputable results, implemented automated UI tests in both Selenium and Playwright at the productivity this large company have never seen. (Reason: this intern developed tests in raw Selenium WebDriver first, then converted to Playwright). Eventually, this fake senior Playwright tester did dirty tricks to sabotage. A good read._

Today, I saw a LinkedIn feed to recommend using Cypress for test automation, and it was posted in a Selenium Group. So I decide to complete and publish this article.

Anyway, the aim of this article is about an objective comparison of Cypress and Selenium syntax, using a very simple example, from a tester’s perspective. To be fair, I used the Cypress test script example posted by Gleb Bahmutov (known as the authority on Cypress). So, the comparison is as objective as it can be.

> #### “Test Scripts are the core of test automation, naturally. Ignore others who tell you otherwise” — Zhimin Zhan

## Cypress vs Selenium WebDriver (Ruby)

I will use [a simple example by Gleb Bahmutov](https://glebbahmutov.com/blog/avoid-cypress-pyramid-of-doom/) (“Avoid Cypress Pyramid of Doom” posted on 2021–07–28): a simple calculator on a web page.

![](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8tq9tb3zq1chg4eb704a.png)


The HTML (_from Gleb’s post_):

```html
<body>
  <p>Calculator</p>
  <div>a = <input name="a" type="number" value="1" /></div>
  <div>b = <input name="b" type="number" value="5" /></div>
  <div>a + b = <span id="result">6</span></div>
</body>
```
Here is Gleb’s ‘**good version**’ (there were a couple of not-so-good versions shown) Cypress test script.

```javascript
it('adds numbers via aliases', () => {
  cy.visit('public/index.html')
  cy.get('[name=a]').invoke('val').then(parseInt).as('a')
  cy.get('[name=b]').invoke('val').then(parseInt).as('b')
  cy.get('#result')
    .invoke('text')
    .then(parseInt)
    .as('result')
    .then(function () {
      expect(this.a + this.b).to.eq(this.result)
    })
})
```

My version in raw Selenium (RSpec):

```ruby
it "adds numbers" do
  driver.get("public/index.html")
  a = driver.find_element(:name, "a")["value"].to_i 
  b = driver.find_element(:name, "b")["value"].to_i
  result = driver.find_element(:id, "result").text.to_i
  expect(a + b).to eq(result)
end
```

It is a lot better, isn’t it? Please take a stand from an independent testing perspective.

> #### “Users do not care how the website was coded in Java, JS, C#, PHP or Ruby. The same applies when end-to-end testing a website from a user perspective” — Zhimin Zhan

## Comparative Analysis

Let’s see some differences. If you are using Cypress or other JS framework, pause, and think objectively as a team member (e.g. Business Analyst or Manual Tester) who might want to use your automated tests:

### Get the value of an input text field

Cypress: `invoke('val')`
Selenium: `["value"]`
**Verdict**: Selenium WebDriver is more natural, as it gets the value attribute in HTML tag: `<input name="a" type="number" value="1"/>` . The invoke and 'val' in Cypress make the simple things complex. The keyword invoke, in particular, is bad. Where is 'val' in the HTML fragment? (_I know as I programmed JS professionally before, again, consider for others who don’t know JS at all_)

### Convert string to an integer

Cypress (JavaScript): `parseInt`
Selenium (Ruby): `to_i`
**Verdict**: the Ruby syntax is better as it is concise and more readable.

### Promise 
_(unneeded in software testing, if thinking outside JS)_

Cypress: `then`
Selenium: no such concept. (Please note, achieving the same testing result).
**Verdict**: Selenium is better. JavaScript’s Promise is confusing and totally unnecessary from the testing perspective.

### Alias 
_(unneeded as well)_

Cypress: `as('a')`, also, later `this.a`
Selenium: no such concept, just naturally assign a variable, `a =` .
**Verdict**: Selenium is a lot better, the alias usage in Cypress is totally unnecessary from the testing perspective.

The winner, clearly, is raw Selenium with Ruby.


![Agile Testing book recommends Ruby](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gyra19r524fgentt53fq.png)

“**Ruby is the best for scripting automated tests**” is not news or secret, why on earth do people fail test automation again and again in Java/C#/JavaScript?

## Human Factors

Besides tech comparison, Selenium WebDriver’s version is more concise and consistent, which are important for maintenance. [The effort for test script maintenance far exceeds that of test creation](https://medium.com/geekculture/is-your-test-automation-on-track-maintenance-is-the-key-267ddb94b525). That’s why most JS test automation attempts started OK (_and excitedly_), then failed badly (_and quietly_): unable to maintain the tests.

There are other factors too, such as Gleb’s article showing several different (worse) versions, which may cause problems in a team environment. With Selenium WebDriver, if the team stays with the raw Selenium, it is quite easy for the team to reach a convention.

> Selenium WebDriver, syntax-wise, is much better than all others for a simple reason: it was created by W3C experts after many rounds of reviews and refinement. — Zhimin Zhan

More importantly, real test automation engineers know that the audience of automated test scripts is the whole team, not limited to programmers. Even the simple syntax that JS programmers take for granted, such as `() => { `, `this.a`, and `})` may confuse the business analysts and manual testers.

## FAQ

I think some Cypress/Playwright/JS testers disagree with my recommendation of raw Selenium WebDriver with Ruby. Before raising your questions, watch the below 37-second video, which is extracted from this great presentation: “[Continuous Integration at Facebook](https://zhiminzhan.medium.com/recommend-a-great-ci-presentation-continuous-integration-at-facebook-6369323da084)”.

Video on YouTube: [https://youtu.be/D5Zk5ylPrGk](https://youtu.be/D5Zk5ylPrGk)

![Facebook’s Testing Pyramid image credit](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tvh1md0ibpbo5fd4ug1g.png)

_Facebook’s [Testing Pyramid](https://zhiminzhan.medium.com/testing-pyramid-clarified-af45535bed8b) image credit: “Continuous Integration at Facebook”_

I added two more references.

> “Facebook is **released twice a day**, and keeping up this pace is at the heart of our culture. With this release pace, automated testing with **Selenium is crucial** to making sure everything works before being released.” — DAMIEN SERENI, Engineering Director at Facebook, at [Selenium 2013 conference](https://2014.seleniumconf.in/2013/speakers/index.html).


![Microsoft recommends Selenium](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w3r15rzc2p72juwu6mug.png)

_Microsoft dumped its “Coded UI Test” and [recommended Selenium WebDriver](https://docs.microsoft.com/en-us/visualstudio/test/use-ui-automation-to-test-your-code?view=vs-2017)_

So, Selenium WebDriver works, and works very well! Accept this, first. This does not mean excluding others. But if someone wants to promote a new framework/tool X, people shall know the free, open-source, W3C-standard compliant Selenium WebDriver is excellent already for web test automation, when used by real test automation engineers, with [extremely high productivity](https://www.linkedin.com/pulse/400000-test-executions-clinicwise-buildwise-ci-server-zhimin-zhan/). Also, under proper guidance, [raw Selenium WebDriver is the easiest to learn](https://zhiminzhan.medium.com/step-by-step-showing-why-selenium-webdriver-is-the-easiest-to-learn-web-test-automation-framework-fa2b5904c08), only takes a few hours.

By the way, my continuous testing process (running automated end-to-end UI tests regression) [enables me to deploy all my apps on a daily basis](https://medium.com/nerd-for-tech/did-you-push-software-updates-into-production-yesterday-96bf5898d854), like Facebook, since 2012. I am NOT interested in debating specific features of a framework or tool, rather than the fundamental, whether your test automation is useful for the team (_check out [Definition of End-to-End Test Automation Success](https://zhiminzhan.medium.com/definition-of-end-to-end-test-automation-success-c668d914a87e)_). My Q&As below are for the engineers who are motivated for real test automation.

(1). _I acknowledge Selenium WebDriver (Ruby) syntax is better, however, Cypress is more than a framework, its tool makes creating tests easier?_

Wrong. The tool is after the framework, and always should be, in the context of software development. We talk about here are the test scripts (what really matters).

(2). _Cypress seems easier to use, compared to Selenium._

Wrong. Cypress is a combination of a framework and tool. You cannot compare a framework with a vendor-provided tool demo. HP’s QTP and IBM’s RFT had good demos too, further, some top magazines or consulting companies (such as Gartner) sang for them. The result: complete failures.

I think Selenium is much easier, TestWise help real automated testers be more productive and fun. Check out my daughter’s “[Set up, Develop Automated UI tests and Run them in a CT server on your First day at work](https://zhiminzhan.medium.com/set-up-develop-automated-ui-tests-and-run-them-in-a-ct-server-on-your-first-day-at-work-bd7110c9f677)”.

(3). _People tell me that Selenium is hard to learn_.

Wrong. My daughter started writing raw Selenium test scripts at the age of 12, with the right mentoring, your child could do that too. Check out my article: “[Why Selenium WebDriver is So Easy to Learn?](http://why%20selenium%20webdriver%20is%20so%20easy%20to%20learn/?)”.

As a matter of fact, some people hesitated for signing up for my [one-day “Web Test Automation with Selenium WebDriver” training](http://agileway.com.au/training/automation-selenium) because it was too short. My reply: “ learning Selenium WebDriver is just that easy, in fact, during that 8 hours, I spent over 50% on [Maintainable Automated Test Design](https://medium.com/geekculture/maintainable-automated-test-design-d325dd13b868) and [Functional Test Refactoring](https://zhiminzhan.medium.com/functional-test-refactoring-598872af9d51)”. By the way, no prior test automation/programming experience is required. Again, that’s because raw Selenium WebDriver is that simple and easy to learn. Many so-called ‘better’ frameworks such as [failed Protractor](https://zhiminzhan.medium.com/protractor-another-automation-framework-i-rightly-avoided-is-being-deprecated-aaf702241f43) actually made it harder.

(4). _I think developing Cypress scripts (with the Cypress tool) is more productive than that of Selenium._

Wrong. I am at least **10X** more productive than any Cypress and Playwright testers I met. I often completed a planned 3-month Test Automation Proof of Concept (POC) in a matter of days, typically ~ 3 days. The staff at those companies were shocked by my productivity. The reason: I am developing raw Selenium WebDriver test scripts in [TestWise](https://agileway.com.au/testwise), following good test-automation practices such as [Maintainable Automated Test Design](https://medium.com/geekculture/maintainable-automated-test-design-d325dd13b868), [Keep browser open](https://zhiminzhan.medium.com/my-innovative-solution-to-test-automation-keep-the-browser-open-after-executing-an-individual-test-b858c0a29a77), [Functional Test Refactoring](https://zhiminzhan.medium.com/functional-test-refactoring-598872af9d51), .., etc. Special mention: [Ruby is great for scripting automated tests](https://zhiminzhan.medium.com/which-selenium-webdriver-language-binding-is-best-683442e05796).
   
Not convinced? Check out the screencast in this article: “[Step by Step showing how to learn to write raw Selenium WebDriver test scripts in minutes](https://zhiminzhan.medium.com/step-by-step-showing-why-selenium-webdriver-is-the-easiest-to-learn-web-test-automation-framework-fa2b5904c08)”, and [some of the test suites](https://zhiminzhan.medium.com/agileway-continuous-testing-grading-f483a870d2e2) I have been maintaining over the years.

  * ClinicWise, [611 raw Selenium WebDriver tests](https://www.linkedin.com/pulse/500000-selenium-ui-test-executions-clinicwise-buildwise-zhimin-zhan/) (since 2012). 
  * TestWise, [307 raw Appium + WinAppDriver tests](https://zhiminzhan.medium.com/appium-desktop-test-automation-milestone-60-000-test-executions-over-2-years-for-300-test-3d0ceb5b84b4) (since 2019)
  * WhenWise, [551 raw Selenium WebDriver tests](https://zhiminzhan.medium.com/whenwise-regression-test-suite-reaches-500-selenium-tests-and-300k-test-executions-84279ae0ed35) (since 2018)

all in my spare time.

Any motivated manual tester can achieve high productivity (might take a while to match mine, but shall be much much higher than the so-called best JS automated tester) quite quickly. Many manual testers I mentored became the test automation authority in their companies.

(5). _I read the above articles and watched the tutoring, it did look very simple and easy. How come automated testers generally are associated with “difficult” to Selenium?_

There are many reasons and I covered those in other articles, such as “[Evil Mudslingings against Selenium WebDriver](https://zhiminzhan.medium.com/evil-mudslinging-against-selenium-webdriver-5a0ba4df07b2)”. Here, I want to just point out key ones concisely.

* Vendors [defame Selenium](https://zhiminzhan.medium.com/evil-mudslinging-against-selenium-webdriver-5a0ba4df07b2) (free, open-source) for commercial interests
* Test automation is often started by programmers who don’t really understand (but pretend), they often chose the [wrong language](https://zhiminzhan.medium.com/which-selenium-webdriver-language-binding-is-best-683442e05796) such as Java, C# or JavaScript.
* Not aware of a good Selenium tool, such as [TestWise](https://agileway.com.au/testwise).
* Never experienced a successful [Continuous Testing](https://zhiminzhan.medium.com/continuous-testing-clarified-52c90e9a6825#:~:text=The%20purpose%20of%20CI%20is,next%20ruined%20%27talker%20term%27.), often using CI servers such as Jenkins to run UI tests. Instead, they should use a CT server such as [Facebook’s Sandcastle](https://zhiminzhan.medium.com/recommend-a-great-ci-presentation-continuous-integration-at-facebook-6369323da084) or [BuildWise](https://agileway.com.au/buildwise).

(6). _I have used Selenium-based frameworks (created by our test architects), but it was not as easy as you showed us. Why?_

That’s because those people did not understand test automation, making Selenium harder. Check out my article “[Please, Not Another Web Test Automation Framework, Just Use Raw Selenium WebDriver](https://zhiminzhan.medium.com/please-not-another-web-test-automation-framework-just-use-selenium-webdriver-86693045d5af)”. Often they used the [wrong languages such as Java/C#](https://zhiminzhan.medium.com/automated-test-scripts-shall-be-in-the-syntax-of-a-scripting-language-naturally-8b6218812314), or the [wrong test syntax frameworks such as Gherkin](https://medium.com/swlh/why-gerkin-cucumber-specflow-always-failed-with-ui-test-automation-c85a8030c07d). Just use raw Selenium WebDriver + RSpec first and most popular [BDD framework](https://zhiminzhan.medium.com/bdd-clarified-bdd-given-when-then-gherkin-773b52b45eb3)).

(7). _Cypress’s new version has better ….?_

This is exactly what the problem is. I have been using Selenium WebDriver exactly the same way since 2011 ([Selenium v4 has some new features](https://zhiminzhan.medium.com/selenium-4-new-features-by-examples-in-ruby-4b1e100b2ad7)). Don’t you want this stability, or rather being dependent on others? Furthermore, it is really important to have consistent test script syntax when working in a team. As you have seen Gleb’s “[Avoid Cypress Pyramid of Doom](https://glebbahmutov.com/blog/avoid-cypress-pyramid-of-doom/)”, there are so many ways, a recipe for chaos.

(8). _How come so many testers claimed doing Cypress well? Are they all fake?_

I only can comment on people I met. Yes, [every Cypress/Playwright testers I met was a fake](https://zhiminzhan.medium.com/an-it-graduates-frustration-with-a-fake-senior-test-automation-engineer-8b0075954394). This is not belittling them, automated end-to-end testing is difficult (_except HelloWorld level demos_), even for Microsoft (see below). Using Cypress/Playwright makes it even much harder, unnecessarily.

> “95% of the time, 95% of test engineers will write bad GUI automation just because it’s a very difficult thing to do correctly”.
> - [this interview from Microsoft Test Guru Alan Page](https://testguild.com/alan-page-principles-lessons-learned-at-microsoft/) (2015)


---

Related articles:

* My eBook: “[Practical Web Test Automation with Selenium WebDriver](https://leanpub.com/practical-web-test-automation)”
* [Why Do Most UI Test Automation Fail? (Part 2: Wrong Choice of Test Syntax Framework)](https://zhiminzhan.medium.com/why-do-most-ui-test-automation-fail-part-2-wrong-choice-of-test-syntax-framework-2289aff0d81e)
* [Testing Pyramid Clarified](https://zhiminzhan.medium.com/testing-pyramid-clarified-af45535bed8b)
* [User Story Card Clarified](https://zhiminzhan.medium.com/user-story-card-clarified-c10df3f1229a)
* [Continuous Testing Clarified](https://zhiminzhan.medium.com/continuous-testing-clarified-52c90e9a6825)
* [“Done, Done” in Agile](https://zhiminzhan.medium.com/done-done-in-agile-8cd95f077411)
* [AgileWay Test Automation Formula](https://medium.com/geekculture/agileway-test-automation-formula-bcf550616d32)
* [Selenium vs X, Y, Z, …, all these years](https://zhiminzhan.medium.com/selenium-vs-x-y-z-all-these-years-979b8aa34125)