Cypress Document Command

Profile picture for user arilio666

Document command fetches the document, or we can say the skeleton of the current page we are in.

Syntax:

cy.document()
cy.document(options)

Arguments Used In Document:

Options: Argument used to pass in an object to change the default behavior of cy.document().

  • Log: Displays the command in the command log, and the default value is true.
  • Timeout: Time to wait till the next command resolves before timing out.

Correct Usage Of Document:

cy.document()
  • Yields the window.document object from the current page.

describe('Automate PB',()=>{

    it('Next',()=>{


      cy.visit("https://www.programsbuzz.com/user/login")
      cy.document()

   

        })
    })

cypress document command

And there we go, cypress yielded the entire document of the current login page.

Rules:

  • cy.document() must be chained off with cy.
  • cy.document() will automatically retry until all chained assertions have passed.
  • cy.document() can also timeout waiting for the assertions added to pass.
  • cy.document() yields the window.document object.