Questions tagged [cypress-conditional-testing]
30 questions
54
votes
6 answers
How to check for an element that may not exist using Cypress
I am writing a Cypress test to log in to a website. There are username and password fields and a Submit button. Mostly logins are straightforward, but sometimes a warning dialog appears first that has to be dismissed.
I tried…

Charles Anderson
- 19,321
- 13
- 57
- 73
18
votes
6 answers
Can I prevent Cypress cy.get from failing if no elements are found?
I am using Cypress cy.get to grab elements, but if there are none, my test is failing.
I do not want it to fail. I want it to continue. The test is simply to list the items that are there, if any.
const listItemTitle =…

Steve Staple
- 2,983
- 9
- 38
- 73
10
votes
0 answers
Dialog that may or may not appear on page start
I need to handle the case where my page may display a popup dialog at the load stage, or it may not appear. Clicking anywhere will remove it and I'm not interested in testing this dialog, but it blocks the page I need to access so it must be…

Lisa La
- 157
- 9
4
votes
2 answers
Cypress returning Synchronous value within Async command?
So I think this is probably me mixing up sync/async code (Mainly because Cypress has told me so) but I have a function within a page object within Cypress that is searching for customer data. I need to use this data later on in my test case to…

msmith1114
- 2,717
- 3
- 33
- 84
4
votes
2 answers
Cypress - Conditional test with timeout
I'm trying to do something very similar to this post:
https://stackoverflow.com/questions/56145926/how-to-check-if-element-exists-using-cypress-io
I'm using typsecript. Here's my code:
cy.get("body").then($body => {
if…

NicolasM
- 77
- 6
2
votes
1 answer
How to do Conditionals in Cypress
In my e2e, I need to check if the datatable is populated first before before checkboxes in the table are clicked.
I am able to check the count like so
cy.get('.p-datatable-table').find('tr').its('length').should('be.gte', 0);
unfortunately, the…

OLA
- 861
- 2
- 11
- 23
2
votes
1 answer
Act when element exists, but don't fail when it doesn't (Cypress E2E tests)
I'm writing E2E tests in Cypress (version 12.3.0). I have a page with a table in a multi-step creation process that requires some data from back-end application. In some cases (rarely, but it occurs) the request gets stuck and the loader never…

Jonasz
- 1,617
- 1
- 13
- 19
2
votes
2 answers
Conditional Testing with Cypress e2e
I have a test case of my site with cypress. however the site, which is been built in vue.js has lets say 2 journeys. in one of them there is an button which I want to click. So, what I want to do is the following:
if ('button exists') {
…

A Bit Of Everything
- 21
- 3
2
votes
2 answers
How to Skip a Test if an element is not present in Cypress
I am writing a test in which if I land on a page and if any records are available, I need to click on three dots buttons near the record. But I should skip the test if no records are available on the page.
cy.get('body')
.then(($body) => {
…

Bhawin Joshi
- 31
- 2
2
votes
2 answers
How can I write if-else conditions in cypress according to element's value?
How can I run this function, according to the value change of element with if-condition?
assertSwitch(){
cy.get('[data-test="form-switch"]').invoke('attr','value').then(($switchOnOff) =>{
…

Solufer
- 21
- 1
- 3
- 7
1
vote
1 answer
Cypress assertion of two classes
I have this code on Cypress
cy.wrap(null).then(() => {
const $calculatorPayout = Cypress.$(".flex.flex-col.items-center.justify-center.h-\\[50px\\].w-10.border.border-solid.border-black-main")
const $usualPayout =…

Hristo Atanasov
- 11
- 1
1
vote
2 answers
Is there a way to return true or false if an element is clickable. I want to check if one of 3 imprint links is clickable
I want to find out if imprint links are working. Sometimes there are cookie consistent banners and you can not click the link on the page.
But is there a way to find out if there is a second imprint link is clickable on the modal?
export const…

Al Kativo
- 135
- 2
- 9
1
vote
2 answers
After updating to cypress 12.0.0, my test is throwing an error in the cypress-if package
After updating to cypress 12.0.0, I get the following error, how can I fix it?

Oleh Dymych
- 315
- 1
- 3
- 7
1
vote
1 answer
How do you make a conditional test if an element exists in Cypress?
There is a lot online about testing if an element exists, but i can't find anything really specific that could help in my case.
For context, I am working on a website that has certain elements in them (like a todo list).
I want to write a…

WirbleWind
- 11
- 1
1
vote
3 answers
Cypress - How to use if statement with contains
so I have to use cy.contains to find the element I want, but all I can find online is how to use if() with cy.find or cy.get if there a way to do this with contains?
Example code:
if(cy.contains('div.name', 'Test 1').length > 0) {
…

FlawFull
- 87
- 9