From 71a41694d929397fa4ba73726f36dde67e98746c Mon Sep 17 00:00:00 2001 From: Aboullos <61687012+Aboullos@users.noreply.github.com> Date: Mon, 25 Jan 2021 18:17:59 +0100 Subject: [PATCH] Modify CRUD tests (#325) --- .../integration/client_scopes_test.spec.js | 58 ++++++++----------- .../cypress/integration/clients_test.spec.js | 38 +++++------- .../cypress/integration/masthead_test.spec.js | 2 + .../integration/realm_roles_test.spec.js | 42 ++++++-------- tests/cypress/integration/realm_test.spec.js | 8 +-- .../pages/admin_console/ListingPage.js | 2 +- 6 files changed, 62 insertions(+), 88 deletions(-) diff --git a/tests/cypress/integration/client_scopes_test.spec.js b/tests/cypress/integration/client_scopes_test.spec.js index 966c073142..37767662b0 100644 --- a/tests/cypress/integration/client_scopes_test.spec.js +++ b/tests/cypress/integration/client_scopes_test.spec.js @@ -5,7 +5,7 @@ import SidebarPage from "../support/pages/admin_console/SidebarPage.js"; import CreateClientScopePage from "../support/pages/admin_console/manage/client_scopes/CreateClientScopePage.js"; describe("Client Scopes test", function () { - const itemId = "client_scope_1"; + let itemId = "client_scope_crud"; const loginPage = new LoginPage(); const masthead = new Masthead(); const sidebarPage = new SidebarPage(); @@ -14,14 +14,13 @@ describe("Client Scopes test", function () { describe("Client Scope creation", function () { beforeEach(function () { + cy.clearCookies(); cy.visit(""); + loginPage.logIn(); + sidebarPage.goToClientScopes(); }); it("should fail creating client scope", function () { - loginPage.logIn(); - - sidebarPage.goToClientScopes(); - listingPage.goToCreateItem(); createClientScopePage.save().checkClientNameRequiredMessage(); @@ -37,38 +36,31 @@ describe("Client Scopes test", function () { ); }); - it("should create client scope", function () { - loginPage.logIn(); + it('Client scope CRUD test',async function () { + itemId += "_" + (Math.random() + 1).toString(36).substring(7); + + // Create + listingPage + .itemExist(itemId, false) + .goToCreateItem(); + + createClientScopePage + .fillClientScopeData(itemId) + .save(); + + masthead.checkNotificationMessage('Client scope created'); sidebarPage.goToClientScopes(); - listingPage.itemExist(itemId, false).goToCreateItem(); + // Delete + listingPage + .itemExist(itemId) + .deleteItem(itemId); // There should be a confirmation pop-up - createClientScopePage.fillClientScopeData(itemId).save(); + masthead.checkNotificationMessage('The client scope has been deleted'); - masthead.checkNotificationMessage("Client scope created"); - - sidebarPage.goToClientScopes(); - - listingPage.itemExist(itemId).searchItem(itemId).itemExist(itemId); + listingPage // It is not refreshing after delete + .itemExist(itemId, false); }); }); - - describe("Client scope elimination", function () { - beforeEach(function () { - cy.visit(""); - }); - - it("should delete client scope", function () { - loginPage.logIn(); - - sidebarPage.goToClientScopes(); - - listingPage.itemExist(itemId).deleteItem(itemId); // There should be a confirmation pop-up - - masthead.checkNotificationMessage("The client scope has been deleted"); - - listingPage.itemExist(itemId, false); - }); - }); -}); +}) \ No newline at end of file diff --git a/tests/cypress/integration/clients_test.spec.js b/tests/cypress/integration/clients_test.spec.js index b734f4ef6a..6f660daf34 100644 --- a/tests/cypress/integration/clients_test.spec.js +++ b/tests/cypress/integration/clients_test.spec.js @@ -5,7 +5,7 @@ import SidebarPage from "../support/pages/admin_console/SidebarPage.js"; import CreateClientPage from "../support/pages/admin_console/manage/clients/CreateClientPage.js"; describe("Clients test", function () { - const itemId = "client_1"; + let itemId = "client_crud"; const loginPage = new LoginPage(); const masthead = new Masthead(); const sidebarPage = new SidebarPage(); @@ -14,14 +14,13 @@ describe("Clients test", function () { describe("Client creation", function () { beforeEach(function () { + cy.clearCookies(); cy.visit(""); + loginPage.logIn(); + sidebarPage.goToClients(); }); it("should fail creating client", function () { - loginPage.logIn(); - - sidebarPage.goToClients(); - listingPage.goToCreateItem(); createClientPage @@ -50,11 +49,10 @@ describe("Clients test", function () { ); }); - it("should create client", function () { - loginPage.logIn(); - - sidebarPage.goToClients(); - + it("Client CRUD test", function () { + itemId += "_" + (Math.random() + 1).toString(36).substring(7); + + // Create listingPage.itemExist(itemId, false).goToCreateItem(); createClientPage @@ -67,21 +65,13 @@ describe("Clients test", function () { sidebarPage.goToClients(); - listingPage.itemExist(itemId).searchItem(itemId).itemExist(itemId); - }); - }); + listingPage + .searchItem(itemId) + .itemExist(itemId); - describe("Client elimination", function () { - beforeEach(function () { - cy.visit(""); - }); - - it("should delete client", function () { - loginPage.logIn(); - - sidebarPage.goToClients(); - - listingPage.itemExist(itemId).deleteItem(itemId); // There should be a confirmation pop-up + // Delete + listingPage + .deleteItem(itemId); // There should be a confirmation pop-up masthead.checkNotificationMessage("The client has been deleted"); diff --git a/tests/cypress/integration/masthead_test.spec.js b/tests/cypress/integration/masthead_test.spec.js index 3ba0851cfc..9f0ac1ca88 100644 --- a/tests/cypress/integration/masthead_test.spec.js +++ b/tests/cypress/integration/masthead_test.spec.js @@ -24,6 +24,7 @@ const goToAcctMgtTest = () => { describe("Masthead tests in desktop mode", () => { beforeEach(() => { + cy.clearCookies(); cy.visit(""); loginPage.logIn(); }); @@ -51,6 +52,7 @@ 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 fc9ec921df..70a50147f9 100644 --- a/tests/cypress/integration/realm_roles_test.spec.js +++ b/tests/cypress/integration/realm_roles_test.spec.js @@ -6,7 +6,7 @@ import SidebarPage from "../support/pages/admin_console/SidebarPage.js"; import CreateRealmRolePage from "../support/pages/admin_console/manage/realm_roles/CreateRealmRolePage.js"; describe("Realm roles test", function () { - const itemId = "realm_role_1"; + let itemId = "realm_role_crud"; const loginPage = new LoginPage(); const masthead = new Masthead(); const modalUtils = new ModalUtils(); @@ -16,14 +16,13 @@ describe("Realm roles test", function () { describe("Realm roles creation", function () { beforeEach(function () { + cy.clearCookies(); cy.visit(""); + loginPage.logIn(); + sidebarPage.goToRealmRoles(); }); it("should fail creating realm role", function () { - loginPage.logIn(); - - sidebarPage.goToRealmRoles(); - listingPage.goToCreateItem(); createRealmRolePage.save().checkRealmRoleNameRequiredMessage(); @@ -36,12 +35,13 @@ describe("Realm roles test", function () { ); }); - it("should create realm role", function () { - loginPage.logIn(); + it("Realm role CRUD test", function () { + itemId += "_" + (Math.random() + 1).toString(36).substring(7); - sidebarPage.goToRealmRoles(); - - listingPage.itemExist(itemId, false).goToCreateItem(); + // Create + listingPage + .itemExist(itemId, false) + .goToCreateItem(); createRealmRolePage.fillRealmRoleData(itemId).save(); @@ -49,21 +49,15 @@ describe("Realm roles test", function () { sidebarPage.goToRealmRoles(); - listingPage.itemExist(itemId).searchItem(itemId).itemExist(itemId); - }); - }); + listingPage + .searchItem(itemId) + .itemExist(itemId); - describe("Realm roles elimination", function () { - beforeEach(function () { - cy.visit(""); - }); - - it("should delete realm role", function () { - loginPage.logIn(); - - sidebarPage.goToRealmRoles(); - - listingPage.itemExist(itemId).deleteItem(itemId); + // Update + + // Delete + listingPage + .deleteItem(itemId); modalUtils.checkModalTitle("Delete role?").confirmModal(); diff --git a/tests/cypress/integration/realm_test.spec.js b/tests/cypress/integration/realm_test.spec.js index 5e9c0947f4..ebd16e05aa 100644 --- a/tests/cypress/integration/realm_test.spec.js +++ b/tests/cypress/integration/realm_test.spec.js @@ -11,12 +11,12 @@ describe("Realms test", function () { describe("Realm creation", function () { beforeEach(function () { + cy.clearCookies(); cy.visit(""); + loginPage.logIn(); }); it("should fail creating Master realm", function () { - loginPage.logIn(); - sidebarPage.goToCreateRealm(); createRealmPage.fillRealmName("master").createRealm(); @@ -26,8 +26,6 @@ describe("Realms test", function () { }); it("should create Test realm", function () { - loginPage.logIn(); - sidebarPage.goToCreateRealm(); createRealmPage.fillRealmName("Test").createRealm(); @@ -35,8 +33,6 @@ describe("Realms test", function () { }); it("should change to Test realm", function () { - loginPage.logIn(); - sidebarPage.getCurrentRealm().should("eq", "Master"); sidebarPage.goToRealm("Test").getCurrentRealm().should("eq", "Test"); diff --git a/tests/cypress/support/pages/admin_console/ListingPage.js b/tests/cypress/support/pages/admin_console/ListingPage.js index 05085ade9b..df4bc09409 100644 --- a/tests/cypress/support/pages/admin_console/ListingPage.js +++ b/tests/cypress/support/pages/admin_console/ListingPage.js @@ -2,7 +2,7 @@ export default class ListingPage { constructor() { this.searchInput = '.pf-c-toolbar__item [type="search"]'; - this.itemsRows = '.pf-c-page__main-section tbody > tr'; + this.itemsRows = '.pf-c-page__main-section table'; this.itemRowDrpDwn = '.pf-c-dropdown > button'; this.exportBtn = '[role="menuitem"]:nth-child(1)'; this.deleteBtn = '[role="menuitem"]:nth-child(2)';