From 8ade6979dfd85d80d8477bcecf9bf0396844235f Mon Sep 17 00:00:00 2001 From: Patrick Burns Date: Sun, 7 Apr 2024 16:09:22 -0500 Subject: [PATCH] more login page tests --- cypress/e2e/1-login.cy.js | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/cypress/e2e/1-login.cy.js b/cypress/e2e/1-login.cy.js index a7a849b2..61515bd9 100644 --- a/cypress/e2e/1-login.cy.js +++ b/cypress/e2e/1-login.cy.js @@ -19,4 +19,67 @@ describe("Login Test", () => { cy.url().should("include", "/dashboard"); cy.contains("Logout"); }); + + it("Should display an error message on failed login", () => { + // Define the username and password + const username = "m0abc"; + const password = "wrongpassword"; + + // Visit the login page + cy.visit("/index.php/user/login"); + + // Type the username and password into the input fields + cy.get('input[name="user_name"]').type(username); + cy.get('input[name="user_password"]').type(password); + + // Click the login button + cy.get('button[type="submit"]').click(); + + // Check if the login was successful + // This could be checking/ for a URL change, looking for a log out button, etc. + cy.url().should("include", "/login"); + + cy.get("body") + .contains("Incorrect username or password!") + .should("be.visible") + .and("have.class", "alert-danger"); + }); + + it("Should display an error message on empty fields", () => { + // Visit the login page + cy.visit("/index.php/user/login"); + + // Click the login button + cy.get('button[type="submit"]').click(); + + // Check if the login was successful + // This could be checking/ for a URL change, looking for a log out button, etc. + cy.url().should("include", "/login"); + + cy.get("body") + .contains(`The "Username" field is required.`) + .should("be.visible") + .parent() + .and("have.class", "alert-danger"); + + cy.get("body") + .contains(`The "Password" field is required.`) + .should("be.visible") + .parent() + .and("have.class", "alert-danger"); + }); + + it("Should display and open the forgot password page", () => { + // Visit the login page + cy.visit("/index.php/user/login"); + + // Click the "Forgot Password?" link + cy.get("a") + .contains("Forgot your password?") + .should("be.visible") + .click(); + + // Check if the correct page has been loaded by checking the URL + cy.url().should("include", "/forgot_password"); + }); });