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().

OptionDefaultDescription
logtrueDisplays the command in the Command log
timeoutdefaultCommandTimeoutTime to wait for cy.document() to resolve before timing out

Yields

  • cy.document() 'yields the window.document object.
  • cy.document() is a query, and it is safe to chain further methods.

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 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:

Command log document

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

console.log document

See also