From 1448fa09a821db35228fdaff2492cf1d5afb125f Mon Sep 17 00:00:00 2001 From: mahima Date: Mon, 26 Sep 2022 14:37:14 +0545 Subject: [PATCH 1/4] add test spec for login odule --- cypress/e2e/auth/auth.cy.js | 152 +++++++++++++++++++++++++++++++ cypress/page_objects/login_PO.js | 37 ++++++++ cypress/support/commands.js | 28 +++++- utilites/helper.js | 19 ++++ 4 files changed, 235 insertions(+), 1 deletion(-) create mode 100644 cypress/e2e/auth/auth.cy.js create mode 100644 cypress/page_objects/login_PO.js create mode 100644 utilites/helper.js diff --git a/cypress/e2e/auth/auth.cy.js b/cypress/e2e/auth/auth.cy.js new file mode 100644 index 0000000..2de60d1 --- /dev/null +++ b/cypress/e2e/auth/auth.cy.js @@ -0,0 +1,152 @@ +const { getRandomEmail,getRandomString } = require("../../../utilites/helper"); +const loginPagePO = require("../../page_objects/login_PO"); + + +describe("authentication module", function () { + beforeEach(function () { + loginPagePO.visitLoginPage(); + }); + it("URL should be https://frontendbootcamp.proshore.eu/accounts/login", function () { + cy.url().should( + "eq", + "https://frontendbootcamp.proshore.eu/accounts/login" + ); + }); + it("verify valid login", function () { + cy.login(); + }); + + it(" should not be submit with empty details", function () { + loginPagePO.clickLogin(); + loginPagePO.elements.loginBtn().should("be.disabled"); + }); + + it("Verify the validation msg when login is attempted with less than 6 letter password", function () { + const randomGenerateEmail = getRandomEmail() + const randomGenerateName = getRandomString(3); + loginPagePO.typeEmail(randomGenerateEmail); + loginPagePO.typePassword(randomGenerateName); + loginPagePO.clickLogin(); + // loginPagePO.elements.loginError() + // .should("have.text","Password length must be at least 6 characters." ); + }); + it("Verify the login process with invalidLogin credentials ", function () { + const randomGenerateEmail = getRandomEmail(); + const randomGenerateName = getRandomString(); + // cy.log(randomGenerateName) + // cy.pause() + loginPagePO.typeEmail(randomGenerateEmail); + loginPagePO.typePassword(randomGenerateName); + loginPagePO.clickLogin(); + loginPagePO.verifyInvalidCredentialAlertMessage() + + }); + it("should visible the password", function () { + cy.login(); + cy.get("#showPassword").click(); + cy.get("#password").invoke("attr", "type").should("eq", "text"); + }); + it("It should not be submit with empty email address", function () { + const randomGenerateName = getRandomString(6); + loginPagePO.typePassword(randomGenerateName); + loginPagePO.clickLogin() + loginPagePO.elements.loginBtn().should("be.disabled"); + }); + it(" should not be submit with empty password", function () { + //perform + const randomGenerateEmail = getRandomEmail(); + loginPagePO.typeEmail(randomGenerateEmail); + loginPagePO.clickLogin() + loginPagePO.elements.loginBtn().should("be.disabled"); + }); + it("It should not be submit with incorrect password", function () { + const randomGenerateEmail = getRandomEmail(); + const randomGenerateName = getRandomString(); + loginPagePO.typeEmail(randomGenerateEmail); + loginPagePO.typePassword(randomGenerateName); + loginPagePO.clickLogin(); + // cy.get(".text-danger").should( + // "have.text", + // "Password length must be at least 6 characters." + // ); + }); + + it("It should not be submit with incorrect email address", function () { + const randomGenerateEmail = getRandomEmail(); + const randomGenerateName = getRandomString(7); + loginPagePO.typeEmail(randomGenerateEmail); + loginPagePO.typePassword(randomGenerateName); + loginPagePO.clickLogin(); + // cy.get(".alert-message").should( + // "have.text", + // "Please enter valid email or password." + // ); + }); + + it("clicked on forget password redirected to forget password page", function () { + //perform + cy.get(".forgot-password").click(); + cy.url().should( + "eq", + "https://frontendbootcamp.proshore.eu/accounts/password-forgot" + ); + }); + + it("URL of reset password should be https://frontendbootcamp.proshore.eu/accounts/password-forgot", function () { + //perform + cy.get(".forgot-password").click(); + cy.url().should( + "eq", + "https://frontendbootcamp.proshore.eu/accounts/password-forgot" + ); + }); + it(" should be submit with empty emailaddress", function () { + //perform + cy.get(".forgot-password").click(); + // cy.location('pathname').should('include','/accounts/password-forget') + cy.get(".form-control"); + cy.get(".btn-primary").click(); + + cy.on(".window:alert", (txt) => { + expect(txt).to.contains("Please fill out the field"); + }); + + it(" should be submit with incorrect email address in reset password page", function () { + //perform + cy.get(".forgot-password").click(); + // cy.location('pathname').should('include','/accounts/password-forget') + cy.get(".form-control.mt-1").type("mahimabh93@gmail.com{enter}"); + //perdict + cy.get(".alert-message").should( + "have.text", + "User with given email address not found" + ); + }); + it(" should be submit with correct email address in reset password page", function () { + //perform + cy.get(".forgot-password").click(); + // cy.location('pathname').should('include','/accounts/password-forget') + cy.get(".form-control").type("test@test.com{enter}"); + // cy.get(".btn-primary").click(); + cy.get(".form-heading-title").should("have.text", "Check your mail"); + }); + + it("Access admin portal via url", function () { + cy.url().should( + "eq", + "https://frontendbootcamp.proshore.eu/accounts/login" + ); + + cy.location("origin").then((URL) => { + //perform + expect(URL).to.eq("https://frontendbootcamp.proshore.eu"); + cy.visit(URL + "/tracker"); + cy.get(".form-heading-title").should("have.text", "Log in"); + cy.url().should( + "eq", + "https://frontendbootcamp.proshore.eu/accounts/login?next=/tracker" + ); + }); + }); + }); +}); diff --git a/cypress/page_objects/login_PO.js b/cypress/page_objects/login_PO.js new file mode 100644 index 0000000..84d2174 --- /dev/null +++ b/cypress/page_objects/login_PO.js @@ -0,0 +1,37 @@ +class login_PO { + elements = { + emailInput: () => cy.get('[data-cy="emailInputField"]').eq(0), + passwordInput: () => cy.get('[data-cy="emailInputField"]').eq(1), + loginBtn: () => cy.get('[data-cy="loginButton"]'), + loginError: () => cy.get(".alert-message"), + validationError: () => cy.get(".text-danger"), + }; + visitLoginPage() { + cy.visit("https://frontendbootcamp.proshore.eu/accounts/login"); + cy.url().should( + "eq", + "https://frontendbootcamp.proshore.eu/accounts/login" + ); + } + + typeEmail(email) { + this.elements.emailInput().type(email); + } + typePassword(password) { + this.elements.passwordInput().type(password); + } + clickLogin() { + this.elements.loginBtn().click({ force: true }); + } + + // errorMessage(){ + // this.elements.validationError() + // } + verifyInvalidCredentialAlertMessage() { + this.elements + .loginError() + .should("have.text", "Please enter valid email or password."); + } +} + +module.exports = new login_PO(); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 66ea16e..5f5a066 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -22,4 +22,30 @@ // // // -- This will overwrite an existing command -- -// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) \ No newline at end of file +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) +Cypress.Commands.add('login', () => { + cy.clearCookies() + cy.clearLocalStorage() + cy.get("#email").type("test@test.com"); + cy.get("#password").type("test123").type("{enter}") + // cy.get('form > .d-grid').click() + // cy.get('[data-cy="loginButton"]').click() + + }) + Cypress.Commands.add('invalidLogin', (emailaddress, password) => { + cy.clearCookies() + cy.clearLocalStorage() + cy.get("#email").type(emailaddress); + cy.get("#password").type(password).type("{enter}") + // cy.get('form > .d-grid').click() + // cy.get("[type='submit']").click() + + }) + Cypress.Commands.add('project', (name, clientname) => { + cy.clearCookies() + cy.clearLocalStorage() + cy.get('[data-cy="projectsSidebarButton"]').contains("Projects").click(); + cy.get('[data-cy="addProjectButton"]').click(); + + + }) \ No newline at end of file diff --git a/utilites/helper.js b/utilites/helper.js new file mode 100644 index 0000000..b687253 --- /dev/null +++ b/utilites/helper.js @@ -0,0 +1,19 @@ +function getRandomString(length=5){ + const characters = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + // const charactersLength = characters.length; + for (let i = 0; i < length; i++) { + result += characters.charAt( + Math.floor(Math.random() * characters.length) + )} + return result; + } + function getRandomEmail(){ + const randomString= getRandomString() + return randomString+'@gmail.com' + } + module.exports= { + getRandomString,getRandomEmail + } + \ No newline at end of file From f9432d7d4643304313d4186ba3450f748efab578 Mon Sep 17 00:00:00 2001 From: mahima Date: Tue, 27 Sep 2022 14:42:10 +0545 Subject: [PATCH 2/4] code refactor --- cypress/e2e/auth/auth.cy.js | 38 ++++++++++---------------------- cypress/page_objects/login_PO.js | 8 ++++--- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/cypress/e2e/auth/auth.cy.js b/cypress/e2e/auth/auth.cy.js index 2de60d1..fda365e 100644 --- a/cypress/e2e/auth/auth.cy.js +++ b/cypress/e2e/auth/auth.cy.js @@ -1,7 +1,6 @@ -const { getRandomEmail,getRandomString } = require("../../../utilites/helper"); +const { getRandomEmail, getRandomString } = require("../../../utilites/helper"); const loginPagePO = require("../../page_objects/login_PO"); - describe("authentication module", function () { beforeEach(function () { loginPagePO.visitLoginPage(); @@ -22,24 +21,24 @@ describe("authentication module", function () { }); it("Verify the validation msg when login is attempted with less than 6 letter password", function () { - const randomGenerateEmail = getRandomEmail() + const randomGenerateEmail = getRandomEmail(); const randomGenerateName = getRandomString(3); loginPagePO.typeEmail(randomGenerateEmail); loginPagePO.typePassword(randomGenerateName); loginPagePO.clickLogin(); - // loginPagePO.elements.loginError() - // .should("have.text","Password length must be at least 6 characters." ); + loginPagePO.verifyPasswordLengthErrorMessage(); + + }); it("Verify the login process with invalidLogin credentials ", function () { const randomGenerateEmail = getRandomEmail(); - const randomGenerateName = getRandomString(); + const randomGenerateName = getRandomString(7); // cy.log(randomGenerateName) // cy.pause() loginPagePO.typeEmail(randomGenerateEmail); loginPagePO.typePassword(randomGenerateName); loginPagePO.clickLogin(); - loginPagePO.verifyInvalidCredentialAlertMessage() - + loginPagePO.verifyInvalidCredentialAlertMessage(); }); it("should visible the password", function () { cy.login(); @@ -49,14 +48,13 @@ describe("authentication module", function () { it("It should not be submit with empty email address", function () { const randomGenerateName = getRandomString(6); loginPagePO.typePassword(randomGenerateName); - loginPagePO.clickLogin() + loginPagePO.clickLogin(); loginPagePO.elements.loginBtn().should("be.disabled"); }); it(" should not be submit with empty password", function () { - //perform const randomGenerateEmail = getRandomEmail(); loginPagePO.typeEmail(randomGenerateEmail); - loginPagePO.clickLogin() + loginPagePO.clickLogin(); loginPagePO.elements.loginBtn().should("be.disabled"); }); it("It should not be submit with incorrect password", function () { @@ -65,10 +63,7 @@ describe("authentication module", function () { loginPagePO.typeEmail(randomGenerateEmail); loginPagePO.typePassword(randomGenerateName); loginPagePO.clickLogin(); - // cy.get(".text-danger").should( - // "have.text", - // "Password length must be at least 6 characters." - // ); + loginPagePO.verifyPasswordLengthErrorMessage(); }); it("It should not be submit with incorrect email address", function () { @@ -77,14 +72,10 @@ describe("authentication module", function () { loginPagePO.typeEmail(randomGenerateEmail); loginPagePO.typePassword(randomGenerateName); loginPagePO.clickLogin(); - // cy.get(".alert-message").should( - // "have.text", - // "Please enter valid email or password." - // ); + loginPagePO.verifyInvalidCredentialAlertMessage(); }); it("clicked on forget password redirected to forget password page", function () { - //perform cy.get(".forgot-password").click(); cy.url().should( "eq", @@ -93,7 +84,6 @@ describe("authentication module", function () { }); it("URL of reset password should be https://frontendbootcamp.proshore.eu/accounts/password-forgot", function () { - //perform cy.get(".forgot-password").click(); cy.url().should( "eq", @@ -101,7 +91,6 @@ describe("authentication module", function () { ); }); it(" should be submit with empty emailaddress", function () { - //perform cy.get(".forgot-password").click(); // cy.location('pathname').should('include','/accounts/password-forget') cy.get(".form-control"); @@ -112,18 +101,16 @@ describe("authentication module", function () { }); it(" should be submit with incorrect email address in reset password page", function () { - //perform cy.get(".forgot-password").click(); // cy.location('pathname').should('include','/accounts/password-forget') cy.get(".form-control.mt-1").type("mahimabh93@gmail.com{enter}"); - //perdict + cy.get(".alert-message").should( "have.text", "User with given email address not found" ); }); it(" should be submit with correct email address in reset password page", function () { - //perform cy.get(".forgot-password").click(); // cy.location('pathname').should('include','/accounts/password-forget') cy.get(".form-control").type("test@test.com{enter}"); @@ -138,7 +125,6 @@ describe("authentication module", function () { ); cy.location("origin").then((URL) => { - //perform expect(URL).to.eq("https://frontendbootcamp.proshore.eu"); cy.visit(URL + "/tracker"); cy.get(".form-heading-title").should("have.text", "Log in"); diff --git a/cypress/page_objects/login_PO.js b/cypress/page_objects/login_PO.js index 84d2174..ea37a13 100644 --- a/cypress/page_objects/login_PO.js +++ b/cypress/page_objects/login_PO.js @@ -24,9 +24,11 @@ class login_PO { this.elements.loginBtn().click({ force: true }); } - // errorMessage(){ - // this.elements.validationError() - // } + verifyPasswordLengthErrorMessage() { + this.elements + .validationError() + .should("have.text", "Password length must be at least 6 characters."); + } verifyInvalidCredentialAlertMessage() { this.elements .loginError() From 03fac2291d07a48efb8b406ea41049b207b4afda Mon Sep 17 00:00:00 2001 From: mahima Date: Wed, 28 Sep 2022 14:34:00 +0545 Subject: [PATCH 3/4] refactor code --- cypress.config.js | 1 + cypress/e2e/auth/auth.cy.js | 122 +++++++++++++------------------ cypress/page_objects/login_PO.js | 2 +- cypress/support/commands.js | 27 ++----- utilites/helper.js | 36 ++++----- 5 files changed, 76 insertions(+), 112 deletions(-) diff --git a/cypress.config.js b/cypress.config.js index 97f47c4..08ff5bc 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -2,6 +2,7 @@ const { defineConfig } = require("cypress"); module.exports = defineConfig({ e2e: { + baseUrl: 'https://frontendbootcamp.proshore.eu/', setupNodeEvents(on, config) { // implement node event listeners here }, diff --git a/cypress/e2e/auth/auth.cy.js b/cypress/e2e/auth/auth.cy.js index fda365e..3c115f0 100644 --- a/cypress/e2e/auth/auth.cy.js +++ b/cypress/e2e/auth/auth.cy.js @@ -1,4 +1,5 @@ const { getRandomEmail, getRandomString } = require("../../../utilites/helper"); +const forgotPassword_PO = require("../../page_objects/forgotPassword_PO"); const loginPagePO = require("../../page_objects/login_PO"); describe("authentication module", function () { @@ -16,7 +17,7 @@ describe("authentication module", function () { }); it(" should not be submit with empty details", function () { - loginPagePO.clickLogin(); + loginPagePO.clickOnLoginButton(); loginPagePO.elements.loginBtn().should("be.disabled"); }); @@ -25,114 +26,93 @@ describe("authentication module", function () { const randomGenerateName = getRandomString(3); loginPagePO.typeEmail(randomGenerateEmail); loginPagePO.typePassword(randomGenerateName); - loginPagePO.clickLogin(); - loginPagePO.verifyPasswordLengthErrorMessage(); - - + loginPagePO.clickOnLoginButton(); + loginPagePO.verifyPasswordLengthErrorMessage(); }); it("Verify the login process with invalidLogin credentials ", function () { const randomGenerateEmail = getRandomEmail(); const randomGenerateName = getRandomString(7); - // cy.log(randomGenerateName) - // cy.pause() loginPagePO.typeEmail(randomGenerateEmail); loginPagePO.typePassword(randomGenerateName); - loginPagePO.clickLogin(); + loginPagePO.clickOnLoginButton(); loginPagePO.verifyInvalidCredentialAlertMessage(); }); - it("should visible the password", function () { - cy.login(); + it("Password should be visible by clicking the toggle_icon eye-slash", function () { + const randomGenerateName = getRandomString(5); + loginPagePO.typePassword(randomGenerateName); cy.get("#showPassword").click(); cy.get("#password").invoke("attr", "type").should("eq", "text"); }); it("It should not be submit with empty email address", function () { const randomGenerateName = getRandomString(6); loginPagePO.typePassword(randomGenerateName); - loginPagePO.clickLogin(); + loginPagePO.clickOnLoginButton(); loginPagePO.elements.loginBtn().should("be.disabled"); }); - it(" should not be submit with empty password", function () { + it("Should not be submit with empty password", function () { const randomGenerateEmail = getRandomEmail(); loginPagePO.typeEmail(randomGenerateEmail); - loginPagePO.clickLogin(); + loginPagePO.clickOnLoginButton(); loginPagePO.elements.loginBtn().should("be.disabled"); }); - it("It should not be submit with incorrect password", function () { - const randomGenerateEmail = getRandomEmail(); - const randomGenerateName = getRandomString(); - loginPagePO.typeEmail(randomGenerateEmail); + it("It should not be submit with correct email address and incorrect password", function () { + const randomGenerateName = getRandomString(7); + loginPagePO.typeEmail(Cypress.env("APP_EMAIL")); loginPagePO.typePassword(randomGenerateName); - loginPagePO.clickLogin(); - loginPagePO.verifyPasswordLengthErrorMessage(); + loginPagePO.clickOnLoginButton(); + loginPagePO.verifyInvalidCredentialAlertMessage(); }); - it("It should not be submit with incorrect email address", function () { + it("It should not be submit with incorrect email address and correct password", function () { const randomGenerateEmail = getRandomEmail(); - const randomGenerateName = getRandomString(7); loginPagePO.typeEmail(randomGenerateEmail); - loginPagePO.typePassword(randomGenerateName); - loginPagePO.clickLogin(); + loginPagePO.typePassword(Cypress.env("APP_PASSWORD")); + loginPagePO.clickOnLoginButton(); loginPagePO.verifyInvalidCredentialAlertMessage(); }); - it("clicked on forget password redirected to forget password page", function () { - cy.get(".forgot-password").click(); - cy.url().should( - "eq", - "https://frontendbootcamp.proshore.eu/accounts/password-forgot" - ); + forgotPassword_PO.visitForgotPasswordPage(); }); - it("URL of reset password should be https://frontendbootcamp.proshore.eu/accounts/password-forgot", function () { - cy.get(".forgot-password").click(); - cy.url().should( - "eq", - "https://frontendbootcamp.proshore.eu/accounts/password-forgot" - ); - }); it(" should be submit with empty emailaddress", function () { - cy.get(".forgot-password").click(); - // cy.location('pathname').should('include','/accounts/password-forget') - cy.get(".form-control"); - cy.get(".btn-primary").click(); + forgotPassword_PO.visitForgotPasswordPage(); + forgotPassword_PO.clickOnGetResetLink(); + // forgotPassword_PO.verifyEmptyCredentialAlertMessage(); - cy.on(".window:alert", (txt) => { - expect(txt).to.contains("Please fill out the field"); - }); + // cy.on(".window:alert", (txt) => { + // expect(txt).to.contains("Please fill out the field"); + }); - it(" should be submit with incorrect email address in reset password page", function () { - cy.get(".forgot-password").click(); - // cy.location('pathname').should('include','/accounts/password-forget') - cy.get(".form-control.mt-1").type("mahimabh93@gmail.com{enter}"); + it(" should be submit with incorrect email address in reset password page", function () { + forgotPassword_PO.visitForgotPasswordPage(); + const randomGenerateEmail = getRandomEmail(); + forgotPassword_PO.typeEmail(randomGenerateEmail); + forgotPassword_PO.clickOnGetResetLink(); + forgotPassword_PO.verifyInvalidCredentialAlertMessage(); + }); + it(" should be submit with correct email address in reset password page", function () { + forgotPassword_PO.visitForgotPasswordPage(); + forgotPassword_PO.typeEmail("test@test.com"); + forgotPassword_PO.clickOnGetResetLink(); + forgotPassword_PO.getResetLink(); - cy.get(".alert-message").should( - "have.text", - "User with given email address not found" - ); - }); - it(" should be submit with correct email address in reset password page", function () { - cy.get(".forgot-password").click(); - // cy.location('pathname').should('include','/accounts/password-forget') - cy.get(".form-control").type("test@test.com{enter}"); - // cy.get(".btn-primary").click(); - cy.get(".form-heading-title").should("have.text", "Check your mail"); - }); + // cy.get(".form-heading-title").should("have.text", "Check your mail"); + }); + + it("Access admin portal via url", function () { + cy.url().should( + "eq", + "https://frontendbootcamp.proshore.eu/accounts/login" + ); - it("Access admin portal via url", function () { + cy.location("origin").then((URL) => { + expect(URL).to.eq("https://frontendbootcamp.proshore.eu"); + cy.visit(URL + "/tracker"); + cy.get(".form-heading-title").should("have.text", "Log in"); cy.url().should( "eq", - "https://frontendbootcamp.proshore.eu/accounts/login" + "https://frontendbootcamp.proshore.eu/accounts/login?next=/tracker" ); - - cy.location("origin").then((URL) => { - expect(URL).to.eq("https://frontendbootcamp.proshore.eu"); - cy.visit(URL + "/tracker"); - cy.get(".form-heading-title").should("have.text", "Log in"); - cy.url().should( - "eq", - "https://frontendbootcamp.proshore.eu/accounts/login?next=/tracker" - ); - }); }); }); }); diff --git a/cypress/page_objects/login_PO.js b/cypress/page_objects/login_PO.js index ea37a13..4238a8a 100644 --- a/cypress/page_objects/login_PO.js +++ b/cypress/page_objects/login_PO.js @@ -20,7 +20,7 @@ class login_PO { typePassword(password) { this.elements.passwordInput().type(password); } - clickLogin() { + clickOnLoginButton() { this.elements.loginBtn().click({ force: true }); } diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 5f5a066..c7632eb 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -26,26 +26,9 @@ Cypress.Commands.add('login', () => { cy.clearCookies() cy.clearLocalStorage() - cy.get("#email").type("test@test.com"); - cy.get("#password").type("test123").type("{enter}") - // cy.get('form > .d-grid').click() - // cy.get('[data-cy="loginButton"]').click() - + cy.get("#email").type(Cypress.env("APP_EMAIL")) + cy.get("#password").type(Cypress.env("APP_PASSWORD")) + .type("{enter}") + cy.url().should("eq","https://frontendbootcamp.proshore.eu/tracker") }) - Cypress.Commands.add('invalidLogin', (emailaddress, password) => { - cy.clearCookies() - cy.clearLocalStorage() - cy.get("#email").type(emailaddress); - cy.get("#password").type(password).type("{enter}") - // cy.get('form > .d-grid').click() - // cy.get("[type='submit']").click() - - }) - Cypress.Commands.add('project', (name, clientname) => { - cy.clearCookies() - cy.clearLocalStorage() - cy.get('[data-cy="projectsSidebarButton"]').contains("Projects").click(); - cy.get('[data-cy="addProjectButton"]').click(); - - - }) \ No newline at end of file + \ No newline at end of file diff --git a/utilites/helper.js b/utilites/helper.js index b687253..37c98ce 100644 --- a/utilites/helper.js +++ b/utilites/helper.js @@ -1,19 +1,19 @@ -function getRandomString(length=5){ - const characters = +function getRandomString(length = 5) { + const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - let result = ""; - // const charactersLength = characters.length; - for (let i = 0; i < length; i++) { - result += characters.charAt( - Math.floor(Math.random() * characters.length) - )} - return result; - } - function getRandomEmail(){ - const randomString= getRandomString() - return randomString+'@gmail.com' - } - module.exports= { - getRandomString,getRandomEmail - } - \ No newline at end of file + let result = ""; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * characters.length)); + } + return result; +} + +function getRandomEmail() { + const randomString = getRandomString(); + return randomString + "@gmail.com"; +} + +module.exports = { + getRandomString, + getRandomEmail, +}; From c8467195664124dabedd6449f39d66530c334d95 Mon Sep 17 00:00:00 2001 From: mahima Date: Wed, 28 Sep 2022 14:34:56 +0545 Subject: [PATCH 4/4] refactor code --- cypress.env.json | 5 +++ cypress/page_objects/forgotPassword_PO.js | 38 +++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 cypress.env.json create mode 100644 cypress/page_objects/forgotPassword_PO.js diff --git a/cypress.env.json b/cypress.env.json new file mode 100644 index 0000000..470251b --- /dev/null +++ b/cypress.env.json @@ -0,0 +1,5 @@ +{ + "APP_EMAIL": "test@test.com", + "APP_PASSWORD": "test123" + } + \ No newline at end of file diff --git a/cypress/page_objects/forgotPassword_PO.js b/cypress/page_objects/forgotPassword_PO.js new file mode 100644 index 0000000..da3525f --- /dev/null +++ b/cypress/page_objects/forgotPassword_PO.js @@ -0,0 +1,38 @@ +class forgotPassword_PO { + elements = { + emailInput: () => cy.get("#email.form-control"), + getResetLinkButton: () => cy.get('[data-cy="forgetPasswordResetButton"]'), + loginError: () => cy.get(".alert-message"), + getResetLink: () => cy.get(".form-heading-title"), + validationError: () => cy.on(".window:alert"), + }; + visitForgotPasswordPage() { + cy.get(".forgot-password").click(); + cy.url().should( + "eq", + "https://frontendbootcamp.proshore.eu/accounts/password-forgot" + ); + } + + typeEmail(email) { + this.elements.emailInput().type(email); + } + clickOnGetResetLink() { + this.elements.getResetLinkButton().click(); + } + verifyInvalidCredentialAlertMessage() { + this.elements + .loginError() + .should("have.text", "User with given email address not found"); + } + getResetLink() { + this.elements.getResetLink().click(); + } + // verifyEmptyCredentialAlertMessage(){ + // this.elements.validationError. + // // on(".window:alert", (txt) => { + // should("contains","Please fill out the field"); + // } +} + +module.exports = new forgotPassword_PO();