From 40eb3ede0de7a4e37b3b7e264e7aa49f7ad09d43 Mon Sep 17 00:00:00 2001 From: mfrances Date: Fri, 5 Mar 2021 11:36:49 -0500 Subject: [PATCH 1/4] refactor cypress tests --- .../user_fed_kerberos_test.spec.ts | 136 +++++------------- .../integration/user_fed_ldap_test.spec.ts | 4 - .../pages/admin_console/SidebarPage.ts | 1 + .../providers/CreateKerberosProviderPage.ts | 47 +++++- 4 files changed, 80 insertions(+), 108 deletions(-) diff --git a/cypress/integration/user_fed_kerberos_test.spec.ts b/cypress/integration/user_fed_kerberos_test.spec.ts index dcd6973f87..1b97684f94 100644 --- a/cypress/integration/user_fed_kerberos_test.spec.ts +++ b/cypress/integration/user_fed_kerberos_test.spec.ts @@ -36,13 +36,23 @@ const deleteModalTitle = "Delete user federation provider?"; const disableModalTitle = "Disable user federation provider?"; describe("User Fed Kerberos tests", () => { + beforeEach(() => { + /* + Prevent unpredictable 401 errors from failing individual tests. + These are most often occurring during the login process: + GET /admin/serverinfo/ + GET /admin/master/console/whoami + */ + cy.on("uncaught:exception", (err, runnable) => { + return false; + }); + cy.visit(""); + loginPage.logIn(); + sidebarPage.goToUserFederation(); + }); + it("Create Kerberos provider from empty state", () => { - cy.visit(""); - loginPage.logIn(); - - sidebarPage.goToUserFederation(); - cy.get("[data-testid=kerberos-card]").click(); - + providersPage.clickNewCard("kerberos"); providersPage.fillKerberosRequiredData( firstKerberosName, firstKerberosRealm, @@ -56,129 +66,70 @@ describe("User Fed Kerberos tests", () => { }); it("Update an existing Kerberos provider and save", () => { - cy.visit(""); - loginPage.logIn(); - sidebarPage.goToUserFederation(); - - cy.get('[data-testid="keycloak-card-title"]') - .contains(firstKerberosName) - .click(); - cy.wait(1000); + providersPage.clickExistingCard(firstKerberosName); providersPage.selectCacheType(newPolicy); - - cy.contains(defaultKerberosDay).click(); - cy.contains(newKerberosDay).click(); - - cy.contains(defaultKerberosHour).click(); - cy.contains(newKerberosHour).click(); - - cy.contains(defaultKerberosMinute).click(); - cy.contains(newKerberosMinute).click(); - + providersPage.changeTime(defaultKerberosDay, newKerberosDay); + providersPage.changeTime(defaultKerberosHour, newKerberosHour); + providersPage.changeTime(defaultKerberosMinute, newKerberosMinute); providersPage.save(); + masthead.checkNotificationMessage(savedSuccessMessage); - sidebarPage.goToUserFederation(); - cy.wait(1000); - - cy.get('[data-testid="keycloak-card-title"]') - .contains(firstKerberosName) - .click(); - cy.wait(1000); + providersPage.clickExistingCard(firstKerberosName); expect(cy.contains(newPolicy).should("exist")); expect(cy.contains(defaultPolicy).should("not.exist")); }); it("Change existing Kerberos provider and click button to cancel", () => { - cy.visit(""); - loginPage.logIn(); - sidebarPage.goToUserFederation(); - - cy.get('[data-testid="keycloak-card-title"]') - .contains(firstKerberosName) - .click(); - cy.wait(1000); + providersPage.clickExistingCard(firstKerberosName); providersPage.selectCacheType(newPolicy); - cy.contains(newKerberosDay).click(); - cy.contains(defaultKerberosDay).click(); - - cy.contains(newKerberosHour).click(); - cy.contains(defaultKerberosHour).click(); - - cy.contains(newKerberosMinute).click(); - cy.contains(defaultKerberosMinute).click(); + providersPage.changeTime(newKerberosDay, defaultKerberosDay); + providersPage.changeTime(newKerberosHour, defaultKerberosHour); + providersPage.changeTime(newKerberosMinute, defaultKerberosMinute); providersPage.cancel(); + cy.wait(1000); - cy.wait(1000); - cy.get('[data-testid="keycloak-card-title"]') - .contains(firstKerberosName) - .click(); - cy.wait(1000); + providersPage.clickExistingCard(firstKerberosName); providersPage.selectCacheType(newPolicy); expect(cy.contains(newKerberosDay).should("exist")); expect(cy.contains(newKerberosHour).should("exist")); expect(cy.contains(newKerberosMinute).should("exist")); - expect(cy.contains(defaultKerberosMinute).should("not.exist")); sidebarPage.goToUserFederation(); }); it("Disable an existing Kerberos provider", () => { - cy.visit(""); - loginPage.logIn(); - sidebarPage.goToUserFederation(); - - cy.get('[data-testid="keycloak-card-title"]') - .contains(firstKerberosName) - .click(); - cy.wait(1000); - + providersPage.clickExistingCard(firstKerberosName); providersPage.disableEnabledSwitch(); modalUtils.checkModalTitle(disableModalTitle).confirmModal(); masthead.checkNotificationMessage(savedSuccessMessage); - sidebarPage.goToUserFederation(); masthead.checkNotificationMessage(savedSuccessMessage); sidebarPage.goToUserFederation(); - - cy.wait(1000); expect(cy.contains("Disabled").should("exist")); }); it("Enable an existing previously-disabled Kerberos provider", () => { - cy.visit(""); - loginPage.logIn(); - sidebarPage.goToUserFederation(); - - cy.get('[data-testid="keycloak-card-title"]') - .contains(firstKerberosName) - .click(); - cy.wait(1000); - + providersPage.clickExistingCard(firstKerberosName); providersPage.enableEnabledSwitch(); + masthead.checkNotificationMessage(savedSuccessMessage); sidebarPage.goToUserFederation(); - - cy.wait(1000); expect(cy.contains("Enabled").should("exist")); }); it("Create new Kerberos provider using the New Provider dropdown", () => { - cy.visit(""); - loginPage.logIn(); - sidebarPage.goToUserFederation(); + providersPage.clickMenuCommand("Add new provider", "Kerberos"); - cy.contains("Add new provider").click(); - cy.contains("Kerberos").click(); providersPage.fillKerberosRequiredData( secondKerberosName, secondKerberosRealm, @@ -186,39 +137,22 @@ describe("User Fed Kerberos tests", () => { secondKerberosKeytab ); providersPage.save(); - masthead.checkNotificationMessage(createdSuccessMessage); + masthead.checkNotificationMessage(createdSuccessMessage); sidebarPage.goToUserFederation(); }); it("Delete a Kerberos provider from card view using the card's menu", () => { - cy.visit(""); - loginPage.logIn(); - sidebarPage.goToUserFederation(); - - cy.get('[data-testid="my-kerberos-2-dropdown"]').click(); - cy.get('[data-testid="card-delete"]').click(); + providersPage.deleteCardFromCard(secondKerberosName); modalUtils.checkModalTitle(deleteModalTitle).confirmModal(); - masthead.checkNotificationMessage(deletedSuccessMessage); }); it("Delete a Kerberos provider using the Settings view's Action menu", () => { - cy.visit(""); - loginPage.logIn(); - sidebarPage.goToUserFederation(); - - cy.get('[data-testid="keycloak-card-title"]') - .contains(firstKerberosName) - .click(); - cy.wait(1000); - - cy.get('[data-testid="action-dropdown"]').click(); - cy.get('[data-testid="delete-kerberos-cmd"]').click(); + providersPage.deleteCardFromMenu("kerberos", firstKerberosName); modalUtils.checkModalTitle(deleteModalTitle).confirmModal(); - masthead.checkNotificationMessage(deletedSuccessMessage); }); }); diff --git a/cypress/integration/user_fed_ldap_test.spec.ts b/cypress/integration/user_fed_ldap_test.spec.ts index c96ac897c6..12beab69e9 100644 --- a/cypress/integration/user_fed_ldap_test.spec.ts +++ b/cypress/integration/user_fed_ldap_test.spec.ts @@ -103,8 +103,6 @@ describe("User Fed LDAP tests", () => { masthead.checkNotificationMessage(savedSuccessMessage); sidebarPage.goToUserFederation(); - cy.wait(1000); - providersPage.clickExistingCard(firstLdapName); expect(cy.contains(newPolicy).should("exist")); @@ -144,7 +142,6 @@ describe("User Fed LDAP tests", () => { masthead.checkNotificationMessage(savedSuccessMessage); sidebarPage.goToUserFederation(); - cy.wait(1000); expect(cy.contains("Disabled").should("exist")); }); @@ -155,7 +152,6 @@ describe("User Fed LDAP tests", () => { masthead.checkNotificationMessage(savedSuccessMessage); sidebarPage.goToUserFederation(); - cy.wait(1000); expect(cy.contains("Enabled").should("exist")); }); diff --git a/cypress/support/pages/admin_console/SidebarPage.ts b/cypress/support/pages/admin_console/SidebarPage.ts index ff9b8ff43e..e46b7eccad 100644 --- a/cypress/support/pages/admin_console/SidebarPage.ts +++ b/cypress/support/pages/admin_console/SidebarPage.ts @@ -113,6 +113,7 @@ export default class SidebarPage { goToUserFederation() { cy.get(this.userFederationBtn).click(); + cy.wait(1000); return this; } diff --git a/cypress/support/pages/admin_console/manage/providers/CreateKerberosProviderPage.ts b/cypress/support/pages/admin_console/manage/providers/CreateKerberosProviderPage.ts index 251b76cea1..2840ba9d8b 100644 --- a/cypress/support/pages/admin_console/manage/providers/CreateKerberosProviderPage.ts +++ b/cypress/support/pages/admin_console/manage/providers/CreateKerberosProviderPage.ts @@ -19,13 +19,13 @@ export default class CreateKerberosProviderPage { cancelBtn: string; constructor() { + // KerberosSettingsRequired required input values this.kerberosNameInput = "data-testid=kerberos-name"; this.kerberosRealmInput = "data-testid=kerberos-realm"; this.kerberosPrincipalInput = "data-testid=kerberos-principal"; this.kerberosKeytabInput = "data-testid=kerberos-keytab"; - this.kerberosEnabledInput = "#Kerberos-switch"; - + // SettingsCache input values this.kerberosCacheDayInput = "#kc-eviction-day"; this.kerberosCacheDayList = "#kc-eviction-day + ul"; this.kerberosCacheHourInput = "#kc-eviction-hour"; @@ -35,11 +35,34 @@ export default class CreateKerberosProviderPage { this.kerberosCachePolicyInput = "#kc-cache-policy"; this.kerberosCachePolicyList = "#kc-cache-policy + ul"; + // Kerberos settings enabled switch + this.kerberosEnabledInput = "#Kerberos-switch"; + + // Kerberos action buttons this.saveBtn = "data-testid=kerberos-save"; this.cancelBtn = "data-testid=kerberos-cancel"; } - //#region Required Settings + changeTime(oldTime: string, newTime: string) { + cy.contains(oldTime).click(); + cy.contains(newTime).click(); + return this; + } + + deleteCardFromCard(card: string) { + cy.get(`[data-testid=${card}-dropdown]`).click(); + cy.get('[data-testid="card-delete"]').click(); + return this; + } + + deleteCardFromMenu(providerType: string, card: string) { + this.clickExistingCard(card); + cy.get('[data-testid="action-dropdown"]').click(); + cy.get(`[data-testid="delete-${providerType}-cmd"]`).click(); + return this; + } + + // Required fields - these always must be filled out when testing a save fillKerberosRequiredData( name: string, realm: string, @@ -67,6 +90,24 @@ export default class CreateKerberosProviderPage { return this; } + clickExistingCard(cardName: string) { + cy.get('[data-testid="keycloak-card-title"]').contains(cardName).click(); + cy.wait(1000); + return this; + } + + clickMenuCommand(menu: string, command: string) { + cy.contains("button", menu).click(); + cy.contains("li", command).click(); + return this; + } + + clickNewCard(providerType: string) { + cy.get(`[data-testid=${providerType}-card]`).click(); + cy.wait(1000); + return this; + } + disableEnabledSwitch() { cy.get(this.kerberosEnabledInput).uncheck({ force: true }); } From df0133896e3205618b06f929856b6636071cee86 Mon Sep 17 00:00:00 2001 From: mfrances Date: Fri, 5 Mar 2021 15:55:01 -0500 Subject: [PATCH 2/4] big refactor of cypress tests and consolidate into one page object --- .../user_fed_kerberos_test.spec.ts | 40 +++--- .../integration/user_fed_ldap_test.spec.ts | 33 +++-- .../providers/CreateKerberosProviderPage.ts | 128 ------------------ ...ateLdapProviderPage.ts => ProviderPage.ts} | 112 ++++++++++----- 4 files changed, 118 insertions(+), 195 deletions(-) delete mode 100644 cypress/support/pages/admin_console/manage/providers/CreateKerberosProviderPage.ts rename cypress/support/pages/admin_console/manage/providers/{CreateLdapProviderPage.ts => ProviderPage.ts} (59%) diff --git a/cypress/integration/user_fed_kerberos_test.spec.ts b/cypress/integration/user_fed_kerberos_test.spec.ts index 1b97684f94..53b1e2aea1 100644 --- a/cypress/integration/user_fed_kerberos_test.spec.ts +++ b/cypress/integration/user_fed_kerberos_test.spec.ts @@ -1,15 +1,18 @@ import LoginPage from "../support/pages/LoginPage"; import SidebarPage from "../support/pages/admin_console/SidebarPage"; -import CreateKerberosProviderPage from "../support/pages/admin_console/manage/providers/CreateKerberosProviderPage"; +import ProviderPage from "../support/pages/admin_console/manage/providers/ProviderPage"; import Masthead from "../support/pages/admin_console/Masthead"; import ModalUtils from "../support/util/ModalUtils"; const loginPage = new LoginPage(); const masthead = new Masthead(); const sidebarPage = new SidebarPage(); -const providersPage = new CreateKerberosProviderPage(); +const providersPage = new ProviderPage(); const modalUtils = new ModalUtils(); +const provider = "kerberos"; +const initCapProvider = provider.charAt(0).toUpperCase() + provider.slice(1); + const firstKerberosName = "my-kerberos"; const firstKerberosRealm = "my-realm"; const firstKerberosPrincipal = "my-principal"; @@ -29,6 +32,7 @@ const newKerberosDay = "Wednesday"; const newKerberosHour = "15"; const newKerberosMinute = "55"; +const addProviderMenu = "Add new provider"; const createdSuccessMessage = "User federation provider successfully created"; const savedSuccessMessage = "User federation provider successfully saved"; const deletedSuccessMessage = "The user federation provider has been deleted."; @@ -52,14 +56,14 @@ describe("User Fed Kerberos tests", () => { }); it("Create Kerberos provider from empty state", () => { - providersPage.clickNewCard("kerberos"); + providersPage.clickNewCard(provider); providersPage.fillKerberosRequiredData( firstKerberosName, firstKerberosRealm, firstKerberosPrincipal, firstKerberosKeytab ); - providersPage.save(); + providersPage.save(provider); masthead.checkNotificationMessage(createdSuccessMessage); sidebarPage.goToUserFederation(); @@ -68,10 +72,10 @@ describe("User Fed Kerberos tests", () => { it("Update an existing Kerberos provider and save", () => { providersPage.clickExistingCard(firstKerberosName); providersPage.selectCacheType(newPolicy); - providersPage.changeTime(defaultKerberosDay, newKerberosDay); - providersPage.changeTime(defaultKerberosHour, newKerberosHour); - providersPage.changeTime(defaultKerberosMinute, newKerberosMinute); - providersPage.save(); + providersPage.changeCacheTime("day", newKerberosDay); + providersPage.changeCacheTime("hour", newKerberosHour); + providersPage.changeCacheTime("minute", newKerberosMinute); + providersPage.save(provider); masthead.checkNotificationMessage(savedSuccessMessage); sidebarPage.goToUserFederation(); @@ -84,12 +88,10 @@ describe("User Fed Kerberos tests", () => { it("Change existing Kerberos provider and click button to cancel", () => { providersPage.clickExistingCard(firstKerberosName); providersPage.selectCacheType(newPolicy); - - providersPage.changeTime(newKerberosDay, defaultKerberosDay); - providersPage.changeTime(newKerberosHour, defaultKerberosHour); - providersPage.changeTime(newKerberosMinute, defaultKerberosMinute); - - providersPage.cancel(); + providersPage.changeCacheTime("day", defaultKerberosDay); + providersPage.changeCacheTime("hour", defaultKerberosHour); + providersPage.changeCacheTime("minute", defaultKerberosMinute); + providersPage.cancel(provider); cy.wait(1000); providersPage.clickExistingCard(firstKerberosName); @@ -105,7 +107,7 @@ describe("User Fed Kerberos tests", () => { it("Disable an existing Kerberos provider", () => { providersPage.clickExistingCard(firstKerberosName); - providersPage.disableEnabledSwitch(); + providersPage.disableEnabledSwitch(initCapProvider); modalUtils.checkModalTitle(disableModalTitle).confirmModal(); @@ -119,7 +121,7 @@ describe("User Fed Kerberos tests", () => { it("Enable an existing previously-disabled Kerberos provider", () => { providersPage.clickExistingCard(firstKerberosName); - providersPage.enableEnabledSwitch(); + providersPage.enableEnabledSwitch(initCapProvider); masthead.checkNotificationMessage(savedSuccessMessage); @@ -128,7 +130,7 @@ describe("User Fed Kerberos tests", () => { }); it("Create new Kerberos provider using the New Provider dropdown", () => { - providersPage.clickMenuCommand("Add new provider", "Kerberos"); + providersPage.clickMenuCommand(addProviderMenu, initCapProvider); providersPage.fillKerberosRequiredData( secondKerberosName, @@ -136,7 +138,7 @@ describe("User Fed Kerberos tests", () => { secondKerberosPrincipal, secondKerberosKeytab ); - providersPage.save(); + providersPage.save(provider); masthead.checkNotificationMessage(createdSuccessMessage); sidebarPage.goToUserFederation(); @@ -150,7 +152,7 @@ describe("User Fed Kerberos tests", () => { }); it("Delete a Kerberos provider using the Settings view's Action menu", () => { - providersPage.deleteCardFromMenu("kerberos", firstKerberosName); + providersPage.deleteCardFromMenu(provider, firstKerberosName); modalUtils.checkModalTitle(deleteModalTitle).confirmModal(); masthead.checkNotificationMessage(deletedSuccessMessage); diff --git a/cypress/integration/user_fed_ldap_test.spec.ts b/cypress/integration/user_fed_ldap_test.spec.ts index 12beab69e9..25db2a1909 100644 --- a/cypress/integration/user_fed_ldap_test.spec.ts +++ b/cypress/integration/user_fed_ldap_test.spec.ts @@ -1,15 +1,18 @@ import LoginPage from "../support/pages/LoginPage"; import SidebarPage from "../support/pages/admin_console/SidebarPage"; -import CreateLdapProviderPage from "../support/pages/admin_console/manage/providers/CreateLdapProviderPage"; +import ProviderPage from "../support/pages/admin_console/manage/providers/ProviderPage"; import Masthead from "../support/pages/admin_console/Masthead"; import ModalUtils from "../support/util/ModalUtils"; const loginPage = new LoginPage(); const masthead = new Masthead(); const sidebarPage = new SidebarPage(); -const providersPage = new CreateLdapProviderPage(); +const providersPage = new ProviderPage(); const modalUtils = new ModalUtils(); +const provider = "ldap"; +const allCapProvider = provider.toUpperCase(); + const firstLdapName = "my-ldap"; const firstLdapVendor = "Active Directory"; @@ -85,7 +88,7 @@ describe("User Fed LDAP tests", () => { firstUserObjClasses ); - providersPage.save(); + providersPage.save(provider); masthead.checkNotificationMessage(createdSuccessMessage); sidebarPage.goToUserFederation(); @@ -95,11 +98,11 @@ describe("User Fed LDAP tests", () => { providersPage.clickExistingCard(firstLdapName); providersPage.selectCacheType(newPolicy); - providersPage.changeTime(defaultLdapDay, newLdapDay); - providersPage.changeTime(defaultLdapHour, newLdapHour); - providersPage.changeTime(defaultLdapMinute, newLdapMinute); + providersPage.changeCacheTime("day", newLdapDay); + providersPage.changeCacheTime("hour", newLdapHour); + providersPage.changeCacheTime("minute", newLdapMinute); - providersPage.save(); + providersPage.save(provider); masthead.checkNotificationMessage(savedSuccessMessage); sidebarPage.goToUserFederation(); @@ -113,11 +116,11 @@ describe("User Fed LDAP tests", () => { providersPage.clickExistingCard(firstLdapName); providersPage.selectCacheType(newPolicy); - providersPage.changeTime(newLdapDay, defaultLdapDay); - providersPage.changeTime(newLdapHour, defaultLdapHour); - providersPage.changeTime(newLdapMinute, defaultLdapMinute); + providersPage.changeCacheTime("day", defaultLdapDay); + providersPage.changeCacheTime("hour", defaultLdapHour); + providersPage.changeCacheTime("minute", defaultLdapMinute); - providersPage.cancel(); + providersPage.cancel(provider); cy.wait(1000); providersPage.clickExistingCard(firstLdapName); @@ -133,7 +136,7 @@ describe("User Fed LDAP tests", () => { it("Disable an existing LDAP provider", () => { providersPage.clickExistingCard(firstLdapName); - providersPage.disableEnabledSwitch(); + providersPage.disableEnabledSwitch(allCapProvider); modalUtils.checkModalTitle(disableModalTitle).confirmModal(); @@ -147,7 +150,7 @@ describe("User Fed LDAP tests", () => { it("Enable an existing previously-disabled LDAP provider", () => { providersPage.clickExistingCard(firstLdapName); - providersPage.enableEnabledSwitch(); + providersPage.enableEnabledSwitch(allCapProvider); masthead.checkNotificationMessage(savedSuccessMessage); @@ -171,7 +174,7 @@ describe("User Fed LDAP tests", () => { secondUuidLdapAtt, secondUserObjClasses ); - providersPage.save(); + providersPage.save(provider); masthead.checkNotificationMessage(createdSuccessMessage); sidebarPage.goToUserFederation(); }); @@ -183,7 +186,7 @@ describe("User Fed LDAP tests", () => { }); it("Delete an LDAP provider using the Settings view's Action menu", () => { - providersPage.deleteCardFromMenu(firstLdapName); + providersPage.deleteCardFromMenu(provider, firstLdapName); modalUtils.checkModalTitle(deleteModalTitle).confirmModal(); masthead.checkNotificationMessage(deletedSuccessMessage); }); diff --git a/cypress/support/pages/admin_console/manage/providers/CreateKerberosProviderPage.ts b/cypress/support/pages/admin_console/manage/providers/CreateKerberosProviderPage.ts deleted file mode 100644 index 2840ba9d8b..0000000000 --- a/cypress/support/pages/admin_console/manage/providers/CreateKerberosProviderPage.ts +++ /dev/null @@ -1,128 +0,0 @@ -export default class CreateKerberosProviderPage { - kerberosNameInput: string; - kerberosRealmInput: string; - kerberosPrincipalInput: string; - kerberosKeytabInput: string; - - kerberosEnabledInput: string; - - kerberosCacheDayInput: string; - kerberosCacheDayList: string; - kerberosCacheHourInput: string; - kerberosCacheHourList: string; - kerberosCacheMinuteInput: string; - kerberosCacheMinuteList: string; - kerberosCachePolicyInput: string; - kerberosCachePolicyList: string; - - saveBtn: string; - cancelBtn: string; - - constructor() { - // KerberosSettingsRequired required input values - this.kerberosNameInput = "data-testid=kerberos-name"; - this.kerberosRealmInput = "data-testid=kerberos-realm"; - this.kerberosPrincipalInput = "data-testid=kerberos-principal"; - this.kerberosKeytabInput = "data-testid=kerberos-keytab"; - - // SettingsCache input values - this.kerberosCacheDayInput = "#kc-eviction-day"; - this.kerberosCacheDayList = "#kc-eviction-day + ul"; - this.kerberosCacheHourInput = "#kc-eviction-hour"; - this.kerberosCacheHourList = "#kc-eviction-hour + ul"; - this.kerberosCacheMinuteInput = "#kc-eviction-minute"; - this.kerberosCacheMinuteList = "#kc-eviction-minute + ul"; - this.kerberosCachePolicyInput = "#kc-cache-policy"; - this.kerberosCachePolicyList = "#kc-cache-policy + ul"; - - // Kerberos settings enabled switch - this.kerberosEnabledInput = "#Kerberos-switch"; - - // Kerberos action buttons - this.saveBtn = "data-testid=kerberos-save"; - this.cancelBtn = "data-testid=kerberos-cancel"; - } - - changeTime(oldTime: string, newTime: string) { - cy.contains(oldTime).click(); - cy.contains(newTime).click(); - return this; - } - - deleteCardFromCard(card: string) { - cy.get(`[data-testid=${card}-dropdown]`).click(); - cy.get('[data-testid="card-delete"]').click(); - return this; - } - - deleteCardFromMenu(providerType: string, card: string) { - this.clickExistingCard(card); - cy.get('[data-testid="action-dropdown"]').click(); - cy.get(`[data-testid="delete-${providerType}-cmd"]`).click(); - return this; - } - - // Required fields - these always must be filled out when testing a save - fillKerberosRequiredData( - name: string, - realm: string, - principal: string, - keytab: string - ) { - if (name) { - cy.get(`[${this.kerberosNameInput}]`).type(name); - } - if (realm) { - cy.get(`[${this.kerberosRealmInput}]`).type(realm); - } - if (principal) { - cy.get(`[${this.kerberosPrincipalInput}]`).type(principal); - } - if (keytab) { - cy.get(`[${this.kerberosKeytabInput}]`).type(keytab); - } - return this; - } - - selectCacheType(cacheType: string) { - cy.get(this.kerberosCachePolicyInput).click(); - cy.get(this.kerberosCachePolicyList).contains(cacheType).click(); - return this; - } - - clickExistingCard(cardName: string) { - cy.get('[data-testid="keycloak-card-title"]').contains(cardName).click(); - cy.wait(1000); - return this; - } - - clickMenuCommand(menu: string, command: string) { - cy.contains("button", menu).click(); - cy.contains("li", command).click(); - return this; - } - - clickNewCard(providerType: string) { - cy.get(`[data-testid=${providerType}-card]`).click(); - cy.wait(1000); - return this; - } - - disableEnabledSwitch() { - cy.get(this.kerberosEnabledInput).uncheck({ force: true }); - } - - enableEnabledSwitch() { - cy.get(this.kerberosEnabledInput).check({ force: true }); - } - - save() { - cy.get(`[${this.saveBtn}]`).click(); - return this; - } - - cancel() { - cy.get(`[${this.cancelBtn}]`).click(); - return this; - } -} diff --git a/cypress/support/pages/admin_console/manage/providers/CreateLdapProviderPage.ts b/cypress/support/pages/admin_console/manage/providers/ProviderPage.ts similarity index 59% rename from cypress/support/pages/admin_console/manage/providers/CreateLdapProviderPage.ts rename to cypress/support/pages/admin_console/manage/providers/ProviderPage.ts index a5054ea374..c665c4935d 100644 --- a/cypress/support/pages/admin_console/manage/providers/CreateLdapProviderPage.ts +++ b/cypress/support/pages/admin_console/manage/providers/ProviderPage.ts @@ -1,4 +1,9 @@ -export default class CreateLdapProviderPage { +export default class ProviderPage { + kerberosNameInput: string; + kerberosRealmInput: string; + kerberosPrincipalInput: string; + kerberosKeytabInput: string; + ldapNameInput: string; ldapVendorInput: string; ldapVendorList: string; @@ -17,19 +22,25 @@ export default class CreateLdapProviderPage { ldapEnabledInput: string; - ldapCacheDayInput: string; - ldapCacheDayList: string; - ldapCacheHourInput: string; - ldapCacheHourList: string; - ldapCacheMinuteInput: string; - ldapCacheMinuteList: string; - ldapCachePolicyInput: string; - ldapCachePolicyList: string; + cacheDayInput: string; + cacheDayList: string; + cacheHourInput: string; + cacheHourList: string; + cacheMinuteInput: string; + cacheMinuteList: string; + cachePolicyInput: string; + cachePolicyList: string; saveBtn: string; cancelBtn: string; constructor() { + // KerberosSettingsRequired required input values + this.kerberosNameInput = "data-testid=kerberos-name"; + this.kerberosRealmInput = "data-testid=kerberos-realm"; + this.kerberosPrincipalInput = "data-testid=kerberos-principal"; + this.kerberosKeytabInput = "data-testid=kerberos-keytab"; + // LdapSettingsGeneral required input values this.ldapNameInput = "data-testid=ldap-name"; this.ldapVendorInput = "#kc-vendor"; @@ -50,14 +61,14 @@ export default class CreateLdapProviderPage { this.ldapUserObjClassesInput = "data-testid=ldap-user-object-classes"; // SettingsCache input values - this.ldapCacheDayInput = "#kc-eviction-day"; - this.ldapCacheDayList = "#kc-eviction-day + ul"; - this.ldapCacheHourInput = "#kc-eviction-hour"; - this.ldapCacheHourList = "#kc-eviction-hour + ul"; - this.ldapCacheMinuteInput = "#kc-eviction-minute"; - this.ldapCacheMinuteList = "#kc-eviction-minute + ul"; - this.ldapCachePolicyInput = "#kc-cache-policy"; - this.ldapCachePolicyList = "#kc-cache-policy + ul"; + this.cacheDayInput = "#kc-eviction-day"; + this.cacheDayList = "#kc-eviction-day + ul"; + this.cacheHourInput = "#kc-eviction-hour"; + this.cacheHourList = "#kc-eviction-hour + ul"; + this.cacheMinuteInput = "#kc-eviction-minute"; + this.cacheMinuteList = "#kc-eviction-minute + ul"; + this.cachePolicyInput = "#kc-cache-policy"; + this.cachePolicyList = "#kc-cache-policy + ul"; // LDAP settings enabled switch this.ldapEnabledInput = "#LDAP-switch"; @@ -67,9 +78,24 @@ export default class CreateLdapProviderPage { this.cancelBtn = "data-testid=ldap-cancel"; } - changeTime(oldTime: string, newTime: string) { - cy.contains(oldTime).click(); - cy.contains(newTime).click(); + changeCacheTime(unit: string, time: string) { + switch (unit) { + case "day": + cy.get(this.cacheDayInput).click(); + cy.get(this.cacheDayList).contains(time).click(); + break; + case "hour": + cy.get(this.cacheHourInput).click(); + cy.get(this.cacheHourList).contains(time).click(); + break; + case "minute": + cy.get(this.cacheMinuteInput).click(); + cy.get(this.cacheMinuteList).contains(time).click(); + break; + default: + console.log("Invalid cache time, must be 'day', 'hour', or 'minute'."); + break; + } return this; } @@ -79,14 +105,34 @@ export default class CreateLdapProviderPage { return this; } - deleteCardFromMenu(card: string) { + deleteCardFromMenu(providerType: string, card: string) { this.clickExistingCard(card); cy.get('[data-testid="action-dropdown"]').click(); - cy.get('[data-testid="delete-ldap-cmd"]').click(); + cy.get(`[data-testid="delete-${providerType}-cmd"]`).click(); + return this; + } + + fillKerberosRequiredData( + name: string, + realm: string, + principal: string, + keytab: string + ) { + if (name) { + cy.get(`[${this.kerberosNameInput}]`).type(name); + } + if (realm) { + cy.get(`[${this.kerberosRealmInput}]`).type(realm); + } + if (principal) { + cy.get(`[${this.kerberosPrincipalInput}]`).type(principal); + } + if (keytab) { + cy.get(`[${this.kerberosKeytabInput}]`).type(keytab); + } return this; } - // Required fields - these always must be filled out when testing a save fillLdapRequiredGeneralData(name: string, vendor: string) { if (name) { cy.get(`[${this.ldapNameInput}]`).type(name); @@ -146,8 +192,8 @@ export default class CreateLdapProviderPage { } selectCacheType(cacheType: string) { - cy.get(this.ldapCachePolicyInput).click(); - cy.get(this.ldapCachePolicyList).contains(cacheType).click(); + cy.get(this.cachePolicyInput).click(); + cy.get(this.cachePolicyList).contains(cacheType).click(); return this; } @@ -169,23 +215,23 @@ export default class CreateLdapProviderPage { return this; } - disableEnabledSwitch() { - cy.get(this.ldapEnabledInput).uncheck({ force: true }); + disableEnabledSwitch(providerType: string) { + cy.get(`#${providerType}-switch`).uncheck({ force: true }); return this; } - enableEnabledSwitch() { - cy.get(this.ldapEnabledInput).check({ force: true }); + enableEnabledSwitch(providerType: string) { + cy.get(`#${providerType}-switch`).check({ force: true }); return this; } - save() { - cy.get(`[${this.saveBtn}]`).click(); + save(providerType: string) { + cy.get(`[data-testid=${providerType}-save]`).click(); return this; } - cancel() { - cy.get(`[${this.cancelBtn}]`).click(); + cancel(providerType: string) { + cy.get(`[data-testid=${providerType}-cancel]`).click(); return this; } } From 337efd1b3b7e9201966f5c7eae579d11862586fd Mon Sep 17 00:00:00 2001 From: mfrances Date: Fri, 5 Mar 2021 16:01:38 -0500 Subject: [PATCH 3/4] rm obsolete vars --- .../admin_console/manage/providers/ProviderPage.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/cypress/support/pages/admin_console/manage/providers/ProviderPage.ts b/cypress/support/pages/admin_console/manage/providers/ProviderPage.ts index c665c4935d..6b3ddcee17 100644 --- a/cypress/support/pages/admin_console/manage/providers/ProviderPage.ts +++ b/cypress/support/pages/admin_console/manage/providers/ProviderPage.ts @@ -20,8 +20,6 @@ export default class ProviderPage { ldapUuidLdapAttInput: string; ldapUserObjClassesInput: string; - ldapEnabledInput: string; - cacheDayInput: string; cacheDayList: string; cacheHourInput: string; @@ -31,9 +29,6 @@ export default class ProviderPage { cachePolicyInput: string; cachePolicyList: string; - saveBtn: string; - cancelBtn: string; - constructor() { // KerberosSettingsRequired required input values this.kerberosNameInput = "data-testid=kerberos-name"; @@ -69,13 +64,6 @@ export default class ProviderPage { this.cacheMinuteList = "#kc-eviction-minute + ul"; this.cachePolicyInput = "#kc-cache-policy"; this.cachePolicyList = "#kc-cache-policy + ul"; - - // LDAP settings enabled switch - this.ldapEnabledInput = "#LDAP-switch"; - - // LDAP action buttons - this.saveBtn = "data-testid=ldap-save"; - this.cancelBtn = "data-testid=ldap-cancel"; } changeCacheTime(unit: string, time: string) { From 50570e9f20260f5afb02d079f57de1a1dbf5400c Mon Sep 17 00:00:00 2001 From: mfrances Date: Fri, 5 Mar 2021 17:04:41 -0500 Subject: [PATCH 4/4] fixes issue 376 --- cypress/integration/user_fed_kerberos_test.spec.ts | 10 +++++++++- cypress/integration/user_fed_ldap_test.spec.ts | 13 +++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cypress/integration/user_fed_kerberos_test.spec.ts b/cypress/integration/user_fed_kerberos_test.spec.ts index 53b1e2aea1..b16d4973b6 100644 --- a/cypress/integration/user_fed_kerberos_test.spec.ts +++ b/cypress/integration/user_fed_kerberos_test.spec.ts @@ -56,7 +56,15 @@ describe("User Fed Kerberos tests", () => { }); it("Create Kerberos provider from empty state", () => { - providersPage.clickNewCard(provider); + // if tests don't start at empty state, e.g. user has providers configured locally, + // create a new card from the card view instead + cy.get("body").then(($body) => { + if ($body.find(`[data-testid=kerberos-card]`).length > 0) { + providersPage.clickNewCard(provider); + } else { + providersPage.clickMenuCommand(addProviderMenu, initCapProvider); + } + }); providersPage.fillKerberosRequiredData( firstKerberosName, firstKerberosRealm, diff --git a/cypress/integration/user_fed_ldap_test.spec.ts b/cypress/integration/user_fed_ldap_test.spec.ts index 25db2a1909..b77501308d 100644 --- a/cypress/integration/user_fed_ldap_test.spec.ts +++ b/cypress/integration/user_fed_ldap_test.spec.ts @@ -49,6 +49,7 @@ const newLdapDay = "Wednesday"; const newLdapHour = "15"; const newLdapMinute = "55"; +const addProviderMenu = "Add new provider"; const createdSuccessMessage = "User federation provider successfully created"; const savedSuccessMessage = "User federation provider successfully saved"; const deletedSuccessMessage = "The user federation provider has been deleted."; @@ -72,7 +73,15 @@ describe("User Fed LDAP tests", () => { }); it("Create Ldap provider from empty state", () => { - providersPage.clickNewCard("ldap"); + // if tests don't start at empty state, e.g. user has providers configured locally, + // create a new card from the card view instead + cy.get("body").then(($body) => { + if ($body.find(`[data-testid=ldap-card]`).length > 0) { + providersPage.clickNewCard(provider); + } else { + providersPage.clickMenuCommand(addProviderMenu, allCapProvider); + } + }); providersPage.fillLdapRequiredGeneralData(firstLdapName, firstLdapVendor); providersPage.fillLdapRequiredConnectionData( connectionUrl, @@ -159,7 +168,7 @@ describe("User Fed LDAP tests", () => { }); it("Create new LDAP provider using the New Provider dropdown", () => { - providersPage.clickMenuCommand("Add new provider", "LDAP"); + providersPage.clickMenuCommand(addProviderMenu, allCapProvider); providersPage.fillLdapRequiredGeneralData(secondLdapName, secondLdapVendor); providersPage.fillLdapRequiredConnectionData( connectionUrl,