To alias a route or DOM element for use later, use the cy.as()
command.
// this is a good use case for an alias,
// we don't want to write this long traversal again
cy
.get('.as-table').find('tbody>tr')
.first().find('td').first().find('button').as('firstBtn')
// maybe do some more testing here...
// when we reference the alias, we place an
// @ in front of it's name
.get('@firstBtn').click()
.get('@firstBtn')
.should('have.class', 'btn-success')
.and('contain', 'Changed')
Column 1 | Column 2 |
---|---|
Row 1: Cell 1 | Row 1: Cell 2 |
Row 2: Cell 1 | Row 2: Cell 2 |