diff --git a/tests/cypress/integration/00_set_new_admin_console.spec.js b/tests/cypress/integration/00_set_new_admin_console.spec.js index 2d1f3e9548..33444d29b4 100644 --- a/tests/cypress/integration/00_set_new_admin_console.spec.js +++ b/tests/cypress/integration/00_set_new_admin_console.spec.js @@ -2,27 +2,24 @@ import LoginPage from '../support/pages/LoginPage.js' import WelcomePage from '../support/pages/WelcomePage.js' import OldClientPage from '../support/pages/admin_console/manage/clients/OldClientPage.js' -describe('Set up test', function () { +const loginPage = new LoginPage(); +const welcomePage = new WelcomePage(); +const oldClientPage = new OldClientPage(); - const loginPage = new LoginPage(); - const welcomePage = new WelcomePage(); - const oldClientPage = new OldClientPage(); - - describe('Set up test', function () { - beforeEach(function () { - cy.visit('http://localhost:8180/auth') - }) +describe("Set up test", function () { + beforeEach(function () { + cy.visit("http://localhost:8180/auth") + }) - it('Create admin user and adds admin console client', function () { - welcomePage - .createAdminUser() - .goToAdminConsole(); + it("Create admin user and adds admin console client", function () { + welcomePage + .createAdminUser() + .goToAdminConsole(); - loginPage.logIn(); + loginPage.logIn(); - oldClientPage - .goToClients() - .addNewAdminConsole(); - }); - }) - }) \ No newline at end of file + oldClientPage + .goToClients() + .addNewAdminConsole(); + }); +}) \ No newline at end of file diff --git a/tests/cypress/integration/client_scopes_test.spec.js b/tests/cypress/integration/client_scopes_test.spec.js index 37767662b0..88660894b9 100644 --- a/tests/cypress/integration/client_scopes_test.spec.js +++ b/tests/cypress/integration/client_scopes_test.spec.js @@ -4,17 +4,17 @@ import ListingPage from "../support/pages/admin_console/ListingPage.js"; import SidebarPage from "../support/pages/admin_console/SidebarPage.js"; import CreateClientScopePage from "../support/pages/admin_console/manage/client_scopes/CreateClientScopePage.js"; +let itemId = "client_scope_crud"; +const loginPage = new LoginPage(); +const masthead = new Masthead(); +const sidebarPage = new SidebarPage(); +const listingPage = new ListingPage(); +const createClientScopePage = new CreateClientScopePage(); + describe("Client Scopes test", function () { - let itemId = "client_scope_crud"; - const loginPage = new LoginPage(); - const masthead = new Masthead(); - const sidebarPage = new SidebarPage(); - const listingPage = new ListingPage(); - const createClientScopePage = new CreateClientScopePage(); describe("Client Scope creation", function () { beforeEach(function () { - cy.clearCookies(); cy.visit(""); loginPage.logIn(); sidebarPage.goToClientScopes(); @@ -48,7 +48,7 @@ describe("Client Scopes test", function () { .fillClientScopeData(itemId) .save(); - masthead.checkNotificationMessage('Client scope created'); + masthead.checkNotificationMessage("Client scope created"); sidebarPage.goToClientScopes(); @@ -57,7 +57,7 @@ describe("Client Scopes test", function () { .itemExist(itemId) .deleteItem(itemId); // There should be a confirmation pop-up - masthead.checkNotificationMessage('The client scope has been deleted'); + masthead.checkNotificationMessage("The client scope has been deleted"); listingPage // It is not refreshing after delete .itemExist(itemId, false); diff --git a/tests/cypress/integration/clients_test.spec.js b/tests/cypress/integration/clients_test.spec.js index 6f660daf34..b6d9a6382e 100644 --- a/tests/cypress/integration/clients_test.spec.js +++ b/tests/cypress/integration/clients_test.spec.js @@ -4,17 +4,17 @@ import ListingPage from "../support/pages/admin_console/ListingPage.js"; import SidebarPage from "../support/pages/admin_console/SidebarPage.js"; import CreateClientPage from "../support/pages/admin_console/manage/clients/CreateClientPage.js"; +let itemId = "client_crud"; +const loginPage = new LoginPage(); +const masthead = new Masthead(); +const sidebarPage = new SidebarPage(); +const listingPage = new ListingPage(); +const createClientPage = new CreateClientPage(); + describe("Clients test", function () { - let itemId = "client_crud"; - const loginPage = new LoginPage(); - const masthead = new Masthead(); - const sidebarPage = new SidebarPage(); - const listingPage = new ListingPage(); - const createClientPage = new CreateClientPage(); describe("Client creation", function () { beforeEach(function () { - cy.clearCookies(); cy.visit(""); loginPage.logIn(); sidebarPage.goToClients(); diff --git a/tests/cypress/integration/login_test.spec.js b/tests/cypress/integration/login_test.spec.js index 9995b748be..c2a0a14651 100644 --- a/tests/cypress/integration/login_test.spec.js +++ b/tests/cypress/integration/login_test.spec.js @@ -1,31 +1,32 @@ import LoginPage from "./../support/pages/LoginPage.js"; import Masthead from "./../support/pages/admin_console/Masthead.js"; +const username = "admin"; +const password = "admin"; + +const loginPage = new LoginPage(); +const masthead = new Masthead(); + describe("Logging In", function () { - const username = "admin"; - const password = "admin"; - const loginPage = new LoginPage(); - const masthead = new Masthead(); + beforeEach(function () { + cy.visit(""); + }); - describe("Login form submission", function () { - beforeEach(function () { - cy.visit(""); - }); + it("displays errors on wrong credentials", function () { + loginPage + .logIn("wrong", "user{enter}"); + + loginPage + .checkErrorMessage("Invalid username or password.") + .isLogInPage(); + }); - it("displays errors on login", function () { - loginPage - .logIn("wrong", "user{enter}") - .checkErrorMessage("Invalid username or password.") - .isLogInPage(); - }); + it("logs in", function () { + loginPage.logIn(username, password); - it("redirects to admin console on success", function () { - loginPage.logIn(username, password); + masthead.isAdminConsole(); - masthead.isAdminConsole(); - - cy.getCookie("KEYCLOAK_SESSION_LEGACY").should("exist"); - }); + cy.getCookie("KEYCLOAK_SESSION_LEGACY").should("exist"); }); }); diff --git a/tests/cypress/integration/masthead_test.spec.js b/tests/cypress/integration/masthead_test.spec.js index 9f0ac1ca88..3ba0851cfc 100644 --- a/tests/cypress/integration/masthead_test.spec.js +++ b/tests/cypress/integration/masthead_test.spec.js @@ -24,7 +24,6 @@ const goToAcctMgtTest = () => { describe("Masthead tests in desktop mode", () => { beforeEach(() => { - cy.clearCookies(); cy.visit(""); loginPage.logIn(); }); @@ -52,7 +51,6 @@ describe("Masthead tests in desktop mode", () => { describe("Masthead tests with kebab menu", () => { beforeEach(() => { - cy.clearCookies(); cy.visit(""); loginPage.logIn(); masthead.setMobileMode(true); diff --git a/tests/cypress/integration/realm_roles_test.spec.js b/tests/cypress/integration/realm_roles_test.spec.js index 70a50147f9..7fe938fcc3 100644 --- a/tests/cypress/integration/realm_roles_test.spec.js +++ b/tests/cypress/integration/realm_roles_test.spec.js @@ -5,18 +5,18 @@ import ListingPage from "../support/pages/admin_console/ListingPage.js"; import SidebarPage from "../support/pages/admin_console/SidebarPage.js"; import CreateRealmRolePage from "../support/pages/admin_console/manage/realm_roles/CreateRealmRolePage.js"; +let itemId = "realm_role_crud"; +const loginPage = new LoginPage(); +const masthead = new Masthead(); +const modalUtils = new ModalUtils(); +const sidebarPage = new SidebarPage(); +const listingPage = new ListingPage(); +const createRealmRolePage = new CreateRealmRolePage(); + describe("Realm roles test", function () { - let itemId = "realm_role_crud"; - const loginPage = new LoginPage(); - const masthead = new Masthead(); - const modalUtils = new ModalUtils(); - const sidebarPage = new SidebarPage(); - const listingPage = new ListingPage(); - const createRealmRolePage = new CreateRealmRolePage(); describe("Realm roles creation", function () { beforeEach(function () { - cy.clearCookies(); cy.visit(""); loginPage.logIn(); sidebarPage.goToRealmRoles(); diff --git a/tests/cypress/integration/realm_test.spec.js b/tests/cypress/integration/realm_test.spec.js index ebd16e05aa..667ceea815 100644 --- a/tests/cypress/integration/realm_test.spec.js +++ b/tests/cypress/integration/realm_test.spec.js @@ -3,15 +3,15 @@ import SidebarPage from "../support/pages/admin_console/SidebarPage.js"; import CreateRealmPage from "../support/pages/admin_console/CreateRealmPage.js"; import Masthead from "../support/pages/admin_console/Masthead.js"; +const masthead = new Masthead(); +const loginPage = new LoginPage(); +const sidebarPage = new SidebarPage(); +const createRealmPage = new CreateRealmPage(); + describe("Realms test", function () { - const loginPage = new LoginPage(); - const sidebarPage = new SidebarPage(); - const createRealmPage = new CreateRealmPage(); - const masthead = new Masthead(); describe("Realm creation", function () { beforeEach(function () { - cy.clearCookies(); cy.visit(""); loginPage.logIn(); }); diff --git a/tests/cypress/support/pages/LoginPage.js b/tests/cypress/support/pages/LoginPage.js index 1d52b4c9c6..6d065ad855 100644 --- a/tests/cypress/support/pages/LoginPage.js +++ b/tests/cypress/support/pages/LoginPage.js @@ -1,38 +1,45 @@ export default class LoginPage { - constructor() { - this.userNameInput = "#username"; - this.passwordInput = "#password"; - this.submitBtn = "#kc-login"; + constructor() { + this.userNameInput = "#username"; + this.passwordInput = "#password"; + this.submitBtn = "#kc-login"; - this.errorText = ".kc-feedback-text"; - } + this.errorText = ".kc-feedback-text"; + this.oldLoadContainer = "#loading"; + this.loadContainer = "div.keycloak__loading-container"; + } - isLogInPage() { - cy.get(this.userNameInput).should('exist'); - cy.url().should('include', '/auth'); + isLogInPage() { + cy.get(this.userNameInput).should("exist"); + cy.url().should("include", "/auth"); - return this; - } + return this; + } - logIn(userName = "admin", password = "admin") { + logIn(userName = "admin", password = "admin") { + cy.get(this.oldLoadContainer).should("not.exist"); + cy.get(this.loadContainer).should("not.exist"); + + cy.get("body").children().then((children) => { + if(children.length == 1) { cy.get(this.userNameInput).type(userName); cy.get(this.passwordInput).type(password); - + cy.get(this.submitBtn).click(); + } + }); + } - return this; - } + checkErrorIsDisplayed() { + cy.get(this.userDrpDwn).should("exist"); - checkErrorIsDisplayed() { - cy.get(this.userDrpDwn).should('exist'); + return this; + } - return this; - } + checkErrorMessage(message) { + cy.get(this.errorText).invoke("text").should("contain", message); - checkErrorMessage(message) { - cy.get(this.errorText).invoke('text').should('contain', message); - - return this; - } + return this; + } } \ No newline at end of file diff --git a/tests/package.json b/tests/package.json index f8e331db95..30412ac506 100644 --- a/tests/package.json +++ b/tests/package.json @@ -9,6 +9,6 @@ "author": "", "license": "ISC", "devDependencies": { - "cypress": "^5.6.0" + "cypress": "6.2.1" } }