This video shows how to do conditional testing (click a button only if it is enabled) using my plugins cypress-if and cypress-await.
// cypress-if solution
cy.contains('button', 'Click Me')
// tests using Chai assertion "be.enabled"
.if('enabled')
.click()
.should('have.text', 'Clicked')
.else('Nothing to click')
// cypress-await solution
const enabled = cy.contains('button', 'Click Me').invoke('is', ':enabled')
cy.log(`enabled? ${enabled}`)
if (enabled) {
cy.contains('button', 'Click Me').click().should('have.text', 'Clicked')
} else {
cy.log('Nothing to click')
}
Plugins repos are https://github.com/bahmutov/cypress-if and https://github.com/bahmutov/cypress-a... Look for a blog post with code examples for this video by following https://glebbahmutov.com/blog/
Watch video Click Button If Enabled Using cypress-if And cypress-await Plugins online, duration hours minute second in high quality that is uploaded to the channel gleb bahmutov 21 February 2024. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 1,063 times and liked it 29 visitors.