Skip to main content

Cypress Document Command

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.
Tags
Submitted by arilio666 on June 10, 2022

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.