The flexi-ways of asserting with Cypress.io

 

One the many joys of working with Cypress is the variety of support for various assertion methodologies.

What is even more powerful is that they can be chained at the end of core Cypress API commands like cy.get

Here are coupe of examples that I put into practice recently.

  1. JQuery based


cy.get("#header > div > div > div:nth-child(2) > div > div.headButtons > div.header_button_float.logMenu > div > a.underLine")
// assert that the element's text matches a reg ex
.should(($txt) => {
const text = $txt.text()
expect(text).to.match(/Login/)
})

view raw

cypress.js

hosted with ❤ by GitHub

2. BDD type assertions


//assert that the element contains a particular text
cy.get('.whtLink').should('contain','nirvana')

view raw

cypres.js

hosted with ❤ by GitHub


//find and confirm that an element is visible
cy.get("#header > div > div > div:nth-child(2) > div > div.headButtons > div.header_button_float.logMenu > div > a.underLine")
.should('be.visible')

view raw

cypress.js

hosted with ❤ by GitHub

Simple , elegant and flexible 🙂

I will continue to practice further ways to assert using Cypress

Which assertion methodology do you particularly prefer?

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s