Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/HPCC-31857-ECL-Watch-Test-Suite'…
Browse files Browse the repository at this point in the history
… into HPCC-31857-ECL-Watch-Test-Suite

# Conflicts:
#	esp/src/test-ui/tests/framework/TestRunner.java
#	esp/src/test-ui/tests/framework/config/Config.java
#	esp/src/test-ui/tests/framework/config/TestClasses.java
#	esp/src/test-ui/tests/framework/pages/ActivitiesTest.java
#	esp/src/test-ui/tests/framework/pages/BaseTableTest.java
#	esp/src/test-ui/tests/framework/pages/ECLWorkUnitsTest.java
#	esp/src/test-ui/tests/framework/setup/LoggerHolder.java
#	esp/src/test-ui/tests/framework/setup/TestInjector.java
#	esp/src/test-ui/tests/framework/utility/Common.java
  • Loading branch information
Nisha-Bagdwal committed Jun 19, 2024
2 parents 8078361 + 3a90042 commit 309ed54
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 198 deletions.
54 changes: 11 additions & 43 deletions esp/src/test-ui/tests/framework/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,16 @@
public class TestRunner {
public static void main(String[] args) {

Logger errorLogger = setupLogger("error");
Logger specificLogger = setupLogger(args[0]);

Logger logger = setupLogger();
WebDriver driver = setupWebDriver();

TestNG testng = new TestNG();
testng.setTestClasses(loadClasses());
testng.addListener(new TestInjector(errorLogger, specificLogger, driver));
testng.addListener(new TestInjector(logger, driver));
testng.run();
driver.quit();
}

private static Logger getSpecificLogger(String[] args) {

String logLevel = args.length > 0 ? args[0] : "error";
Logger specificLogger = null;

if (!logLevel.equalsIgnoreCase("error")) {
specificLogger = setupLogger(logLevel);
}

return specificLogger;
}

private static WebDriver setupWebDriver() {

ChromeOptions chromeOptions = new ChromeOptions();
Expand Down Expand Up @@ -93,38 +79,20 @@ private static Class<?>[] loadClasses() {
return classes.toArray(new Class<?>[0]);
}

private static Logger setupLogger(String logLevel) {

if (logLevel == null) {
return null;
}

Logger logger = Logger.getLogger(logLevel);
logger.setUseParentHandlers(false); // Disable console logging

private static Logger setupLogger() {
Logger logger = Logger.getLogger(TestRunner.class.getName());
try {
if (logLevel.equalsIgnoreCase("error")) {
FileHandler errorFileHandler = new FileHandler(Config.LOG_FILE_ERROR);
errorFileHandler.setFormatter(new SimpleFormatter());
logger.addHandler(errorFileHandler);
logger.setLevel(Level.SEVERE);
} else if (logLevel.equalsIgnoreCase("debug")) {
FileHandler debugFileHandler = new FileHandler(Config.LOG_FILE_DEBUG);
debugFileHandler.setFormatter(new SimpleFormatter());
logger.addHandler(debugFileHandler);
logger.setLevel(Level.INFO);
} else if (logLevel.equalsIgnoreCase("detail")) {
FileHandler detailFileHandler = new FileHandler(Config.LOG_FILE_DETAIL);
detailFileHandler.setFormatter(new SimpleFormatter());
logger.addHandler(detailFileHandler);
logger.setLevel(Level.FINE);
}

FileHandler fileHandler = new FileHandler(Config.LOG_FILE);
SimpleFormatter formatter = new SimpleFormatter();
fileHandler.setFormatter(formatter);
logger.addHandler(fileHandler);
logger.setUseParentHandlers(false);
logger.setLevel(Level.ALL);
} catch (IOException e) {
System.err.println("Failed to setup logger: " + e.getMessage());
}

Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF); // Turn off all logging from the Selenium WebDriver.
Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF); // turn off all logging from the Selenium WebDriver.
return logger;
}
}
4 changes: 1 addition & 3 deletions esp/src/test-ui/tests/framework/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

public class Config {

public static final String LOG_FILE_ERROR = "error_ecl_test.log";
public static final String LOG_FILE_DEBUG = "debug_ecl_test.log";
public static final String LOG_FILE_DETAIL = "detail_ecl_test.log";
public static final String LOG_FILE = "errorLog.log";
public static final String LOCAL_OS = "Windows";
public static final String LOCAL_USER_PROFILE = "C:\\Users\\nisha";
public static final String PATH_LOCAL_CHROME_DRIVER = "C:/Users/nisha/Documents/Internship/Work/jars/chromeDriver";
Expand Down
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")
);
}
27 changes: 11 additions & 16 deletions esp/src/test-ui/tests/framework/pages/ActivitiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ActivitiesTest {
Expand All @@ -29,37 +28,33 @@ public class ActivitiesTest {
//"DummyNavName", List.of("DummyTab1", "DummyTab2")
);

Logger errorLogger, specificLogger;

@Test
public void testActivitiesPage() {
WebDriver driver = WebDriverHolder.getDriver();
Common.openWebPage(driver, Common.getUrl(Config.ACTIVITIES_URL));

errorLogger = LoggerHolder.getErrorLogger();
specificLogger = LoggerHolder.getSpecificLogger();

Common.logDebug(specificLogger, "Tests started for Activities Page");
Logger logger = LoggerHolder.getLogger();

testForAllText(driver);
testForAllText(logger, driver);

List<NavigationWebElement> navWebElements = getNavWebElements(driver);

testForNavigationLinks(driver, navWebElements);

Common.logDebug(specificLogger, "Tests finished for Activities Page");
testForNavigationLinks(driver, navWebElements, logger);
}

private void testForNavigationLinks(WebDriver driver, List<NavigationWebElement> navWebElements) {
private void testForNavigationLinks(WebDriver driver, List<NavigationWebElement> navWebElements, Logger logger) {

for (NavigationWebElement element : navWebElements) {
element.webElement().click();

if (testTabsForNavigationLinks(driver, element)) {
Common.logDetail(specificLogger, "Success: Navigation Menu Link for " + element.name() + ". URL : " + element.hrefValue());
String msg = "Success: Navigation Menu Link for " + element.name() + ". URL : " + element.hrefValue();
System.out.println(msg);
} else {
String currentPage = getCurrentPage(driver);
Common.logError(errorLogger, "Failure: Navigation Menu Link for " + element.name() + " page failed. The current navigation page that we landed on is " + currentPage + ". Current URL : " + element.hrefValue());
String errorMsg = "Failure: Navigation Menu Link for " + element.name() + " page failed. The current navigation page that we landed on is " + currentPage + ". Current URL : " + element.hrefValue();
System.err.println(errorMsg);
logger.severe(errorMsg);
}
}
}
Expand Down Expand Up @@ -113,10 +108,10 @@ private List<NavigationWebElement> getNavWebElements(WebDriver driver) {
return navWebElements;
}

private void testForAllText(WebDriver driver) {
private void testForAllText(Logger logger, WebDriver driver) {

for (String text : textArray) {
Common.checkTextPresent(driver, text, "Activities Page", errorLogger, specificLogger);
Common.checkTextPresent(driver, text, "Activities Page", logger);
}
}
}
Loading

0 comments on commit 309ed54

Please sign in to comment.