Integrating Cypress Explicit Wait / Wait Until Library
Kushan Shalindra Amarasiri
Director Quality Engineering at Social Catfish
In any test automation tool we will experience slowness in the web solution that we have test automated. It might be due to slowness in the communication channel or slowness in the hosted server. Therefore we have to instruct the script to wait for a stipulated time and see whether elements are appearing. Most favourable way we can do is to use a explicit wait.
In this article we will cover how we can integrate explicit wait with the use of Wait Until library.
First install the module with the following npm command
npm?install?cypress-wait-until
Then add the command easily to your script where we do a page transition
require('cypress-xpath')
import?'cypress-axe'
import?'cypress-wait-until'; // add the import
///?<reference?types="cypress"?/>
///?<reference?types="cypress-xpath"?/>
?
describe('Kushan?First?Test',?function(){
????it('Guru?99?Login',function(){
????????cy.visit('https://demo.guru99.com/v4/')
????????cy.xpath("https://input[@name='uid']").type('mngr332873')
????????cy.xpath("https://input[@name='password']").type('umEtyvy')
????????cy.xpath("https://input[@name='btnLogin']").click()
????????cy.waitUntil(()?=>?cy.window().then(?cy.xpath("https://tr[@class='heading3']/td").should('have.text',?'Manger?Id?:?mngr332873')),?{
??????????errorMsg:?'There?is?an?issue?with?login',?//?overrides?the?default?error?message
??????????timeout:?2000,?//?waits?up?to?2000?ms,?default?to?5000
??????????interval:?500?//?performs?the?check?every?500?ms,?default?to?200
????????});
????????cy.xpath("https://tr[@class='heading3']/td").should('have.text',?'Manger?Id?:?mngr332873')
???????
???????
????})
})