mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-24 09:29:35 -05:00
81 lines
1.6 KiB
Markdown
81 lines
1.6 KiB
Markdown
---
|
|
title: document
|
|
comments: true
|
|
description: ''
|
|
---
|
|
|
|
Get the document.
|
|
|
|
# Syntax
|
|
|
|
```javascript
|
|
.document()
|
|
.document(options)
|
|
```
|
|
|
|
## Usage
|
|
|
|
`.document()` cannot be chained off any other cy commands, so should be chained off of `cy` for clarity.
|
|
|
|
**{% fa fa-check-circle green %} Valid Usage**
|
|
|
|
```javascript
|
|
cy.document()
|
|
```
|
|
|
|
## Arguments
|
|
|
|
**{% fa fa-angle-right %} options** ***(Object)***
|
|
|
|
Pass in an options object to change the default behavior of `.document()`.
|
|
|
|
Option | Default | Notes
|
|
--- | --- | ---
|
|
`log` | `true` | whether to display command in command log
|
|
|
|
## Yields
|
|
|
|
`.as()` yields the `window.document` object.
|
|
|
|
## Timeout
|
|
|
|
`.document()` will retry for the duration of the [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts)
|
|
|
|
# Examples
|
|
|
|
## Document
|
|
|
|
**Get document and do some work**
|
|
|
|
```javascript
|
|
cy.document().then(function(document) {
|
|
// work with document element
|
|
});
|
|
```
|
|
|
|
**Make an assertion about the document**
|
|
|
|
```javascript
|
|
cy.document().its('contentType').should('eq', 'text/html')
|
|
```
|
|
|
|
# Command Log
|
|
|
|
**Get the document**
|
|
|
|
```javascript
|
|
cy.document()
|
|
```
|
|
|
|
The command above will display in the command log as:
|
|
|
|
<img width="588" alt="screen shot 2015-11-29 at 2 00 09 pm" src="https://cloud.githubusercontent.com/assets/1271364/11459311/aab8fe88-96a1-11e5-9b72-b0501204030d.png">
|
|
|
|
When clicking on `document` within the command log, the console outputs the following:
|
|
|
|
<img width="491" alt="screen shot 2015-11-29 at 2 00 22 pm" src="https://cloud.githubusercontent.com/assets/1271364/11459314/ad27d7e8-96a1-11e5-8d1c-9c4ede6c54aa.png">
|
|
|
|
# See also
|
|
|
|
- [window](https://on.cypress.io/api/window)
|