|
| 1 | +// *********************************************** |
| 2 | +// This example commands.js shows you how to |
| 3 | +// create various custom commands and overwrite |
| 4 | +// existing commands. |
| 5 | +// |
| 6 | +// For more comprehensive examples of custom |
| 7 | +// commands please read more here: |
| 8 | +// https://on.cypress.io/custom-commands |
| 9 | +// *********************************************** |
| 10 | +// |
| 11 | +// |
| 12 | +// -- This is a parent command -- |
| 13 | +// Cypress.Commands.add('login', (email, password) => { ... }) |
| 14 | +// |
| 15 | +// |
| 16 | +// -- This is a child command -- |
| 17 | +// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) |
| 18 | +// |
| 19 | +// |
| 20 | +// -- This is a dual command -- |
| 21 | +// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) |
| 22 | +// |
| 23 | +// |
| 24 | +// -- This will overwrite an existing command -- |
| 25 | +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) |
| 26 | + |
| 27 | +Cypress.Commands.add('ionSwipeToGoBack', (complete = false, selector = 'ion-router-outlet') => { |
| 28 | + const increment = complete ? 60 : 25; |
| 29 | + cy.get(selector) |
| 30 | + .first() |
| 31 | + .trigger('mousedown', 0, 275, { which: 1, force: true }) |
| 32 | + .trigger('mousemove', increment * 1, 275, { which: 1, force: true }) |
| 33 | + .wait(50) |
| 34 | + .trigger('mousemove', increment * 2, 275, { which: 1, force: true }) |
| 35 | + .wait(50) |
| 36 | + .trigger('mousemove', increment * 3, 275, { which: 1, force: true }) |
| 37 | + .wait(50) |
| 38 | + .trigger('mousemove', increment * 4, 275, { which: 1, force: true }) |
| 39 | + .wait(50) |
| 40 | + .trigger('mouseup', increment * 4, 275, { which: 1, force: true }); |
| 41 | + cy.wait(150); |
| 42 | +}); |
| 43 | + |
| 44 | +/** |
| 45 | + * getStack is a query because it has automatic |
| 46 | + * retries built in which will let us account for |
| 47 | + * async routing without having to use |
| 48 | + * arbitrary cy.wait calls. |
| 49 | + */ |
| 50 | +Cypress.Commands.addQuery('getStack', (selector) => { |
| 51 | + return () => { |
| 52 | + const el = cy.$$(selector); |
| 53 | + return Array.from(el.children()).map((el) => el.tagName.toLowerCase()); |
| 54 | + } |
| 55 | +}); |
| 56 | + |
| 57 | +Cypress.Commands.add('testStack', (selector, expected) => { |
| 58 | + cy.getStack(selector).should('deep.equal', expected); |
| 59 | +}); |
| 60 | + |
| 61 | +Cypress.Commands.add('testLifeCycle', (selector, expected) => { |
| 62 | + cy.get(`${selector} #ngOnInit`).invoke('text').should('equal', '1'); |
| 63 | + cy.get(`${selector} #ionViewWillEnter`).invoke('text').should('equal', expected.ionViewWillEnter.toString()); |
| 64 | + cy.get(`${selector} #ionViewDidEnter`).invoke('text').should('equal', expected.ionViewDidEnter.toString()); |
| 65 | + cy.get(`${selector} #ionViewWillLeave`).invoke('text').should('equal', expected.ionViewWillLeave.toString()); |
| 66 | + cy.get(`${selector} #ionViewDidLeave`).invoke('text').should('equal', expected.ionViewDidLeave.toString()); |
| 67 | +}); |
| 68 | + |
| 69 | +Cypress.Commands.add('ionPageVisible', (selector) => { |
| 70 | + cy.get(selector) |
| 71 | + .should('have.class', 'ion-page') |
| 72 | + .should('not.have.class', 'ion-page-hidden') |
| 73 | + .should('not.have.class', 'ion-page-invisible') |
| 74 | + .should('have.length', 1); |
| 75 | +}); |
| 76 | + |
| 77 | +Cypress.Commands.add('ionPageHidden', (selector) => { |
| 78 | + cy.get(selector).should('have.class', 'ion-page').should('have.class', 'ion-page-hidden').should('have.length', 1); |
| 79 | +}); |
| 80 | + |
| 81 | +Cypress.Commands.add('ionPageDoesNotExist', (selector) => { |
| 82 | + cy.get(selector).should('not.exist'); |
| 83 | +}); |
| 84 | + |
| 85 | +Cypress.Commands.add('ionTabClick', (tabText) => { |
| 86 | + // TODO FW-2790: Figure out how to get rid of wait. It's a workaround for flakiness in CI. |
| 87 | + cy.wait(250); |
| 88 | + cy.contains('ion-tab-button', tabText).click({ force: true }); |
| 89 | +}); |
0 commit comments