big refactor of cypress tests and consolidate into one page object

This commit is contained in:
mfrances 2021-03-05 15:55:01 -05:00
parent 40eb3ede0d
commit df0133896e
4 changed files with 118 additions and 195 deletions

View file

@ -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);

View file

@ -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);
});

View file

@ -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;
}
}

View file

@ -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;
}
}