Cypress tutorials
what is cypress?
cypress architecture
Selenium & cypress Architecture
cypress features
Cypress Installation and project setup
node-js
Visual Studio Code
Create New Project in Cypress
Open and start Cypress
cypress executable location
cypress open
Switch browser in cypress
Run TestCase in cypress
cypress Test Runner
cypress command line
Basic Test Case in Cypress
Mocha test framework in cypress
Describe and it in cypress
Basic test case
Hooks in Cypress
before() Hooks in Cypress
beforeEach() Hooks in Cypress
after() Hooks in Cypress
afterEach() Hooks in Cypress
Default assertion in cypress
When not to assert in cypress
How to modify default assertion timeout
Assertions in cypress
Implicit assertion using should & and
How to use should & and for assertion
Explicit assertion using should & and
How to use expect in assertion
Common assertions in cypress
Basic Comands in cypress
Custom Comands in cypress
Custom command syntax & command.js
Parent custom commands in cypress
Child custom commands in cypress
Dual custom commands in cypress
Example of cypress custom commands
Variables & Aliases in cypress
Return Values In Cypress
Closures in cypress
Default Assertion in Cypress
Assertion is used to verify a state of elements, objects and application that as per functionality is true.
Cypress commands automatically retry their assertions.The assertion behavior can be modified as per the use case.
We will cover below topics of assertions in cypress below:

When not to assert in Cypress?
Many Cypress commands have default built in Assertions and do not require to be invoked specifically.
Few of the commands that have default assertions are:
-
- cy.visit() : expects the page to send text/html content with a 200 status code.
- cy.request() :expects the remote server to exist and provide a response.
- cy.contains() :expects the element with content to eventually exist in the DOM.
- cy.get() :expects the element to eventually exist in the DOM.
- .find() : expects the element to eventually exist in the DOM.
- .type() :expects the element to eventually be in a typeable state.
- .click() :expects the element to eventually be in an actionable state.
- .its() :expects to find a property on the current subject.
Some Example to explain default assertion:
-
-
Default assertion example:
-
// there is a default assertion here
// .get() —verifies that button must exist in the DOM before proceeding
// .click() — verifies the button must be “actionable”
cy.get('button').click()
2. Reverse default assertion:
In some scenarios you need to verify that element does not exist or wait till it does not exist. You can simply reverse the default assertion by adding that assertion and Cypress will reverse its rules waiting for elements to exist. .should(‘not.exist’) is added to achieve this. // and now make sure this #alertMsg does not exist in the DOM // and automatically wait until it’s gone!cy.get('#alertMsg').should('not.exist')
*Default assertion waits up to 4 seconds for it to exist in the DOM for cy.get()*
Cypress gives different default timeout values for different commands.
Modify timeout of Default Assertions
-
- By Default the timeout set for default assertion is 4 seconds.
- For Example if there is a command cy.get(‘.button’) , cypress will wait for 4 seconds for the element to exist in DOM, otherwise it will fail.
- This default time can be modified using “timeout”.
cy.get('.button', { timeout: 10000 }) .should('be.visible') .and('contain', 'Tutorials')
cypress waits up to 10 seconds for ‘.button’ element to exist in the DOM
and waits up to 10 seconds for it to be visible
and waits up to 10 seconds for it to contain the text: Tutorials
Notice that this timeout has flowed down to all assertions and Cypress will now wait up to 10 seconds total for all of them to pass.
NOTE: The timeout parameter always goes inside the command not the assertion. Otherwise it will give an error.
Cypress tutorials
what is cypress?
cypress architecture
Selenium & cypress Architecture
cypress features
Cypress Installation and project setup
node-js
Visual Studio Code
Create New Project in Cypress
Open and start Cypress
cypress executable location
cypress open
Switch browser in cypress
Run TestCase in cypress
cypress Test Runner
cypress command line
Basic Test Case in Cypress
Mocha test framework in cypress
Describe and it in cypress
Basic test case
Default assertion in cypress
When not to assert in cypress
How to modify default assertion timeout
Assertions in cypress
Implicit assertion using should & and
How to use should & and for assertion
Explicit assertion using should & and
How to use expect in assertion
Common assertions in cypress
Basic Comands in cypress
Custom Comands in cypress
Custom command syntax & command.js
Parent custom commands in cypress
Child custom commands in cypress
Dual custom commands in cypress
Example of cypress custom commands
Variables & Aliases in cypress
Return Values In Cypress
Closures in cypress