I’m trying to automate a webpage which shows a popup sometimes, not every time.
I tried to automate it using cypress-if
plugin
<code>// Close popup if present
Cypress.Commands.add('closePopupIfPresent', (popupSelector, buttonSelector) => {
cy.xpath(popupSelector).should('not.be.exist')
.if('be.exist').and('be.visible')
.then(() =>
cy.clickXpathElement(buttonSelector))
.else()
.log('No popup found');
});
</code>
<code>// Close popup if present
Cypress.Commands.add('closePopupIfPresent', (popupSelector, buttonSelector) => {
cy.xpath(popupSelector).should('not.be.exist')
.if('be.exist').and('be.visible')
.then(() =>
cy.clickXpathElement(buttonSelector))
.else()
.log('No popup found');
});
</code>
// Close popup if present
Cypress.Commands.add('closePopupIfPresent', (popupSelector, buttonSelector) => {
cy.xpath(popupSelector).should('not.be.exist')
.if('be.exist').and('be.visible')
.then(() =>
cy.clickXpathElement(buttonSelector))
.else()
.log('No popup found');
});
- If no elements present it works fine. But it’s not click the close button when it appears.
The error I’m facing:
<code>AssertionError: Timed out retrying after 30000ms:
Expected <section#__dialog8-cont.sapMDialogSection> not to exist in the DOM,
but it was continuously found.
</code>
<code>AssertionError: Timed out retrying after 30000ms:
Expected <section#__dialog8-cont.sapMDialogSection> not to exist in the DOM,
but it was continuously found.
</code>
AssertionError: Timed out retrying after 30000ms:
Expected <section#__dialog8-cont.sapMDialogSection> not to exist in the DOM,
but it was continuously found.
New contributor
Noordeen M is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1