Last active
September 1, 2020 12:33
-
-
Save shwetaneelsharma/a25581a6e6f0594c1902a144be209828 to your computer and use it in GitHub Desktop.
Cypress blog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Create a User through Drush | |
| * @param {*} user - String | |
| * @param {*} password - String | |
| */ | |
| Cypress.Commands.add('createUser', (user, pass, role) => { | |
| let drush = 'lando drush'; | |
| cy.exec(`${drush} user-create "${user}" --mail="${user}@example.com" --password="${pass}"`, | |
| //Code will continue to execute if the given user account data already exists | |
| { failOnNonZeroExit: false } | |
| ); | |
| cy.exec( | |
| `${drush} user-add-role "${role}" "${user}"`, | |
| { failOnNonZeroExit: false } | |
| ); | |
| cy.exec(`${drush} user-information "${user}"`); | |
| //we didn’t explicitly set the failOnNonZeroExit property here and the test will fail | |
| //if the given user account doesn’t exist. | |
| }); | |
| /** | |
| * Login with different user roles(considered: "administrator" and "editor") | |
| */ | |
| Cypress.Commands.add('login', (type) => { | |
| let perms = {}; | |
| switch (type) { | |
| case 'admin': | |
| perms = { | |
| name: Cypress.env('cyAdminUser'), | |
| pass: Cypress.env('cyAdminPassword'), | |
| }; | |
| break; | |
| case 'editor': | |
| perms = { | |
| name: Cypress.env('cyEditorUser'), | |
| pass: Cypress.env('cyEditorPassword'), | |
| }; | |
| break; | |
| } | |
| return cy.request({ | |
| method: 'POST', | |
| url: '/user/login', | |
| form: true, | |
| body: { | |
| ...perms, | |
| form_id: 'user_login_form', | |
| }, | |
| }); | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment