Skip to content

Commit

Permalink
HPCC-31857 : Description and Protected Functionality Testing - Added …
Browse files Browse the repository at this point in the history
…common logic for save button, made testing configurable.
  • Loading branch information
Nisha-Bagdwal committed Jul 1, 2024
1 parent 3025b75 commit 19d4a22
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 63 deletions.
4 changes: 4 additions & 0 deletions esp/src/test-ui/tests/framework/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion esp/src/test-ui/tests/framework/config/TestClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class TestClasses {

public static final List<TestClass> testClassesList = List.of(
//new TestClass("ActivitiesTest", "framework.pages.ActivitiesTest"),
new TestClass("ActivitiesTest", "framework.pages.ActivitiesTest"),
new TestClass("ECLWorkUnitsTest", "framework.pages.ECLWorkUnitsTest")
);
}
59 changes: 28 additions & 31 deletions esp/src/test-ui/tests/framework/pages/BaseTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public abstract class BaseTableTest<T> {

protected abstract String getJsonFilePath();

protected abstract String getSaveButtonDetailsPage();

protected abstract String[] getColumnNames();

protected abstract String[] getDetailNames();
Expand Down Expand Up @@ -58,7 +60,7 @@ public abstract class BaseTableTest<T> {

protected abstract Map<String, T> getJsonMap();

protected abstract void testDetailSpecificFunctionality(String name);
protected abstract void testDetailSpecificFunctionality(String name, int i);

protected List<T> jsonObjects;

Expand Down Expand Up @@ -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() {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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()) {
Expand Down
65 changes: 36 additions & 29 deletions esp/src/test-ui/tests/framework/pages/ECLWorkUnitsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ protected String[] getColumnKeys() {

private final List<String> badStates = Arrays.asList("compiled", "failed");

String saveButtonDetailsPage = "Save";
@Override
protected String getSaveButtonDetailsPage() {
return "Save";
}

@Override
protected String[] getDetailNames() {
Expand Down Expand Up @@ -113,23 +116,32 @@ protected Map<String, ECLWorkunit> 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) {
Expand All @@ -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);
}
}

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

Expand All @@ -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;
Expand All @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions esp/src/test-ui/tests/framework/utility/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 19d4a22

Please sign in to comment.