I am writing e2e tests using Cypress and I need to write a test that asserts if front-end correctly orders a set of elements.
Only for example, consider I have a page that just list a set of ages as follows:
<div id="list">
<div class="age">18</div>
<div class="age">20</div>
<div class="age">19</div>
</div>
And I want to write a test that asserts if it is sorted from older to younger.
One approach could be to get elements in which class is age and discover if it is ordered by iterate over them:
cy.get(".age").then((ages) => {
//check if elements are ordered iterating over ages array
})
But I can only guarantee that my test is correct if ages
array is in the same order as presented in HTML.
Does DOM elements yield by cy.get()
always are in the exact order that it is put in HTML document?
I can't find any reference to this in official documentation