Skip to content

Commit

Permalink
HPCC-31857 : Description Functionality Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Nisha-Bagdwal committed Jun 28, 2024
1 parent aeca50d commit bdbe5cf
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 39 deletions.
2 changes: 1 addition & 1 deletion esp/src/test-ui/tests/framework/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ public class Config {
public static final int[] dropdownValues = {10, 25, 50, 100, 250, 500, 1000};
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 = 20;
public static final int WAIT_TIME_THRESHOLD_IN_SECONDS = 10;
}
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")
);
}
66 changes: 36 additions & 30 deletions esp/src/test-ui/tests/framework/pages/BaseTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class BaseTableTest<T> {

protected abstract String getAttributeTypeForDetailsPage();

protected abstract String getAttributeTitleForDetailsPage();
protected abstract String getAttributeValueForDetailsPage();

protected abstract String[] getDetailKeysForPageLoad();

Expand All @@ -58,6 +58,8 @@ public abstract class BaseTableTest<T> {

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

protected abstract void testDetailSpecificFunctionality(String name);

protected List<T> jsonObjects;

protected void testPage() {
Expand All @@ -66,11 +68,15 @@ protected void testPage() {
try {
Common.logDebug("Tests started for: " + getPageName() + " page.");

testForAllText();
//testForAllText();

jsonObjects = getAllObjectsFromJson();
if (jsonObjects != null) {
testContentAndSortingOrder();

int numOfItemsJSON = jsonObjects.size();
clickDropdown(numOfItemsJSON);

//testContentAndSortingOrder();
}

testLinksInTable();
Expand All @@ -84,19 +90,19 @@ protected void testPage() {

private void testDetailsPage(String name, int i) {

//testForAllTextInDetailsPage(name);
//testDetailsContentPage(name);

// if(i == 0){
// testForAllTextInDetailsPage(name);
// testDetailSpecificFunctionality(name);
// }
testForAllTextInDetailsPage(name);
testDetailsContentPage(name);
testDetailSpecificFunctionality(name);
}

private void testLinksInTable() {

Common.logDebug("Tests started for: " + getPageName() + " page: Testing Links");

long startTime = System.currentTimeMillis();

for (String columnKey : getColumnKeysWithLinks()) {

List<Object> values = getDataFromUIUsingColumnKey(columnKey);
Expand All @@ -114,14 +120,14 @@ private void testLinksInTable() {
element.click();

if (Common.driver.getPageSource().contains(name)) {
String msg = "Success: " + getPageName() + ": Link Test Pass for " + i + ". " + 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 + ". " + 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 All @@ -140,13 +146,9 @@ private void testLinksInTable() {
}
}
}

long endTime = System.currentTimeMillis();

System.out.println("Total time taken: " + (endTime - startTime) + " ms");
}

private void waitToLoadDetailsPage() {
protected void waitToLoadDetailsPage() {

int waitTimeInSecs = Config.WAIT_TIME_IN_SECONDS;

Expand All @@ -158,7 +160,7 @@ private void waitToLoadDetailsPage() {

for (String detailKey : getDetailKeysForPageLoad()) {
WebElement element = Common.waitForElement(By.id(detailKey));
if ("".equals(element.getAttribute(getAttributeTitleForDetailsPage()))) {
if ("".equals(element.getAttribute(getAttributeValueForDetailsPage()))) {
allVisible = false;
break;
}
Expand All @@ -177,7 +179,11 @@ private void waitToLoadDetailsPage() {

private void testDetailsContentPage(String name) {
Common.logDebug("Tests started for : " + getPageName() + " Details page content: " + getUniqueKeyName() + " : " + name);
waitToLoadDetailsPage(); // sleep until the specific detail fields have loaded
try {
waitToLoadDetailsPage(); // sleep until the specific detail fields have loaded
} catch (Exception ex) {
Common.logError("Error: "+getPageName()+": Exception in waitToLoadDetailsPage: " + getUniqueKeyName() + " : " + name);
}

boolean pass = true;

Expand All @@ -192,7 +198,7 @@ private void testDetailsContentPage(String name) {
if (element.getAttribute(getAttributeTypeForDetailsPage()).equals(getCheckboxTypeForDetailsPage())) {
dataUIValue = element.isSelected();
} else {
dataUIValue = element.getAttribute(getAttributeTitleForDetailsPage());
dataUIValue = element.getAttribute(getAttributeValueForDetailsPage());
}

dataJSONValue = getColumnDataFromJson(object, detailKey);
Expand Down Expand Up @@ -224,9 +230,6 @@ private void testForAllTextInDetailsPage(String name) {

private void testContentAndSortingOrder() {

int numOfItemsJSON = jsonObjects.size();
clickDropdown(numOfItemsJSON);

Common.logDebug("Tests started for: " + getPageName() + " page: Testing Content");

if (testTableContent()) {
Expand Down Expand Up @@ -332,15 +335,15 @@ private List<Object> getDataFromJSONUsingColumnKey(String columnKey) {
return columnDataFromJSON;
}

private List<Object> getDataFromUIUsingColumnKey(String columnKey) {
protected List<Object> getDataFromUIUsingColumnKey(String columnKey) {

List<Object> columnData = new ArrayList<>();

try {

List<WebElement> elements = waitToLoadListOfAllUIObjects(columnKey);
for (int i = 1; i < elements.size(); i++) {
columnData.add(elements.get(i).getText());
for (int i = 1; i < elements.size(); i++) { // first element fetched is of column header, so we fetch values from 2nd element.
columnData.add(elements.get(i).getText().trim());
}

} catch (Exception ex) {
Expand All @@ -358,7 +361,7 @@ private List<WebElement> waitToLoadListOfAllUIObjects(String columnKey) {
do {
elements = Common.driver.findElements(By.xpath("//*[@*[.='" + columnKey + "']]"));

if (elements.size() - 1 >= jsonObjects.size()) {
if (elements.size() - 1 >= jsonObjects.size()) { // first element fetched is of column header, so we do -1 from total elements
break;
}

Expand Down Expand Up @@ -459,15 +462,17 @@ private boolean checkValues(Object dataUIValue, Object dataJSONValue, Object dat
return true;
}

// need to change and fix "pageSize" and "ms-Dropdown-item"
private void clickDropdown(int numOfItemsJSON) {

try {
WebElement dropdown = Common.driver.findElement(By.id("pageSize"));
dropdown.click();

WebDriverWait wait = new WebDriverWait(Common.driver, Duration.ofSeconds(Config.WAIT_TIME_THRESHOLD_IN_SECONDS));
List<WebElement> options = wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector(".ms-Dropdown-item")));

WebElement dropdownList = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("pageSize-list")));

List<WebElement> options = dropdownList.findElements(By.tagName("button"));

int selectedValue = Config.dropdownValues[0];

Expand All @@ -479,16 +484,17 @@ private void clickDropdown(int numOfItemsJSON) {
}
}

Common.logDebug("Page: " + getPageName() + ": Dropdown selected: " + selectedValue);

for (WebElement option : options) {
if (option.getText().equals(String.valueOf(selectedValue))) {
option.click();
break;
}
}

wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".ms-Dropdown-item")));
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("pageSize-list")));

Common.logDebug("Page: " + getPageName() + ": Dropdown selected: " + selectedValue);

Common.driver.navigate().refresh();
Common.sleep();
} catch (Exception ex) {
Expand Down
Loading

0 comments on commit bdbe5cf

Please sign in to comment.