mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-21 07:38:53 -05:00
91bb010fd6
- go into more detail on trigger vs action commands - explain actionability further - better format notes + examples - consistent no arg / arg examples - es6 all the functions - remove duplicated intractability content - remove simulated events garbage - go into more detail on pseudo action commands - much better cy.contains usage
2.1 KiB
2.1 KiB
title, comments
| title | comments |
|---|---|
| root | false |
Get the root DOM element.
Syntax
cy.root()
cy.root(options)
Usage
{% fa fa-check-circle green %} Correct Usage
cy.root() // Yield root element <html>
cy.get('nav').within(function(nav) {
cy.root() // Yield root element <nav>
})
Arguments
{% fa fa-angle-right %} options (Object)
Pass in an options object to change the default behavior of .root().
| Option | Default | Description |
|---|---|---|
log |
true |
{% usage_options log %} |
timeout |
{% url defaultCommandTimeout configuration#Timeouts %} |
{% usage_options timeout cy.root %} |
Yields {% helper_icon yields %}
.root() yields the root DOM element.
The root element yielded is <html> by default. However, when calling .root() from a {% url .within() within %} command, the root element will point to the element you are "within".
Examples
HTML
Get the root element
cy.root() // yields <html>
Within
Get the root element in a {% url .within() within %} callback function
cy.get('form').within(($form) => {
cy.get('input[name="email"]').type('john.doe@email.com')
cy.get('input[name="password"]').type('password')
cy.root().submit() // submits the form yielded from 'within'
})
Rules
Requirements {% helper_icon requirements %}
{% requirements parent cy.root %}
Assertions {% helper_icon assertions %}
{% assertions retry cy.root %}
Timeouts {% helper_icon timeout %}
{% timeouts assertions cy.root %}
Command Log
Get root element
cy.root().should('match', 'html')
cy.get('.query-ul').within(function(){
cy.root().should('have.class', 'query-ul')
})
The commands above will display in the command log as:
When clicking on the root command within the command log, the console outputs the following:
See also
- {% url
cy.get()get %} - {% url
.within()within %}

