Skip to content

Commit

Permalink
HPCC-31857 : Develop an automated ECL Watch Test Suite
Browse files Browse the repository at this point in the history
Developed a testing framework using Java, Selenium, and TestNG. The framework is initiated by TestRunner.java, which loads all test classes listed in config/TestClasses.java and executes them sequentially. Each test class contains at least one method annotated with @test, which serves as the entry point for the tests. Initial test cases cover the Activities and ECL Workunit pages, including tests for text presence, link functionality, and sorting order. Additionally, provided comprehensive documentation with UML diagrams and detailed explanations of each method within the classes.

Signed-off-by: Nisha Bagdwal <[email protected]>
  • Loading branch information
Nisha-Bagdwal committed Jun 18, 2024
1 parent db29ee9 commit b7bbeb8
Show file tree
Hide file tree
Showing 41 changed files with 1,590 additions and 0 deletions.
7 changes: 7 additions & 0 deletions esp/src/test-ui/tests/framework/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Project: An Automated ECL Watch Test Suite

This project's code begins with the TestRunner.java file. The main method in this class loads all the Java classes created for writing test cases for specific web pages of the ECL Watch UI and then runs the tests in those classes sequentially.

The names of the Java classes that the TestRunner class needs to load should be listed in the config/TestClasses.java file.

Each Java class created to write tests for specific web pages should have at least one method annotated with @Test. The code for each class starts to run from this method.
98 changes: 98 additions & 0 deletions esp/src/test-ui/tests/framework/TestRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package framework;

import framework.config.Config;
import framework.config.TestClasses;
import framework.model.TestClass;
import framework.setup.TestInjector;
import org.openqa.selenium.WebDriver;
import framework.utility.Common;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.TestNG;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

public class TestRunner {
public static void main(String[] args) {

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

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

private static WebDriver setupWebDriver() {

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless"); // sets the ChromeDriver to run in headless mode, meaning it runs without opening a visible browser window.
chromeOptions.addArguments("--no-sandbox"); // disables the sandbox security feature in Chrome.
chromeOptions.addArguments("--log-level=3"); // sets the log level for the ChromeDriver. Level 3 corresponds to errors only.

System.setProperty("webdriver.chrome.silentOutput", "true"); // suppresses the logs generated by the ChromeDriver

WebDriver driver;

if (Common.isRunningOnLocal()) {
System.setProperty("webdriver.chrome.driver", Config.PATH_LOCAL_CHROME_DRIVER); // sets the system property to the path of the ChromeDriver executable.
try {
driver = new RemoteWebDriver(URI.create(Config.LOCAL_SELENIUM_SERVER).toURL(), chromeOptions);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
} else {
System.setProperty("webdriver.chrome.driver", Config.PATH_GH_ACTION_CHROME_DRIVER);
driver = new ChromeDriver(chromeOptions);
}

//Capabilities caps = ((RemoteWebDriver) driver).getCapabilities();
//String browserName = caps.getBrowserName();
//String browserVersion = caps.getBrowserVersion();
//System.out.println(browserName+" "+browserVersion);

return driver;
}

private static Class<?>[] loadClasses() {

List<Class<?>> classes = new ArrayList<>();
for (TestClass testClass : TestClasses.testClassesList) {
try {
classes.add(Class.forName(testClass.getPath()));
} catch (ClassNotFoundException e) {
System.err.println(e.getMessage());
}
}

return classes.toArray(new Class<?>[0]);
}

private static Logger setupLogger() {
Logger logger = Logger.getLogger(TestRunner.class.getName());
try {
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.
return logger;
}
}
20 changes: 20 additions & 0 deletions esp/src/test-ui/tests/framework/config/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package framework.config;

public class Config {

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";
public static final String PATH_GH_ACTION_CHROME_DRIVER = "/usr/bin/chromedriver";
public static final String PATH_LOCAL_WORKUNITS_JSON = "C:/Users/nisha/Documents/Internship/Work/files/workunits.json";
public static final String PATH_GH_ACTION_WORKUNITS_JSON = "";
public static final String LOCAL_SELENIUM_SERVER = "http://localhost:4444/wd/hub";
public static final String LOCAL_IP = "http://192.168.0.221:8010/";
public static final String GITHUB_ACTION_IP = "http://127.0.0.1:8010/";
public static final String ACTIVITIES_URL = "esp/files/index.html#/activities";
public static final String ECL_WORK_UNITS_URL = "esp/files/index.html#/workunits";
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 = 4;
}
13 changes: 13 additions & 0 deletions esp/src/test-ui/tests/framework/config/TestClasses.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package framework.config;

import framework.model.TestClass;

import java.util.List;

public class TestClasses {

public static final List<TestClass> testClassesList = List.of(
//new TestClass("ActivitiesTest", "framework.pages.ActivitiesTest"),
new TestClass("ECLWorkUnitsTest", "framework.pages.ECLWorkUnitsTest")
);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b7bbeb8

Please sign in to comment.