Skip to content

Commit

Permalink
test: Refactor E2E tests towards greater maintainability and robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-frak committed Jul 20, 2024
1 parent 07521f5 commit 9b8b16c
Show file tree
Hide file tree
Showing 18 changed files with 571 additions and 244 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
working-directory: docker/e2e
# Video recording turned off due to free GitHub CI runners seemingly not being powerful enough for it.
# Headed Chrome used to minimize issues with tests failing for no reason.
run: npx cypress run --headed --browser chrome --config video=false
run: npx cypress run --headed --browser electron --config video=false

- name: Archive videos
if: always()
Expand Down
1 change: 1 addition & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
environment:
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin
KC_LOG_LEVEL: DEBUG
DB_VENDOR: h2
ports:
- "8024:8080"
Expand Down
37 changes: 37 additions & 0 deletions docker/e2e/cypress/e2e/accountDetailsPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class AccountDetailsPage {

/**
* @param {Keycloak} keycloak
*/
constructor(keycloak) {
this.keycloak = keycloak;
}

elements = {
emailInput: () => cy.get('#email'),
firstNameInput: () => cy.get('#firstName'),
lastNameInput: () => cy.get('#lastName'),
saveBtn: () => cy.get('button').contains('Save')
}

visit() {
cy.intercept('GET', '/realms/master/account/**')
.as("accountDetails");
cy.visit('/realms/master/account');
cy.wait('@accountDetails');
}

configurePersonalInfo(email, firstName, lastName) {
this.elements.emailInput().clear();
this.elements.emailInput().type(email);
this.elements.firstNameInput().clear().type(firstName);
this.elements.lastNameInput().clear().type(lastName);

cy.intercept('POST', '/realms/master/account/**')
.as("saveAccountDetails");
this.elements.saveBtn().click();
cy.wait("@saveAccountDetails");
}
}

module.exports = AccountDetailsPage;
21 changes: 21 additions & 0 deletions docker/e2e/cypress/e2e/forgotPasswordPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class ForgotPasswordPage {
elements = {
userNameInput: () => cy.get('#username'),
submitBtn: () => cy.get('input[type=submit]')
}

visit() {
cy.visit('/realms/master/login-actions/reset-credentials');
}

triggerPasswordReset(userEmail) {
this.elements.userNameInput().clear().type(userEmail);
this.elements.submitBtn().click();
cy.get('body').should('contain.text',
'You should receive an email shortly with further instructions.');
cy.mhGetMailsBySubject('Reset password')
.should('have.length', 1);
}
}

module.exports = ForgotPasswordPage;
23 changes: 23 additions & 0 deletions docker/e2e/cypress/e2e/keycloak.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Keycloak {

elements = {
userDropdown: () => cy.get('#user-dropdown'),
notification: () => cy.get('.pf-c-alert__title'),
accountDropdown: () => cy.get('[data-testid="options"]')
}

signOutViaUIAndClearCache() {
this.elements.userDropdown().click()
cy.get('#sign-out').get('a').contains('Sign out').click({force: true});

cy.clearAllCookies();
cy.clearAllLocalStorage();
cy.clearAllSessionStorage();
}

assertIsLoggedInAsUser(userFirstName, userLastName) {
this.elements.accountDropdown().should('contain', userFirstName + ' ' + userLastName);
}
}

module.exports = Keycloak;
29 changes: 29 additions & 0 deletions docker/e2e/cypress/e2e/loginPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class LoginPage {

elements = {
usernameField: () => cy.get('#username'),
passwordField: () => cy.get('#password'),
logInBtn: () => cy.get('#kc-login'),
forgotPasswordBtn: () => cy.get("a").contains("Forgot Password?")
}

visitForAdmin() {
cy.visit('/admin');
}

visitForUser() {
cy.visit('/realms/master/account');
}

logIn(login, password) {
this.elements.usernameField().type(login);
this.elements.passwordField().type(password);

cy.intercept('POST', '/realms/master/login-actions/authenticate*')
.as("loginSubmit");
this.elements.logInBtn().click();
cy.wait("@loginSubmit");
}
}

module.exports = LoginPage;
Loading

0 comments on commit 9b8b16c

Please sign in to comment.