Hot answers tagged

46 votes

How to check a button is disabled using Cypress

Well this was embarrassingly simple cy.get('button.mat-button.mat-primary').eq(8).should('not.be.disabled') cy.get('button.mat-button.mat-primary').eq(8).should('be.disabled') and this will allow me ...
Adam A's user avatar
  • 1,037
11 votes

How to check a button is disabled using Cypress

The Cypress documentation shows examples how you can use should() to verify elements are enabled/disabled: https://docs.cypress.io/api/commands/should.html#Assert-the-checkbox-is-disabled cy.get(':...
Niels van Reijmersdal's user avatar
9 votes
Accepted

Is Cypress set to replace Selenium as the preferred tool for automating web applications?

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-...
Daniel Boehm's user avatar
  • 1,173
8 votes
Accepted

How to simulate a simple keypress in Cypress

Found an answer: cy.get('body').trigger('keydown', { keyCode: 27}); cy.wait(500); cy.get('body').trigger('keyup', { keyCode: 27}); The amount of time cy.wait() waits is arbitrary. It depends on ...
Yu Zhang's user avatar
  • 9,952
7 votes

Is there a way to automate multiple tabs using cypress?

From the Cypress site: Because Cypress runs in the browser, it will never have multi-tabs support. We do have access to the browser automation APIs to actually switch tabs, but there is no ...
João Farias's user avatar
  • 10.9k
7 votes

Is Cypress set to replace Selenium as the preferred tool for automating web applications?

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 ...
Niels van Reijmersdal's user avatar
7 votes

How to simulate a simple keypress in Cypress

The recommended command is: cy.get('#someId').type('{esc}'); I'm using this to disclose pop-ups and where it makes sense to use ESCape as a User. Cypress version: 8.3.0
Raul Huluban's user avatar
6 votes

Cypress vs Protractor for end-to-end testing

Open Source: I am a developer at Cypress.io. Cypress recently released its public beta and is now open source. The code for it's core product, the Test Runner can be found here. The Cypress ...
Jennifer Shehane's user avatar
6 votes
Accepted

Cypress vs Protractor for end-to-end testing

Open source: Cypress.IO looks promising, but I have been holding off with starting to use it on a production project. My main reason that it is a commercial company and I cannot be sure they keep ...
Niels van Reijmersdal's user avatar
5 votes
Accepted

Test all elements in a single test or 18 separate tests

Three things should be considered, all equally important: Performance: Will creating several tests increase the suite execution time? It highly depends on your framework. Even if the time to ...
João Farias's user avatar
  • 10.9k
5 votes

How to check a button is disabled using Cypress

Your question mentioned both active and visible and they are separate as in: visible / not-visible active / not-active (disabled but visible) These two different pieces of state should be considered ...
ARMUGHAN ALI's user avatar
5 votes

Is Cypress set to replace Selenium as the preferred tool for automating web applications?

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 ...
pavelsaman's user avatar
  • 4,548
4 votes
Accepted

If else loop is not working/ element exists: cypress automation

$() is equal to findelement(by.css('')). And in your case the locator is: .Typography__StyledTypography-sc-153d8g4-0 jhYDmS TrainingQueueListstyles__EmptyListMessage-sc-19yfim3-1 ihRiqU which means ...
PDHide's user avatar
  • 11.1k
4 votes
Accepted

Do something as long as element is on page - cypress

Ok so there is a way, but I am not sure if this is "the" way when it comes to Cypress. You can write a recursive function that will call itself when the button is present. I have used a site which has ...
Moro's user avatar
  • 1,052
4 votes

How to check a button is disabled using Cypress

I recently found this code working in my case where I wanted to check if the element was enabled for next actions: this.button().then(($btn) => { if ($btn.is("enabled")) { //do ...
Mudra's user avatar
  • 41
4 votes
Accepted

How to wait till all components are loaded in Cypress?

There's no such concept of waiting or even writing your own waits (like with Selenium) in Cypress. Cypress has this built in. I recommend reading their docs, it's one of the core concepts mentioned ...
pavelsaman's user avatar
  • 4,548
4 votes
Accepted

Assert that options (text) in drop down are unique

Get the text and add to a array Convert array to set and compare the size Set will have only unique elements (Removes the duplicates) So if length of set and array are different , it means there where ...
PDHide's user avatar
  • 11.1k
4 votes

How can Cypress be seen as an End-to-end testing tool when it cannot travel across different domains?

What you're describing is mentioned here in the Cypress documentation. Cypress documentation also mentiones some workarounds. I think the bottom line for you is this part: A common use case for this ...
pavelsaman's user avatar
  • 4,548
4 votes

How to simulate a simple keypress in Cypress

I was able to simulate native keypresses by utilizing the following repo: https://github.com/dmtrKovalenko/cypress-real-events With the included cy.realPress('Escape') command it should work like a ...
PhilipAllStar's user avatar
4 votes

XHR requests are cancelled in Cypress

It seems you want to wait until routes resolve. If that is the case, you need to explicitly tell Cypress to do just that. For example, if I want Cypress to wait for a specific route, I write it like ...
pavelsaman's user avatar
  • 4,548
4 votes

Conditional testing on checkbox in Cypress

Conditional testing is not recommended by Cypress, but it's possible to deal with this situation like this: html: <div> <input type="checkbox" id="mytestcheckbox" /> ...
pavelsaman's user avatar
  • 4,548
3 votes

Cypress if-then-else, while and foreach

The creators have strong opinions on why you should not use conditional logic in your test however, Cypress doesn't disallow the use of javascript control methods. Cypress has a robust API you can ...
Phillipe Bojorquez's user avatar
3 votes

End to End tests on multiple build agents?

Depends on the goal of the test. I like to differentiate test goals, for example between: Pure Functional, Tests which check if the functionality works in general. This should work on a stable ...
Niels van Reijmersdal's user avatar
3 votes

Is Cypress set to replace Selenium as the preferred tool for automating web applications?

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 ...
codemon's user avatar
  • 179
3 votes
Accepted

How can I measure the coverage of my E2E tests?

Michael Bolton proposes testing coverage as: “X coverage is how thoroughly we have examined the product with respect to some model of X”. And he completes: "Test coverage, like quality, is not ...
João Farias's user avatar
  • 10.9k
3 votes

How can Cypress be seen as an End-to-end testing tool when it cannot travel across different domains?

Remember context - what works for some may not work for you. Other than the suggestions above, consider your system and think about what you need. Cypress is a popular tool but not every test tool is ...
Moorpheus's user avatar
  • 263
3 votes
Accepted

How to get cookie value in cypress from a cy.request response?

Cookies are in headers, so you need to get them there: cy.request({ method:'GET', url:`https://test:[email protected]/meat/meat-chicken.html` }) .then((response) => { ...
pavelsaman's user avatar
  • 4,548
3 votes

How to return a value from a then() block and use it in another then block in cypress

It's mentioned in the documentation mentioned in the comment section, I recommend reading it. Specifically, you can read this part about closures. What you can do is to put the other cy.get() inside ...
pavelsaman's user avatar
  • 4,548
3 votes
Accepted

Conditional statement in cypress

Just like jonrsharpe said in the comments, cy.contains will not return true/false depending on whether the element is there. In fact, it won't return anything of interest, as Cypress commands are ...
Cycy's user avatar
  • 136
3 votes

What is the best cypress approach for waiting on data from an API?

You can pass a timeout argument. cy.get('[data-cy=searchOutput]', { timeout: 10000 }).contains('Searching...');
João Farias's user avatar
  • 10.9k

Only top scored, non community-wiki answers of a minimum length are eligible