Forem Creator Cypress Setup (#14984)
* Adds loginCreator(); to commands.js and a creatorUser.js fixture * Update cypress/support/commands.js * Update cypress/support/commands.js * Removes redundant loginUser(); function * Remove superfluous back slashes from commands.js Co-authored-by: Suzanne Aitchison <suzanne@forem.com> Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
This commit is contained in:
parent
acbda16b8a
commit
df825e64fb
2 changed files with 45 additions and 0 deletions
6
cypress/fixtures/users/creatorUser.json
Normal file
6
cypress/fixtures/users/creatorUser.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "Creator",
|
||||
"username": "creator",
|
||||
"email": "creator@forem.local",
|
||||
"password": "password"
|
||||
}
|
||||
|
|
@ -117,6 +117,45 @@ Cypress.Commands.add('loginUser', ({ email, password }) => {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Logs in a creator with the given name, username, email, and password.
|
||||
*
|
||||
* @param credentials
|
||||
* @param credentials.name {string} A name
|
||||
* @param credentials.username {string} A username
|
||||
* @param credentials.email {string} An email address
|
||||
* @param credentials.password {string} A password
|
||||
*
|
||||
* @returns {Cypress.Chainable<Cypress.Response>} A cypress request for signing in a creator.
|
||||
*/
|
||||
Cypress.Commands.add('loginCreator', ({ name, username, email, password }) => {
|
||||
const encodedName = encodeURIComponent(name);
|
||||
const encodedUsername = encodeURIComponent(username);
|
||||
const encodedEmail = encodeURIComponent(email);
|
||||
const encodedPassword = encodeURIComponent(password);
|
||||
|
||||
function getLoginRequest() {
|
||||
return cy.request(
|
||||
'POST',
|
||||
'/users',
|
||||
`utf8=%E2%9C%93&user%5Bname%5D=${encodedName}&user%5Busername%5D=${encodedUsername}&user%5Bemail%5D=${encodedEmail}%40forem.local&user%5Bpassword%5D=${encodedPassword}&commit=Create+my+account`,
|
||||
);
|
||||
}
|
||||
|
||||
return getLoginRequest().then((response) => {
|
||||
if (response.status === 200) {
|
||||
return response;
|
||||
}
|
||||
|
||||
cy.log('Login failed. Attempting one more login.');
|
||||
|
||||
// If we have a login failure, try one more time.
|
||||
// This is to combat some flaky tests where the login fails occasionnally.
|
||||
return getLoginRequest();
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Gets an iframe with the given selector (or the first/only iframe if none is passed in),
|
||||
* waits for its content to be loaded, and returns a wrapped reference to the iframe body
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue