refactor cypress tests

This commit is contained in:
mfrances 2021-03-05 11:36:49 -05:00
parent 7c816736d2
commit 40eb3ede0d
4 changed files with 80 additions and 108 deletions

View file

@ -36,13 +36,23 @@ const deleteModalTitle = "Delete user federation provider?";
const disableModalTitle = "Disable user federation provider?"; const disableModalTitle = "Disable user federation provider?";
describe("User Fed Kerberos tests", () => { 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", () => { it("Create Kerberos provider from empty state", () => {
cy.visit(""); providersPage.clickNewCard("kerberos");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get("[data-testid=kerberos-card]").click();
providersPage.fillKerberosRequiredData( providersPage.fillKerberosRequiredData(
firstKerberosName, firstKerberosName,
firstKerberosRealm, firstKerberosRealm,
@ -56,129 +66,70 @@ describe("User Fed Kerberos tests", () => {
}); });
it("Update an existing Kerberos provider and save", () => { it("Update an existing Kerberos provider and save", () => {
cy.visit(""); providersPage.clickExistingCard(firstKerberosName);
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
providersPage.selectCacheType(newPolicy); providersPage.selectCacheType(newPolicy);
providersPage.changeTime(defaultKerberosDay, newKerberosDay);
cy.contains(defaultKerberosDay).click(); providersPage.changeTime(defaultKerberosHour, newKerberosHour);
cy.contains(newKerberosDay).click(); providersPage.changeTime(defaultKerberosMinute, newKerberosMinute);
cy.contains(defaultKerberosHour).click();
cy.contains(newKerberosHour).click();
cy.contains(defaultKerberosMinute).click();
cy.contains(newKerberosMinute).click();
providersPage.save(); providersPage.save();
masthead.checkNotificationMessage(savedSuccessMessage); masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation(); sidebarPage.goToUserFederation();
cy.wait(1000); providersPage.clickExistingCard(firstKerberosName);
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
expect(cy.contains(newPolicy).should("exist")); expect(cy.contains(newPolicy).should("exist"));
expect(cy.contains(defaultPolicy).should("not.exist")); expect(cy.contains(defaultPolicy).should("not.exist"));
}); });
it("Change existing Kerberos provider and click button to cancel", () => { it("Change existing Kerberos provider and click button to cancel", () => {
cy.visit(""); providersPage.clickExistingCard(firstKerberosName);
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
providersPage.selectCacheType(newPolicy); providersPage.selectCacheType(newPolicy);
cy.contains(newKerberosDay).click(); providersPage.changeTime(newKerberosDay, defaultKerberosDay);
cy.contains(defaultKerberosDay).click(); providersPage.changeTime(newKerberosHour, defaultKerberosHour);
providersPage.changeTime(newKerberosMinute, defaultKerberosMinute);
cy.contains(newKerberosHour).click();
cy.contains(defaultKerberosHour).click();
cy.contains(newKerberosMinute).click();
cy.contains(defaultKerberosMinute).click();
providersPage.cancel(); providersPage.cancel();
cy.wait(1000);
cy.wait(1000); providersPage.clickExistingCard(firstKerberosName);
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
providersPage.selectCacheType(newPolicy); providersPage.selectCacheType(newPolicy);
expect(cy.contains(newKerberosDay).should("exist")); expect(cy.contains(newKerberosDay).should("exist"));
expect(cy.contains(newKerberosHour).should("exist")); expect(cy.contains(newKerberosHour).should("exist"));
expect(cy.contains(newKerberosMinute).should("exist")); expect(cy.contains(newKerberosMinute).should("exist"));
expect(cy.contains(defaultKerberosMinute).should("not.exist")); expect(cy.contains(defaultKerberosMinute).should("not.exist"));
sidebarPage.goToUserFederation(); sidebarPage.goToUserFederation();
}); });
it("Disable an existing Kerberos provider", () => { it("Disable an existing Kerberos provider", () => {
cy.visit(""); providersPage.clickExistingCard(firstKerberosName);
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
providersPage.disableEnabledSwitch(); providersPage.disableEnabledSwitch();
modalUtils.checkModalTitle(disableModalTitle).confirmModal(); modalUtils.checkModalTitle(disableModalTitle).confirmModal();
masthead.checkNotificationMessage(savedSuccessMessage); masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation(); sidebarPage.goToUserFederation();
masthead.checkNotificationMessage(savedSuccessMessage); masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation(); sidebarPage.goToUserFederation();
cy.wait(1000);
expect(cy.contains("Disabled").should("exist")); expect(cy.contains("Disabled").should("exist"));
}); });
it("Enable an existing previously-disabled Kerberos provider", () => { it("Enable an existing previously-disabled Kerberos provider", () => {
cy.visit(""); providersPage.clickExistingCard(firstKerberosName);
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-testid="keycloak-card-title"]')
.contains(firstKerberosName)
.click();
cy.wait(1000);
providersPage.enableEnabledSwitch(); providersPage.enableEnabledSwitch();
masthead.checkNotificationMessage(savedSuccessMessage); masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation(); sidebarPage.goToUserFederation();
cy.wait(1000);
expect(cy.contains("Enabled").should("exist")); expect(cy.contains("Enabled").should("exist"));
}); });
it("Create new Kerberos provider using the New Provider dropdown", () => { it("Create new Kerberos provider using the New Provider dropdown", () => {
cy.visit(""); providersPage.clickMenuCommand("Add new provider", "Kerberos");
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.contains("Add new provider").click();
cy.contains("Kerberos").click();
providersPage.fillKerberosRequiredData( providersPage.fillKerberosRequiredData(
secondKerberosName, secondKerberosName,
secondKerberosRealm, secondKerberosRealm,
@ -186,39 +137,22 @@ describe("User Fed Kerberos tests", () => {
secondKerberosKeytab secondKerberosKeytab
); );
providersPage.save(); providersPage.save();
masthead.checkNotificationMessage(createdSuccessMessage);
masthead.checkNotificationMessage(createdSuccessMessage);
sidebarPage.goToUserFederation(); sidebarPage.goToUserFederation();
}); });
it("Delete a Kerberos provider from card view using the card's menu", () => { it("Delete a Kerberos provider from card view using the card's menu", () => {
cy.visit(""); providersPage.deleteCardFromCard(secondKerberosName);
loginPage.logIn();
sidebarPage.goToUserFederation();
cy.get('[data-testid="my-kerberos-2-dropdown"]').click();
cy.get('[data-testid="card-delete"]').click();
modalUtils.checkModalTitle(deleteModalTitle).confirmModal(); modalUtils.checkModalTitle(deleteModalTitle).confirmModal();
masthead.checkNotificationMessage(deletedSuccessMessage); masthead.checkNotificationMessage(deletedSuccessMessage);
}); });
it("Delete a Kerberos provider using the Settings view's Action menu", () => { it("Delete a Kerberos provider using the Settings view's Action menu", () => {
cy.visit(""); providersPage.deleteCardFromMenu("kerberos", firstKerberosName);
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();
modalUtils.checkModalTitle(deleteModalTitle).confirmModal(); modalUtils.checkModalTitle(deleteModalTitle).confirmModal();
masthead.checkNotificationMessage(deletedSuccessMessage); masthead.checkNotificationMessage(deletedSuccessMessage);
}); });
}); });

