|
| 1 | +class BasePage { |
| 2 | + visit(url = '/') { |
| 3 | + cy.visit(url); |
| 4 | + } |
| 5 | + |
| 6 | + getElement(selector) { |
| 7 | + return cy.get(selector); |
| 8 | + } |
| 9 | + |
| 10 | + hoverElement(selector) { |
| 11 | + return this.getElement(selector) |
| 12 | + .trigger('mouseover') |
| 13 | + .trigger('mouseenter'); |
| 14 | + } |
| 15 | + |
| 16 | + verifyElementIsVisible(selector) { |
| 17 | + return this.getElement(selector).should('be.visible'); |
| 18 | + } |
| 19 | + |
| 20 | + verifyElementHasAttribute(selector, attribute, value) { |
| 21 | + return this.getElement(selector).should('have.attr', attribute, value); |
| 22 | + } |
| 23 | + |
| 24 | + verifyHeadingExists(headingText) { |
| 25 | + return cy.contains('h1, h2, h3, h4, h5, h6', headingText).should('be.visible'); |
| 26 | + } |
| 27 | + |
| 28 | + verifyLink(href, text, { findByText = false } = {}) { |
| 29 | + if (findByText && text) { |
| 30 | + const chain = cy.contains('a', text).should('be.visible'); |
| 31 | + return href ? chain.and('have.attr', 'href', href) : chain; |
| 32 | + } |
| 33 | + const chain = cy.get(`a[href="${href}"]`).should('be.visible').and('have.attr', 'href', href); |
| 34 | + return text ? chain.and('contain', text) : chain; |
| 35 | + } |
| 36 | + |
| 37 | + verifyButtonLink(href, buttonText) { |
| 38 | + return this.verifyLink(href, buttonText, { findByText: true }); |
| 39 | + } |
| 40 | + |
| 41 | + verifyElementContainsText(selector, text) { |
| 42 | + return cy.contains(selector, text).should('exist'); |
| 43 | + } |
| 44 | + |
| 45 | + verifyImageVisible(altText) { |
| 46 | + return cy.get(`img[alt="${altText}"]`) |
| 47 | + .should('be.visible') |
| 48 | + .and('have.attr', 'src') |
| 49 | + .should('not.be.empty'); |
| 50 | + } |
| 51 | + |
| 52 | +} |
| 53 | + |
| 54 | +export default BasePage; |
0 commit comments