document

Improve this doc

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 the window.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 of cy.

Assertions

  • cy.document() will automatically retry itself until assertions you've chained all pass.

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:

Command log document

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

console.log document

See also