|
| 1 | +// <reference types="cypress" /> |
| 2 | +// *********************************************** |
| 3 | +// This example commands.ts shows you how to |
| 4 | +// create various custom commands and overwrite |
| 5 | +// existing commands. |
| 6 | +// |
| 7 | +// For more comprehensive examples of custom |
| 8 | +// commands please read more here: |
| 9 | +// https://on.cypress.io/custom-commands |
| 10 | +// *********************************************** |
| 11 | +// |
| 12 | +// |
| 13 | +// -- This is a parent command -- |
| 14 | +// Cypress.Commands.add('login', (email, password) => { ... }) |
| 15 | +// |
| 16 | +// |
| 17 | +// -- This is a child command -- |
| 18 | +// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) |
| 19 | +// |
| 20 | +// |
| 21 | +// -- This is a dual command -- |
| 22 | +// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) |
| 23 | +// |
| 24 | +// |
| 25 | +// -- This will overwrite an existing command -- |
| 26 | +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) |
| 27 | +// |
| 28 | + |
| 29 | +Cypress.Commands.add('login', (path) => { |
| 30 | + cy.visit('/'); |
| 31 | + |
| 32 | + cy.intercept({ |
| 33 | + method: 'GET', |
| 34 | + url: '/admin/users/me', |
| 35 | + }).as('sessionCheck'); |
| 36 | + |
| 37 | + cy.intercept({ |
| 38 | + method: 'GET', |
| 39 | + url: '/admin/init', |
| 40 | + }).as('adminInit'); |
| 41 | + |
| 42 | + // Wait for the initial request to complete. |
| 43 | + cy.wait('@adminInit').its('response.statusCode').should('equal', 200); |
| 44 | + |
| 45 | + // Wait for the form to render. |
| 46 | + // eslint-disable-next-line cypress/no-unnecessary-waiting |
| 47 | + cy.wait(1000); |
| 48 | + |
| 49 | + cy.get('body').then(($body) => { |
| 50 | + // Login |
| 51 | + if ($body.text().includes('Log in to your Strapi account')) { |
| 52 | + cy.get('input[name="email"]').type('johndoe@example.com'); |
| 53 | + cy.get('input[name="password"]').type('Abc12345678'); |
| 54 | + cy.get('button[type="submit"]').click(); |
| 55 | + cy.wait('@sessionCheck').its('response.statusCode').should('equal', 200); |
| 56 | + |
| 57 | + // Sometimes the page hangs after logging in. |
| 58 | + // If this happens we reload the page and log in again. |
| 59 | + cy.reload(); |
| 60 | + cy.get('body').then(($b) => { |
| 61 | + if ($b.text().includes('Log in to your Strapi account')) { |
| 62 | + cy.login(); |
| 63 | + } |
| 64 | + }); |
| 65 | + } |
| 66 | + // Register |
| 67 | + if ($body.text().includes('Credentials are only used to authenticate in Strapi')) { |
| 68 | + cy.get('input[name="firstname"]').type('John'); |
| 69 | + cy.get('input[name="email"]').type('johndoe@example.com'); |
| 70 | + cy.get('input[name="password"]').type('Abc12345678'); |
| 71 | + cy.get('input[name="confirmPassword"]').type('Abc12345678'); |
| 72 | + cy.get('button[type="submit"]').click(); |
| 73 | + cy.wait('@sessionCheck').its('response.statusCode').should('equal', 200); |
| 74 | + } |
| 75 | + }); |
| 76 | +}); |
| 77 | + |
| 78 | +Cypress.Commands.add('navigateToInterface', (path) => { |
| 79 | + cy.intercept({ |
| 80 | + method: 'GET', |
| 81 | + url: '/config-sync/diff', |
| 82 | + }).as('getConfigDiff'); |
| 83 | + |
| 84 | + cy.get('a[href="/admin/settings"]').click(); |
| 85 | + cy.get('a[href="/admin/settings/config-sync"]').click(); |
| 86 | + |
| 87 | + cy.wait('@getConfigDiff').its('response.statusCode').should('equal', 200); |
| 88 | +}); |
| 89 | + |
| 90 | + |
| 91 | +Cypress.Commands.add('initialExport', (path) => { |
| 92 | + cy.intercept({ |
| 93 | + method: 'POST', |
| 94 | + url: '/config-sync/export', |
| 95 | + }).as('exportConfig'); |
| 96 | + |
| 97 | + cy.get('button').contains('Make the initial export').click(); |
| 98 | + cy.get('button').contains('Yes, export').click(); |
| 99 | + |
| 100 | + cy.wait('@exportConfig').its('response.statusCode').should('equal', 200); |
| 101 | + |
| 102 | + cy.contains('Config was successfully exported to config/sync/.'); |
| 103 | +}); |
| 104 | + |
| 105 | +Cypress.Commands.add('makeConfigChanges', (path) => { |
| 106 | + // Change a setting in the UP advanced settings |
| 107 | + cy.intercept({ |
| 108 | + method: 'PUT', |
| 109 | + url: '/users-permissions/advanced', |
| 110 | + }).as('saveUpAdvanced'); |
| 111 | + cy.get('a[href="/admin/settings/users-permissions/advanced-settings"]').click(); |
| 112 | + cy.get('input[name="unique_email"').click(); |
| 113 | + cy.get('button[type="submit"]').click(); |
| 114 | + cy.wait('@saveUpAdvanced').its('response.statusCode').should('equal', 200); |
| 115 | + |
| 116 | + // Change a setting in the media library settings |
| 117 | + cy.intercept({ |
| 118 | + method: 'PUT', |
| 119 | + url: '/upload/settings', |
| 120 | + }).as('saveMediaLibrarySettings'); |
| 121 | + cy.get('a[href="/admin/settings/media-library"]').click(); |
| 122 | + cy.get('input[name="responsiveDimensions"').click(); |
| 123 | + cy.get('button[type="submit"]').click(); |
| 124 | + cy.wait('@saveMediaLibrarySettings').its('response.statusCode').should('equal', 200); |
| 125 | + |
| 126 | + // Change a setting in the email templates |
| 127 | + cy.intercept({ |
| 128 | + method: 'PUT', |
| 129 | + url: '/users-permissions/email-templates', |
| 130 | + }).as('saveUpEmailTemplates'); |
| 131 | + cy.get('a[href="/admin/settings/users-permissions/email-templates"]').click(); |
| 132 | + cy.get('tbody tr').contains('Reset password').click(); |
| 133 | + cy.get('input[name="options.response_email"]').clear(); |
| 134 | + cy.get('input[name="options.response_email"]').type(`${Math.random().toString(36).substring(2, 15)}@example.com`); |
| 135 | + cy.get('button[type="submit"]').click(); |
| 136 | + cy.wait('@saveUpEmailTemplates').its('response.statusCode').should('equal', 200); |
| 137 | +}); |
0 commit comments