6

I see many articles pointing out the effectiveness of Cypress as against Selenium for automating web applications. From most of the articles I've read, I see some points for Cypress such as:

  1. Cypress is lightweight and faster than Selenium
  2. Cypress is better at handling implicit / explicit waits than Selenium
  3. Cypress is more versatile than Selenium i.e. Cypress Can do DB as well as API testing as opposed to Selenium which is mainly used for testing UI.

For those who have used both tools, if given a choice which tool would you prefer?

  • 6
    This is like asking whether automobiles are set to replace engines as the preferred tool for transportation. Selenium is one component of an end-to-end testing system; combining it with something like Geb and Spock vs. Cypress is a much closer comparison. – chrylis -cautiouslyoptimistic- May 21 at 23:13
8

In our last project we also evaluated different tools among these were also Cypress and Selenium. At the end we decided for Selenium, because we were testing front end applications and for us Cross-Browser testing was one of the most important reasons, why we made the decision for selenium. Furthermore our test management had the requirement to integrate one of the evaluated tools in our test management tool.

So it is difficult just to say, selenium or cypress is better. From my point of view this also depends on your project which you have (just E2E test, Unit test, etc. focus on cross browser testing?) and also on the circumstances. As already said in our case it was cross-browser testing and ingetration with other test management tools.

Let me highlight some of the differences between both (and why at the end we used selenium):

  • Cross Browser testing

We had to test different browsers since we had to test a front end application. This should be run with every version & kind of browsers e.g. Opera, Firefox, IE, Chrome etc, and Cypress is just running with Chrome (by the way this was nearly a k.o. critera for us as front end testers)

EDIT: With Cypress Version 4.0 Cypress introduced also the browser MS Edge and Firefox but that was before our implementation (around 2018/2019) see link: Introducing Firefox Cypress

  • Supported dev languages

Most of us were familiar with Java. Furthermore selenium is also supporting C#, JavaScript, Python etc. And Cypress is just supporting JavaScript. But since most of our guys were familiar with Java - most of our testers voted for Selenium.

  • Regarding documentation

We also thougth about documentation about both tools. So what would happen, if we set up a large framework (at least we got around > 30 testers in different departments) and we e.g. need more information about creating automated test cases? So is are there plenty of documentation? I think in both cases - in Selenium you got a robust community, mulitple bindings and also best practices, in Cypress.io you have only a "good documentation" but In my opinion it is not widespread as Selenium. (Furthermore our department - we have a large software quality department / It-department - was thinking also introducing Selenium as standard test automation tool for front end applications)

  • Breadth of testing options & binding with commercial tools

This question was also important for us. Can we do also other testing stuff e.g not just E2E tests also e.g. Unit test? We don't wanted to introduce a tool for E2E test, a different tool for Unit test, a different tool for security test....with Selenium we were also able to execute unit tests. And with Cypress.io you just can execute E2E tests. Furthermore the adaption with other tools is relevant. For example for our test management tool we used Tricentis. Also most commercial tools (e.g. test management tools) are supporting selenium and unfortunately not Cypres.io.

But of course, from our lessons learned we also found out that selenium (sometimes) is not as fast as Cypress.io. Seems that Cypress.io is more related to developers than to testers. (see also link Aplitools Selenium vs. Cypress )

If you need more readings there are some links which can help you in your decision which tool to use:

Cypress-vs.Selenium

| improve this answer | |
  • There're 2 inaccurate statements in your answer: 1) Cypress supports more browsers as well, including Edge and Firefox (so far in beta): docs.cypress.io/guides/guides/launching-browsers.html#Browsers 2) Cypress also supports unit testing docs.cypress.io/guides/overview/… – pavelsaman May 21 at 18:47
  • Thanks for your advice! During our evaluation we hadn't found this, but one thing was also important for us - the adaption & integration wiht our tool tricentis, with selenium it was working but not with cypress.io :-) – Daniel Boehm May 21 at 18:50
  • 1
    thanks for the advice! I edited my answer above – Daniel Boehm May 21 at 19:25
  • 3
    "With Cypress Version 4.0 Cypress introduced also the browser MS Edge and Firefox" Note that when they say they added Edge, they mean the Edge project moved to Chromium and so integrating with it was just like with integrating with Chrome. It doesn't support Legacy Edge (v44 and earlier). Right now, a lot of people are still on Legacy Edge, though hopefully across the course of the year that drops fast. – T.J. Crowder May 22 at 6:49
  • 1
    I prefer to avoid the language "more related to developers than to testers" becuase developers are testers as well and testers are developers of automation code. Using the terms QA and testers has unfortunately become part of a pervasive 2nd class citizen characterization of people. (to be clear, when I use the reference citizen,I am talking about testing vs. dev not anything about immigration etc.). I advocate Automation Engineers and Application Engineers be the terms used. – Michael Durrant May 24 at 16:25