View file

@ -103,8 +103,6 @@ describe("User Fed LDAP tests", () => {
masthead.checkNotificationMessage(savedSuccessMessage); masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation(); sidebarPage.goToUserFederation();
cy.wait(1000);
providersPage.clickExistingCard(firstLdapName); providersPage.clickExistingCard(firstLdapName);
expect(cy.contains(newPolicy).should("exist")); expect(cy.contains(newPolicy).should("exist"));
@ -144,7 +142,6 @@ describe("User Fed LDAP tests", () => {
masthead.checkNotificationMessage(savedSuccessMessage); masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation(); sidebarPage.goToUserFederation();
cy.wait(1000);
expect(cy.contains("Disabled").should("exist")); expect(cy.contains("Disabled").should("exist"));
}); });
@ -155,7 +152,6 @@ describe("User Fed LDAP tests", () => {
masthead.checkNotificationMessage(savedSuccessMessage); masthead.checkNotificationMessage(savedSuccessMessage);
sidebarPage.goToUserFederation(); sidebarPage.goToUserFederation();
cy.wait(1000);
expect(cy.contains("Enabled").should("exist")); expect(cy.contains("Enabled").should("exist"));
}); });

View file

@ -113,6 +113,7 @@ export default class SidebarPage {
goToUserFederation() { goToUserFederation() {
cy.get(this.userFederationBtn).click(); cy.get(this.userFederationBtn).click();
cy.wait(1000);
return this; return this;
} }

View file

@ -19,13 +19,13 @@ export default class CreateKerberosProviderPage {
cancelBtn: string; cancelBtn: string;
constructor() { constructor() {
// KerberosSettingsRequired required input values
this.kerberosNameInput = "data-testid=kerberos-name"; this.kerberosNameInput = "data-testid=kerberos-name";
this.kerberosRealmInput = "data-testid=kerberos-realm"; this.kerberosRealmInput = "data-testid=kerberos-realm";
this.kerberosPrincipalInput = "data-testid=kerberos-principal"; this.kerberosPrincipalInput = "data-testid=kerberos-principal";
this.kerberosKeytabInput = "data-testid=kerberos-keytab"; this.kerberosKeytabInput = "data-testid=kerberos-keytab";
this.kerberosEnabledInput = "#Kerberos-switch"; // SettingsCache input values
this.kerberosCacheDayInput = "#kc-eviction-day"; this.kerberosCacheDayInput = "#kc-eviction-day";
this.kerberosCacheDayList = "#kc-eviction-day + ul"; this.kerberosCacheDayList = "#kc-eviction-day + ul";
this.kerberosCacheHourInput = "#kc-eviction-hour"; this.kerberosCacheHourInput = "#kc-eviction-hour";
@ -35,11 +35,34 @@ export default class CreateKerberosProviderPage {
this.kerberosCachePolicyInput = "#kc-cache-policy"; this.kerberosCachePolicyInput = "#kc-cache-policy";
this.kerberosCachePolicyList = "#kc-cache-policy + ul"; this.kerberosCachePolicyList = "#kc-cache-policy + ul";
// Kerberos settings enabled switch
this.kerberosEnabledInput = "#Kerberos-switch";
// Kerberos action buttons
this.saveBtn = "data-testid=kerberos-save"; this.saveBtn = "data-testid=kerberos-save";
this.cancelBtn = "data-testid=kerberos-cancel"; 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( fillKerberosRequiredData(
name: string, name: string,
realm: string, realm: string,
@ -67,6 +90,24 @@ export default class CreateKerberosProviderPage {
return this; 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() { disableEnabledSwitch() {
cy.get(this.kerberosEnabledInput).uncheck({ force: true }); cy.get(this.kerberosEnabledInput).uncheck({ force: true });
} }