Category:
Cypress
1. Implicit Assertion
a) should
b) and
2. Explicit Assertion
a) expect (BDD style)
b) assert (TDD style)
Implicit Assertion - should - example:
cy.visit("https://hireqa.co.in/interview-qa/?include_category=cypress")
cy.url().should('include', 'hireqa.co.in')
cy.url().should('eq', 'https://hireqa.co.in/interview-qa/?include_category=cypress')
cy.url().should('contain', 'hireqa')
//Verify the element is visible
cy.get('webelement').should('be.visible')
//Verify the element exist
cy.get('webelement').should('exist')
//Verify the entered username is correct
cy.get('webelement').type('username')
cy.get('webelement').should('have.value','username')
Implicit Assertion - and - example:
cy.visit("https://hireqa.co.in/interview-qa/?include_category=cypress")
cy.url().should('include', 'hireqa.co.in')
.and('eq', 'https://hireqa.co.in/interview-qa/?include_category=cypress')
.and('contain', 'hireqa')
.and('not.contain', 'xyz');
//Verify the logged-in user is same
let expectedName = 'hireqa';
cy.get('webelement').then((name) => {
let actualName = name.text()
expect(actualName).to.equal(expectedName)
})
//Assert example
assert.equal(actualName, expectedName)
assert.notEqual(actualName,expectedName)