From db63cdd61c6394fd7a708c7cba71ce53d8c75446 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Mon, 24 Jan 2022 15:17:55 +0100 Subject: [PATCH] Removed waits from realm test (#1906) --- ...ealm_settings_client_policies_test.spec.ts | 26 +++++++---- ...ealm_settings_client_profiles_test.spec.ts | 17 ++++--- cypress/integration/realm_test.spec.ts | 29 ++++++++++-- .../realm_settings/RealmSettingsPage.ts | 45 +++++++++++-------- src/realm-settings/messages.ts | 3 +- 5 files changed, 81 insertions(+), 39 deletions(-) diff --git a/cypress/integration/realm_settings_client_policies_test.spec.ts b/cypress/integration/realm_settings_client_policies_test.spec.ts index d8414f4021..6b472ce68a 100644 --- a/cypress/integration/realm_settings_client_policies_test.spec.ts +++ b/cypress/integration/realm_settings_client_policies_test.spec.ts @@ -1,30 +1,35 @@ import SidebarPage from "../support/pages/admin_console/SidebarPage"; import LoginPage from "../support/pages/LoginPage"; import RealmSettingsPage from "../support/pages/admin_console/manage/realm_settings/RealmSettingsPage"; -import { keycloakBefore } from "../support/util/keycloak_hooks"; +import { + keycloakBefore, + keycloakBeforeEach, +} from "../support/util/keycloak_hooks"; import AdminClient from "../support/util/AdminClient"; const loginPage = new LoginPage(); const sidebarPage = new SidebarPage(); -const realmSettingsPage = new RealmSettingsPage(); describe("Realm settings client policies tab tests", () => { const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7); + const realmSettingsPage = new RealmSettingsPage(realmName); beforeEach(() => { - keycloakBefore(); - loginPage.logIn(); + keycloakBeforeEach(); + sidebarPage.goToRealm(realmName); sidebarPage.goToRealmSettings(); cy.findByTestId("rs-clientPolicies-tab").click(); cy.findByTestId("rs-policies-clientPolicies-tab").click(); }); - before(async () => { - await new AdminClient().createRealm(realmName); + before(() => { + keycloakBefore(); + new AdminClient().createRealm(realmName); + loginPage.logIn(); }); - after(async () => { - await new AdminClient().deleteRealm(realmName); + after(() => { + new AdminClient().deleteRealm(realmName); }); it("Go to client policies tab", () => { @@ -96,14 +101,17 @@ describe("Realm settings client policies tab tests", () => { }); it("Should not create duplicate client profile", () => { + const url = `/auth/admin/realms/${realmName}/client-policies/policies`; + cy.intercept("PUT", url).as("save"); realmSettingsPage.shouldCompleteAndCreateNewClientPolicyFromEmptyState(); + cy.wait("@save"); sidebarPage.goToRealmSettings(); cy.findByTestId("rs-clientPolicies-tab").click(); cy.findByTestId("rs-policies-clientPolicies-tab").click(); realmSettingsPage.shouldCompleteAndCreateNewClientPolicy(); + cy.wait("@save"); realmSettingsPage.shouldNotCreateDuplicateClientPolicy(); - cy.wait(2000); sidebarPage.goToRealmSettings(); cy.findByTestId("rs-clientPolicies-tab").click(); cy.findByTestId("rs-policies-clientPolicies-tab").click(); diff --git a/cypress/integration/realm_settings_client_profiles_test.spec.ts b/cypress/integration/realm_settings_client_profiles_test.spec.ts index 1a4d61dfae..3ca8d53a1f 100644 --- a/cypress/integration/realm_settings_client_profiles_test.spec.ts +++ b/cypress/integration/realm_settings_client_profiles_test.spec.ts @@ -1,26 +1,31 @@ import SidebarPage from "../support/pages/admin_console/SidebarPage"; import LoginPage from "../support/pages/LoginPage"; import RealmSettingsPage from "../support/pages/admin_console/manage/realm_settings/RealmSettingsPage"; -import { keycloakBefore } from "../support/util/keycloak_hooks"; +import { + keycloakBefore, + keycloakBeforeEach, +} from "../support/util/keycloak_hooks"; import AdminClient from "../support/util/AdminClient"; const loginPage = new LoginPage(); const sidebarPage = new SidebarPage(); -const realmSettingsPage = new RealmSettingsPage(); describe("Realm settings client profiles tab tests", () => { const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7); + const realmSettingsPage = new RealmSettingsPage(realmName); beforeEach(() => { - keycloakBefore(); - loginPage.logIn(); + keycloakBeforeEach(); + sidebarPage.goToRealm(realmName); sidebarPage.goToRealmSettings(); cy.findByTestId("rs-clientPolicies-tab").click(); cy.findByTestId("rs-policies-clientProfiles-tab").click(); }); - before(async () => { - await new AdminClient().createRealm(realmName); + before(() => { + keycloakBefore(); + new AdminClient().createRealm(realmName); + loginPage.logIn(); }); after(async () => { diff --git a/cypress/integration/realm_test.spec.ts b/cypress/integration/realm_test.spec.ts index fc3d0f57fb..8a2e8d9034 100644 --- a/cypress/integration/realm_test.spec.ts +++ b/cypress/integration/realm_test.spec.ts @@ -3,6 +3,7 @@ import SidebarPage from "../support/pages/admin_console/SidebarPage"; import CreateRealmPage from "../support/pages/admin_console/CreateRealmPage"; import Masthead from "../support/pages/admin_console/Masthead"; import AdminClient from "../support/util/AdminClient"; +import RealmSelector from "../support/pages/admin_console/RealmSelector"; import { keycloakBefore, keycloakBeforeEach, @@ -12,6 +13,8 @@ const masthead = new Masthead(); const loginPage = new LoginPage(); const sidebarPage = new SidebarPage(); const createRealmPage = new CreateRealmPage(); +const realmSelector = new RealmSelector(); +const adminClient = new AdminClient(); describe("Realms test", () => { const testRealmName = "Test realm"; @@ -25,10 +28,9 @@ describe("Realms test", () => { keycloakBeforeEach(); }); - after(async () => { - const client = new AdminClient(); - [testRealmName, "one", "two"].map( - async (realm) => await client.deleteRealm(realm) + after(() => { + [testRealmName, "one", "two"].map((realm) => + adminClient.deleteRealm(realm) ); }); @@ -76,4 +78,23 @@ describe("Realms test", () => { .should("eq", testRealmName); }); }); + + describe("More then 5 realms", () => { + const realmNames = ["One", "Two", "Three", "Four", "Five"]; + before(() => { + keycloakBefore(); + loginPage.logIn(); + realmNames.map((realm) => adminClient.createRealm(realm)); + }); + + after(() => { + for (const realmName of realmNames) { + adminClient.deleteRealm(realmName); + } + }); + + it("switch to searchable realm selector", () => { + realmSelector.openRealmContextSelector().shouldContainAll(realmNames); + }); + }); }); diff --git a/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts b/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts index dcdfd436df..dc0cd2b17b 100644 --- a/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts +++ b/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts @@ -220,6 +220,11 @@ export default class RealmSettingsPage { private deleteClientRolesCondition = "delete-client-roles-condition"; private deleteClientScopesCondition = "delete-client-scopes-condition"; + private realmName?: string; + constructor(realmName?: string) { + this.realmName = realmName; + } + selectLoginThemeType(themeType: string) { cy.get(this.selectLoginTheme).click(); cy.get(this.loginThemeList).contains(themeType).click(); @@ -303,7 +308,7 @@ export default class RealmSettingsPage { } toggleAddProviderDropdown() { - const keysUrl = "/auth/admin/realms/master/keys"; + const keysUrl = `/auth/admin/realms/${this.realmName}/keys`; cy.intercept(keysUrl).as("keysFetch"); cy.findByTestId(this.addProviderDropdown).click(); @@ -327,17 +332,6 @@ export default class RealmSettingsPage { return this; } - deleteProvider(providerName: string) { - cy.findAllByTestId("provider-name-link") - .contains(providerName) - .parent() - .siblings(".pf-c-data-list__item-action") - .click() - .findByTestId(this.deleteAction) - .click(); - cy.wait(500).findByTestId(this.modalConfirm).click(); - } - enterConsoleDisplayName(name: string) { cy.findByTestId(this.displayName).clear().type(name); } @@ -772,9 +766,9 @@ export default class RealmSettingsPage { shouldCancelEditingExecutor() { cy.get(this.clientProfileTwo).click(); - cy.intercept("/auth/admin/realms/master/client-policies/profiles*").as( - "profilesFetch" - ); + cy.intercept( + `/auth/admin/realms/${this.realmName}/client-policies/profiles*` + ).as("profilesFetch"); cy.findByTestId(this.editExecutor).first().click(); cy.wait("@profilesFetch"); @@ -1016,6 +1010,10 @@ export default class RealmSettingsPage { } shouldAddClientScopesCondition() { + cy.intercept(`/auth/admin/realms/${this.realmName}/client-scopes`).as( + "clientScopes" + ); + cy.get(this.clientPolicy).click(); cy.findByTestId(this.addCondition).click(); cy.get(this.addConditionDrpDwn).click(); @@ -1023,6 +1021,7 @@ export default class RealmSettingsPage { .contains("client-scopes") .click(); + cy.wait("@clientScopes"); this.addClientScopes(); cy.findByTestId(this.addConditionSaveBtn).click(); @@ -1051,12 +1050,13 @@ export default class RealmSettingsPage { } shouldEditClientScopesCondition() { + cy.intercept(`/auth/admin/realms/${this.realmName}/client-scopes`).as( + "clientScopes" + ); cy.get(this.clientPolicy).click(); - cy.findByTestId(this.clientScopesConditionLink).click(); - cy.wait(200); - + cy.wait("@clientScopes"); this.addClientScopes(); cy.findByTestId(this.addConditionSaveBtn).click(); @@ -1117,9 +1117,16 @@ export default class RealmSettingsPage { cy.findByTestId(this.newClientPolicyDescriptionInput).type( "Test Again Description" ); + cy.intercept( + "PUT", + `/auth/admin/realms/${this.realmName}/client-policies/policies` + ).as("save"); + cy.findByTestId(this.saveNewClientPolicyBtn).click(); cy.get(this.alertMessage).should("be.visible", "New client policy created"); - cy.wait(500); + cy.wait("@save"); + cy.get(".pf-c-alert").should("not.exist"); + cy.findByTestId(this.clientPolicyDrpDwn).contains("Action").click(); cy.findByTestId("deleteClientPolicyDropdown").click(); cy.findByTestId("modalConfirm").contains("Delete").click(); diff --git a/src/realm-settings/messages.ts b/src/realm-settings/messages.ts index ae138ea530..ba93490d66 100644 --- a/src/realm-settings/messages.ts +++ b/src/realm-settings/messages.ts @@ -199,7 +199,7 @@ export default { accessTokenLifespanImplicitFlow: "Access Token Lifespan For Implicit Flow", clientLoginTimeout: "Client Login Timeout", userInitiatedActionLifespan: "User-Initiated Action Lifespan", - defaultAdminInitiated: "Default Admin-Initated Action Lifespan", + defaultAdminInitiated: "Default Admin-Initiated Action Lifespan", emailVerification: "Email Verification", idpAccountEmailVerification: "IdP account email verification", executeActions: "Execute actions", @@ -211,6 +211,7 @@ export default { createClientPolicy: "Create client policy", createClientPolicySuccess: "New policy created", updateClientPolicySuccess: "Client policy updated", + createClientPolicyError: "Could not create policy due to: {{error}}", createClientConditionSuccess: "Condition created successfully.", createClientConditionError: "Error creating condition: {{error}}", updateClientConditionSuccess: "Condition updated successfully.",