7

Probably not, mainly because:

  • WebDriver is a W3C Spec
    • WebDriver supports all major programming languages
    • WebDriver is supported by all major browser vendors
    • WebDriver is 100% open-source
  • Cypress has commercial owners and for example "Test parallelization" is not in their open-source offering.
  • Cypress is JavaScript only, which is not everyones cup-of-tea
  • Cypress has limited cross-browser support (currently missing Safari, Opera, Legacy Edge and InternetExplorer)
    • What if a new browser becomes popular? The browser probably implements W3C and you can use it with WebDriver, how long do you have to wait for Cypress support?

I guess you could monitor vacancy requirements trends. Looking at the Dutch vacancies there are 5 times more Selenium items. I guess Cypress is growing, but I do not expect it to overtake Selenium any time soon if at all.

Also Cypress has a competitor called Puppeteer in the JavaScript front-end testing niche, which might be more atractive to developers as that is its target group. My previous team choose Puppeteer over the other tools.

| improve this answer | |
  • Puppeteer has the same limitation of supporting one browser(chrome) only. Look for "Playwright" the new puppeteer implementation(by same team as new library) supporting all browsers. – Vishal Aggarwal May 21 at 20:42
  • 2
    "currently missing Safari and Opera" And Legacy Edge. The Edge support is only for Chromium Edge. – T.J. Crowder May 22 at 9:33
4

It really depends on what you need. I've used both, so here's my opinion:

  • Cypress seems better at handling waits (your point n. 2), this could be such a pain in other tools, but it's an internal part of Cypress, which usually makes you write tests faster and the tests tend to be a bit more stable.
  • Selenium is almost always used with some programming/scripting language (popular are Java, C#, or Python), or even within other framework/wrappers such as Robot framework. This basically means you can connect to a DB or API easily. Selenium in this setup is really just an API that you use in a programming/scripting language to access a web page. You can check out more here: https://en.wikipedia.org/wiki/Selenium_(software). So I don't really see why your Cypress should be more versatile in this regard.
  • Cypress uses a different syntax, callbacks, JS, no conditional testing, chains etc. Many of these features are what many people/testers are not used to, so if you give them a tool that's so different in so many ways, they might struggle with it for some time. You need to consider how your team/colleagues can work with the tool before making it a default on a project.

So, before making a decision, you should consider what you want to use it for, who is going to use it, what training you can provide to your testers etc. I don't think there's a general answer to your question.

| improve this answer | |
  • 1
    Also want to add the screenshot and video recording feature in cypress which looks interesting . But i haven't played much with cypress yet – PDHide May 21 at 13:28
3

From what I remember Selenium handles iFrames and parallel testing far better than Cypress. Finally, If you learn cypress without learning selenium you won't build transferable skills. I'm a javascript dev, but if push came to shove I could probably write a test suite in Java or Python because the api is the same and there's plenty documentation (in fact, I have).

Importantly, you can transfer your selenium skills to Appium and write automation suites for iPhone and android apps. Not with Cypress, this is because not only does it introduce an entirely new API, but they are trying to burn down all the old conventions as well.

| improve this answer | |
1

If the underlying real question is -Which library is better to invest time from job perspective in long term? The question itself is WRONG!!

Atleast 90% of the time when we think we are learning/understanding/working/troubleshooting an automation library, we are actually dealing with an language. Is comparison of text or connecting to an DB/executing queries or making API calls are features of selenium/or cypress - NO.

The battle never was and never will be between libraries but between underlying languages. What are these libraries/frameworks anyways ? Nothing just tips of icebergs called languages.

In quite short term(few months) a new library will surface as "new preferred one" before one would be able to call oneself an expert in library "A" after investing long hours/weeks/or even months into it.

Its always been like this and likely will be in the future.

On the other hand once upon a time the de facto language for test automation was vbScript then later it became Java then ruby/python etc..but now all new automation libraries are moving in one direction - JAVASCRIPT. This process roughly took almost 20 years as I witnessed!

Most of the people, new to automation/ or even experienced automation engineers spend most of their time on learning new libraries features and very less time is devoted on the underlying language on the deeper level.

If one analyse, all his interview rejections he will find majority of them were due to inability to handle language level problems instead of library level.

Ex. Find the value of row X & column Y from a grid displayed in a page.

Any serious JavaScript automation engineer will tell you how important is to deeply learn "Promises" compared to any library level feature to handle sync issues which is one of the most frequently faced problem in any automation.

Advice: Invest time to deeply learn the language(JavaScript) not the library!

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.