document
Get the window.document
of the page that is currently active.
Syntax
cy.document()
cy.document(options)
Usage
Correct Usage
cy.document() // yield the window.document object
Arguments
options (Object)
Pass in an options object to change the default behavior of cy.document()
.
Option | Default | Description |
---|---|---|
log | true | Displays the command in the Command log |
timeout | defaultCommandTimeout | Time to wait for cy.document() to resolve before timing out |
Yields
-
cy.document()
'yields thewindow.document
object'
Examples
No Args
Get document and do some work
cy.document().then((doc) => {
// work with document element
})
Make an assertion about the document
cy.document().its('contentType').should('eq', 'text/html')
Rules
Requirements
-
cy.document()
requires being chained off ofcy
.
Assertions
-
cy.document()
will automatically retry until all chained assertions have passed
Timeouts
-
cy.document()
can time out waiting for assertions you've added to pass.
Command Log
Get the document
cy.document()
The command above will display in the Command Log as:

When clicking on document
within the command log, the console outputs the
following:
