I have the following lines of code in my before() hook.
before(() ==> {
cy.get(this.testPopup).then(($el) => {
if ($el.length) {
cy.get(this.testPopupCloseButton).click();
cy.get(this.testPopup).should("not.exist");
}
});
});
There will be a popup which will display sometimes and sometimes it will not. I tried to write a logic to close that popup and check if it getting disappeared on closing only when the popup exists.
But I am getting the following error.
Timed out retrying after 30000ms: Expected to find element: #test-popup-element, but never found it.
Because this error occurred during a before all hook we are skipping the remaining tests in the current suite`
I am expecting a soft assert here basically, which will continue to run the rest of the tests even if this assertion fails.
Please advice.
The issue is that using
cy.get(this.testPopup)
contains an implicit assertion that thethis.testPopup
element exists. So in the case where it doesn't, the test fails because Cypress can't find the element.From the Cypress Conditional Testing documentation, they recommend using
cy.get('body')
and then querying for the element (using JQuery's.find()
.)