I am writing a UI assertions test with cypress and I am seeing a lot of repeated chaining. Is there a way to abstract this out into a helper method for easier maintainability (and less code duplication)?
example code:
it('displays the table column headers', () => {
DivisionPage.divisionNameColumnHeader()
.should('be.visible')
.and('have.css', 'text-transform', 'capitalize')
.and('have.css', 'color', 'rgb(35, 40, 43)')
.and('have.css', 'background-color', 'rgb(195, 202, 206)')
.and('have.css', 'cursor', 'pointer')
.and('have.css', 'font-family', '"Open Sans"')
.and('have.css', 'position', 'sticky')
DivisionPage.teamsColumnHeader()
.should('be.visible')
.and('have.css', 'text-transform', 'capitalize')
.and('have.css', 'color', 'rgb(35, 40, 43)')
.and('have.css', 'background-color', 'rgb(212, 217, 220)')
.and('have.css', 'cursor', 'pointer')
.and('have.css', 'font-family', '"Open Sans"')
.and('have.css', 'position', 'sticky')
DivisionPage.playersColumnHeader()
.should('be.visible')
.and('have.css', 'text-transform', 'capitalize')
.and('have.css', 'color', 'rgb(35, 40, 43)')
.and('have.css', 'background-color', 'rgb(212, 217, 220)')
.and('have.css', 'cursor', 'pointer')
.and('have.css', 'font-family', '"Open Sans"')
.and('have.css', 'position', 'sticky')
})
Note that I am using page models so the DivisionPage.divisionNameColumnHeader() is equal to something like this: cy.get('[data-cy="division-name-column-header"]')