Cypress pause Command

Profile picture for user arilio666

The Cypress pause command stops or pauses the running code to where we specified the command. It stops/pauses the test from running and allows interaction with the test.

The test can be resumed in the test runner place. Note that this does not set debugger on our code like the .debug()

Syntax

.pause()
.pause(options)

cy.pause()
cy.pause(options)

Options: Can pass an options object to change the default normal behavior of the cy.pause(). The only accepted option is log. pause can be chained off directly with cy and with any other command also.

Correct Use:

cy.pause().get('#search-widgets img')

Pause at the beginning of commands

cy.get('#search-widgets img').pause() 

Pause after the 'get' commands.

Example

  • Let us see a real-time demo with a URL command to execute the URL and location command.
  • We will pause before running the location command.
describe('URL Command',()=> {
    it('Should load the url',()=>{
        cy.visit('/')
        cy.url().should('include','/user/login')
        cy.url().should('contain',Cypress.config().baseUrl)
        cy.url().should('eq',Cypress.config().baseUrl)
        cy.pause()
        cy.location('href').should('include','/user/login')
        cy.location('href').should('contain',Cypress.config().baseUrl)
        cy.location('href').should('eq',Cypress.config().baseUrl)
        
    })
})
  • Here, we try to pause the URL assertion before location command execution.
  • Let us see what happens.

  • As we can see here, the test got stopped/paused before executing the location test code part.
  • It will not resume until we click resume here in the test runner window.
  • When clicked resume, it automatically resumes the test.
  • The play button on the right bottom will suffice to continue the test.

  • So we can see here that the test has paused and resumed when clicked on the play button.
  • This is one way we can utilize the feature of the pause command.