From 19d4a225e8d549e747a6903d14b601b214ca27da Mon Sep 17 00:00:00 2001 From: Nisha Bagdwal Date: Mon, 1 Jul 2024 16:54:08 -0400 Subject: [PATCH] HPCC-31857 : Description and Protected Functionality Testing - Added common logic for save button, made testing configurable. --- .../tests/framework/config/Config.java | 4 ++ .../tests/framework/config/TestClasses.java | 2 +- .../tests/framework/pages/BaseTableTest.java | 59 ++++++++--------- .../framework/pages/ECLWorkUnitsTest.java | 65 ++++++++++--------- .../tests/framework/utility/Common.java | 9 ++- 5 files changed, 76 insertions(+), 63 deletions(-) diff --git a/esp/src/test-ui/tests/framework/config/Config.java b/esp/src/test-ui/tests/framework/config/Config.java index d44d571f5b7..01c99b870c2 100644 --- a/esp/src/test-ui/tests/framework/config/Config.java +++ b/esp/src/test-ui/tests/framework/config/Config.java @@ -20,4 +20,8 @@ public class Config { public static final int MALFORMED_TIME_STRING = -1; public static final int WAIT_TIME_IN_SECONDS = 1; public static final int WAIT_TIME_THRESHOLD_IN_SECONDS = 10; + public static final String TEST_DESCRIPTION_TEXT = "Testing Description"; + public static final boolean TEST_WU_DETAIL_PAGE_FIELD_NAMES_ALL = false; + public static final boolean TEST_WU_DETAIL_PAGE_DESCRIPTION_ALL = false; + public static final boolean TEST_WU_DETAIL_PAGE_PROTECTED_ALL = false; } diff --git a/esp/src/test-ui/tests/framework/config/TestClasses.java b/esp/src/test-ui/tests/framework/config/TestClasses.java index 2a1a3fb1faf..2f850a49bb9 100644 --- a/esp/src/test-ui/tests/framework/config/TestClasses.java +++ b/esp/src/test-ui/tests/framework/config/TestClasses.java @@ -7,7 +7,7 @@ public class TestClasses { public static final List testClassesList = List.of( - //new TestClass("ActivitiesTest", "framework.pages.ActivitiesTest"), + new TestClass("ActivitiesTest", "framework.pages.ActivitiesTest"), new TestClass("ECLWorkUnitsTest", "framework.pages.ECLWorkUnitsTest") ); } diff --git a/esp/src/test-ui/tests/framework/pages/BaseTableTest.java b/esp/src/test-ui/tests/framework/pages/BaseTableTest.java index 4f25244ea2f..f63fa55f429 100644 --- a/esp/src/test-ui/tests/framework/pages/BaseTableTest.java +++ b/esp/src/test-ui/tests/framework/pages/BaseTableTest.java @@ -22,6 +22,8 @@ public abstract class BaseTableTest { protected abstract String getJsonFilePath(); + protected abstract String getSaveButtonDetailsPage(); + protected abstract String[] getColumnNames(); protected abstract String[] getDetailNames(); @@ -58,7 +60,7 @@ public abstract class BaseTableTest { protected abstract Map getJsonMap(); - protected abstract void testDetailSpecificFunctionality(String name); + protected abstract void testDetailSpecificFunctionality(String name, int i); protected List jsonObjects; @@ -90,13 +92,22 @@ protected void testPage() { private void testDetailsPage(String name, int i) { - testForAllTextInDetailsPage(name); + if (!Config.TEST_WU_DETAIL_PAGE_FIELD_NAMES_ALL && i == 0) { + testForAllTextInDetailsPage(name); + } + testDetailsContentPage(name); + testDetailSpecificFunctionality(name, i); + } + + protected void clickOnSaveButton() { -// if(i == 0){ -// testDetailSpecificFunctionality(name); -// } - testDetailSpecificFunctionality(name); + WebElement saveButton = getSaveButtonWebElementDetailsPage(); + Common.waitForElementToBeClickable(saveButton); + saveButton.click(); + + saveButton = getSaveButtonWebElementDetailsPage(); + Common.waitForElementToBeDisabled(saveButton); } private void testLinksInTable() { @@ -120,14 +131,14 @@ private void testLinksInTable() { element.click(); if (Common.driver.getPageSource().contains(name)) { - String msg = "Success: " + getPageName() + ": Link Test Pass for " + (i+1) + ". " + name + ". URL : " + href; + String msg = "Success: " + getPageName() + ": Link Test Pass for " + (i + 1) + ". " + name + ". URL : " + href; Common.logDetail(msg); // after the link test has passed, the code tests the details page(including, the text, content and tabs) it has landed on testDetailsPage(name, i); } else { String currentPage = getCurrentPage(); - String errorMsg = "Failure: " + getPageName() + ": Link Test Fail for " + (i+1) + ". " + name + " page failed. The current navigation page that we landed on is " + currentPage + ". Current URL : " + href; + String errorMsg = "Failure: " + getPageName() + ": Link Test Fail for " + (i + 1) + ". " + name + " page failed. The current navigation page that we landed on is " + currentPage + ". Current URL : " + href; Common.logError(errorMsg); } @@ -182,7 +193,7 @@ private void testDetailsContentPage(String name) { try { waitToLoadDetailsPage(); // sleep until the specific detail fields have loaded } catch (Exception ex) { - Common.logError("Error: "+getPageName()+": Exception in waitToLoadDetailsPage: " + getUniqueKeyName() + " : " + name); + Common.logError("Error: " + getPageName() + ": Exception in waitToLoadDetailsPage: " + getUniqueKeyName() + " : " + name + " Exception: " + ex.getMessage()); } boolean pass = true; @@ -272,7 +283,7 @@ private String getCurrentSortingOrder(String columnKey) { WebElement columnHeader = Common.driver.findElement(By.xpath("//*[@*[.='" + columnKey + "']]")); - String oldSortOrder = getSortOrderForColumnHeader(columnHeader); + String oldSortOrder = columnHeader.getAttribute("aria-sort"); columnHeader.click(); @@ -285,25 +296,6 @@ private String getCurrentSortingOrder(String columnKey) { return null; } - private String getSortOrderForColumnHeader(WebElement columnHeader) { - - String[] attributes = Common.getAttributeList(columnHeader, getPageName()); - String sortValue = null; - - // Iterate through the list to find the attribute containing "sort" - for (String attribute : attributes) { - if (attribute.contains("sort")) { - String[] parts = attribute.split("=", 2); - if (parts.length == 2) { - sortValue = parts[1].replaceAll("['\"]", ""); - break; - } - } - } - - return sortValue; - } - private String waitToLoadChangedSortOrder(String oldSortOrder, String columnKey) { int waitTimeInSecs = Config.WAIT_TIME_IN_SECONDS; @@ -314,7 +306,7 @@ private String waitToLoadChangedSortOrder(String oldSortOrder, String columnKey) WebElement columnHeaderNew = Common.driver.findElement(By.xpath("//*[@*[.='" + columnKey + "']]")); - newSortOrder = getSortOrderForColumnHeader(columnHeaderNew); + newSortOrder = columnHeaderNew.getAttribute("aria-sort"); if (!Objects.equals(newSortOrder, oldSortOrder)) { break; @@ -465,7 +457,8 @@ private boolean checkValues(Object dataUIValue, Object dataJSONValue, Object dat private void clickDropdown(int numOfItemsJSON) { try { - WebElement dropdown = Common.driver.findElement(By.id("pageSize")); + + WebElement dropdown = Common.waitForElement(By.id("pageSize")); dropdown.click(); WebDriverWait wait = new WebDriverWait(Common.driver, Duration.ofSeconds(Config.WAIT_TIME_THRESHOLD_IN_SECONDS)); @@ -513,6 +506,10 @@ private String getSelectedDropdownValue() { return ""; } + protected WebElement getSaveButtonWebElementDetailsPage() { + return Common.waitForElement(By.xpath("//button//*[text()='" + getSaveButtonDetailsPage() + "']/../../..")); + } + private void testForAllText() { Common.logDebug("Tests started for: " + getPageName() + " page: Testing Text"); for (String text : getColumnNames()) { diff --git a/esp/src/test-ui/tests/framework/pages/ECLWorkUnitsTest.java b/esp/src/test-ui/tests/framework/pages/ECLWorkUnitsTest.java index 6fa3be535c5..a8753975cf5 100644 --- a/esp/src/test-ui/tests/framework/pages/ECLWorkUnitsTest.java +++ b/esp/src/test-ui/tests/framework/pages/ECLWorkUnitsTest.java @@ -52,7 +52,10 @@ protected String[] getColumnKeys() { private final List badStates = Arrays.asList("compiled", "failed"); - String saveButtonDetailsPage = "Save"; + @Override + protected String getSaveButtonDetailsPage() { + return "Save"; + } @Override protected String[] getDetailNames() { @@ -113,23 +116,32 @@ protected Map getJsonMap() { } @Override - protected void testDetailSpecificFunctionality(String wuName) { + protected void testDetailSpecificFunctionality(String wuName, int i) { - //testProtectedButtonFunctionality(wuName); - testDescriptionUpdateFunctionality(wuName); + if (!Config.TEST_WU_DETAIL_PAGE_PROTECTED_ALL && i == 0) { + testProtectedButtonFunctionality(wuName); + } + + if (!Config.TEST_WU_DETAIL_PAGE_DESCRIPTION_ALL && i == 0) { + testDescriptionUpdateFunctionality(wuName); + } } private void testDescriptionUpdateFunctionality(String wuName) { + try { + String newDescription = Config.TEST_DESCRIPTION_TEXT; - String newDescription = "Testing Description"; + String oldDescription = updateDescriptionAndSave(newDescription); - String oldDescription = updateDescriptionAndSave(newDescription); + testIfTheDescriptionUpdated(wuName, newDescription); - testIfTheDescriptionUpdated(wuName, newDescription); + Common.logDetail("Reverting Description Update To Old Value: " + getPageName() + " Details page, for WUID: " + wuName); - Common.logDetail("Reverting Description Update To Old Value: "+ getPageName() +" Details page, for WUID: " + wuName); + updateDescriptionAndSave(oldDescription); - updateDescriptionAndSave(oldDescription); + } catch (Exception ex) { + Common.logError("Error: " + getPageName() + " Details page for WUID: " + wuName + ", Exception occurred while testing for description. Exception: " + ex.getMessage()); + } } private void testIfTheDescriptionUpdated(String wuName, String newDescription) { @@ -143,9 +155,9 @@ private void testIfTheDescriptionUpdated(String wuName, String newDescription) { String updatedDescription = element.getAttribute(getAttributeValueForDetailsPage()).trim(); if (newDescription.equals(updatedDescription)) { - Common.logDetail("Success: "+ getPageName() +" Details page. Description Updated Successfully on click of save button: Description After refresh showing on UI: "+ updatedDescription+", Updated description was: "+newDescription+" for WUID: " + wuName); - }else{ - Common.logError("Failure: "+ getPageName() +" Details page. Description Did Not Update on click of save button : Description After refresh showing on UI: "+ updatedDescription+", Updated description should be: "+newDescription+" for WUID: " + wuName); + Common.logDetail("Success: " + getPageName() + " Details page. Description Updated Successfully on click of save button: Description After refresh showing on UI: " + updatedDescription + ", Updated description was: " + newDescription + " for WUID: " + wuName); + } else { + Common.logError("Failure: " + getPageName() + " Details page. Description Did Not Update on click of save button : Description After refresh showing on UI: " + updatedDescription + ", Updated description should be: " + newDescription + " for WUID: " + wuName); } } @@ -162,14 +174,10 @@ private String updateDescriptionAndSave(String newDescription) { element.sendKeys(newDescription); - WebElement saveButton = Common.waitForElement(By.xpath("//button//*[text()='" + saveButtonDetailsPage + "']")); - - Common.waitForElementToBeClickable(saveButton); - saveButton.click(); - Common.sleepWithTime(4); // need to modify this to wait dynamically + clickOnSaveButton(); element = Common.waitForElement(By.id("description")); - Common.logDetail("Old Description: "+ oldDescription +", Updated Description After Save: " + element.getAttribute(getAttributeValueForDetailsPage())); + Common.logDetail("Old Description: " + oldDescription + ", Updated Description After Save: " + element.getAttribute(getAttributeValueForDetailsPage())); return oldDescription; } @@ -184,8 +192,6 @@ private void testProtectedButtonFunctionality(String wuName) { WebElement element = Common.waitForElement(By.xpath("//div[text()='" + wuName + "']/..")); element.click(); - waitToLoadDetailsPage(); - if (checkIfNewCheckBoxValuePresentInDetailsPage(newCheckboxValue)) { Common.logDetail(getPageName() + " Details Page: Reverting the checkbox value for WUID: " + wuName); clickProtectedCheckboxAndSave(wuName); @@ -198,6 +204,8 @@ private void testProtectedButtonFunctionality(String wuName) { private boolean checkIfNewCheckBoxValuePresentInDetailsPage(boolean newCheckboxValue) { + waitToLoadDetailsPage(); + WebElement protectedCheckbox = Common.waitForElement(By.id("protected")); boolean currentCheckboxValue = protectedCheckbox.isSelected(); @@ -212,25 +220,26 @@ private boolean checkIfNewCheckBoxValuePresentInDetailsPage(boolean newCheckboxV private boolean clickProtectedCheckboxAndSave(String wuName) { + waitToLoadDetailsPage(); + WebElement protectedCheckbox = Common.waitForElement(By.id("protected")); boolean oldCheckboxValue = protectedCheckbox.isSelected(); - WebElement parentElement = protectedCheckbox.findElement(By.xpath("..")); JavascriptExecutor js = (JavascriptExecutor) Common.driver; - js.executeScript("arguments[0].click();", parentElement); + js.executeScript("arguments[0].click();", protectedCheckbox); - boolean newCheckboxValue = waitToLoadUpdatedProtectedCheckbox(oldCheckboxValue); + waitToLoadUpdatedProtectedCheckbox(oldCheckboxValue); - Common.logDetail("Protected checkbox old Value: " + oldCheckboxValue + ", current value: " + newCheckboxValue + " for WUID: " + wuName); + clickOnSaveButton(); - WebElement saveButton = Common.waitForElement(By.xpath("//button//*[text()='" + saveButtonDetailsPage + "']")); + boolean newCheckboxValue = protectedCheckbox.isSelected(); - saveButton.click(); + Common.logDetail("Protected checkbox old Value: " + oldCheckboxValue + ", current value after save: " + newCheckboxValue + " for WUID: " + wuName); return newCheckboxValue; } - private boolean waitToLoadUpdatedProtectedCheckbox(boolean oldCheckboxValue) { + private void waitToLoadUpdatedProtectedCheckbox(boolean oldCheckboxValue) { int waitTimeInSecs = Config.WAIT_TIME_IN_SECONDS; boolean newCheckboxValue; @@ -248,8 +257,6 @@ private boolean waitToLoadUpdatedProtectedCheckbox(boolean oldCheckboxValue) { waitTimeInSecs++; } while (waitTimeInSecs < Config.WAIT_TIME_THRESHOLD_IN_SECONDS); - - return newCheckboxValue; } private void checkProtectedStatusOnECLWorkunitsPage(String wuName, boolean newCheckboxValue) { diff --git a/esp/src/test-ui/tests/framework/utility/Common.java b/esp/src/test-ui/tests/framework/utility/Common.java index 140de52ecfa..925e224f84e 100644 --- a/esp/src/test-ui/tests/framework/utility/Common.java +++ b/esp/src/test-ui/tests/framework/utility/Common.java @@ -74,8 +74,13 @@ public static WebElement waitForElement(By locator) { return new WebDriverWait(driver, Duration.ofSeconds(Config.WAIT_TIME_THRESHOLD_IN_SECONDS)).until(ExpectedConditions.presenceOfElementLocated(locator)); } - public static WebElement waitForElementToBeClickable(WebElement element) { - return new WebDriverWait(driver, Duration.ofSeconds(Config.WAIT_TIME_THRESHOLD_IN_SECONDS)).until(ExpectedConditions.elementToBeClickable(element)); + public static void waitForElementToBeClickable(WebElement element) { + new WebDriverWait(driver, Duration.ofSeconds(Config.WAIT_TIME_THRESHOLD_IN_SECONDS)).until(ExpectedConditions.elementToBeClickable(element)); + } + + public static void waitForElementToBeDisabled(WebElement element) { + new WebDriverWait(driver, Duration.ofSeconds(Config.WAIT_TIME_THRESHOLD_IN_SECONDS)) + .until(ExpectedConditions.attributeContains(element, "aria-disabled", "true")); } public static void logError(String message) {