prevAll
Get all previous siblings of each DOM element in a set of matched DOM elements.
The querying behavior of this command matches exactly how
.prevAll()
works in jQuery.
Syntax
.prevAll()
.prevAll(selector)
.prevAll(options)
.prevAll(selector, options)
Usage
Correct Usage
cy.get('.active').prevAll() // Yield all links previous to `.active`
Incorrect Usage
cy.prevAll() // Errors, cannot be chained off 'cy'
cy.getCookies().prevAll() // Errors, 'getCookies' does not yield DOM element
Arguments
selector (String selector)
A selector used to filter matching DOM elements.
options (Object)
Pass in an options object to change the default behavior of .prevAll()
.
Option | Default | Description |
---|---|---|
log | true | Displays the command in the Command log |
timeout | defaultCommandTimeout | Time to wait for .prevAll() to resolve before timing out |
Yields
-
.prevAll()
yields the new DOM element(s) it found.
Examples
No Args
.third
Find all of the element's siblings before <ul>
<li>apples</li>
<li>oranges</li>
<li class="third">bananas</li>
<li>pineapples</li>
<li>grapes</li>
</ul>
// yields [<li>apples</li>, <li>oranges</li>]
cy.get('.third').prevAll()
Selector
li
. Keep only the ones with a class selected
Find all of the previous siblings of each <ul>
<li>apples</li>
<li>oranges</li>
<li>bananas</li>
<li class="selected">pineapples</li>
<li>grapes</li>
</ul>
// yields <li>pineapples</li>
cy.get('li').prevAll('.selected')
Rules
Requirements
-
.prevAll()
requires being chained off a command that yields DOM element(s).
Assertions
-
.prevAll()
will automatically retry until the element(s) exist in the DOM -
.prevAll()
will automatically retry until all chained assertions have passed
Timeouts
-
.prevAll()
can time out waiting for the element(s) to exist in the DOM . -
.prevAll()
can time out waiting for assertions you've added to pass.
Command Log
Find all elements before the .active
li
cy.get('.left-nav').find('li.active').prevAll()
The commands above will display in the Command Log as:
When clicking on prevAll
within the command log, the console outputs the
following: