diff --git a/esp/src/test-ui/tests/framework/README.md b/esp/src/test-ui/tests/framework/README.md new file mode 100644 index 00000000000..df8da1cc4d2 --- /dev/null +++ b/esp/src/test-ui/tests/framework/README.md @@ -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. \ No newline at end of file diff --git a/esp/src/test-ui/tests/framework/TestRunner.java b/esp/src/test-ui/tests/framework/TestRunner.java new file mode 100644 index 00000000000..3ab5376fd81 --- /dev/null +++ b/esp/src/test-ui/tests/framework/TestRunner.java @@ -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> 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; + } +} diff --git a/esp/src/test-ui/tests/framework/config/Config.java b/esp/src/test-ui/tests/framework/config/Config.java new file mode 100644 index 00000000000..98b8311ac28 --- /dev/null +++ b/esp/src/test-ui/tests/framework/config/Config.java @@ -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; +} diff --git a/esp/src/test-ui/tests/framework/config/TestClasses.java b/esp/src/test-ui/tests/framework/config/TestClasses.java new file mode 100644 index 00000000000..2a1a3fb1faf --- /dev/null +++ b/esp/src/test-ui/tests/framework/config/TestClasses.java @@ -0,0 +1,13 @@ +package framework.config; + +import framework.model.TestClass; + +import java.util.List; + +public class TestClasses { + + public static final List testClassesList = List.of( + //new TestClass("ActivitiesTest", "framework.pages.ActivitiesTest"), + new TestClass("ECLWorkUnitsTest", "framework.pages.ECLWorkUnitsTest") + ); +} diff --git a/esp/src/test-ui/tests/framework/documentation/ActivitiesTest.png b/esp/src/test-ui/tests/framework/documentation/ActivitiesTest.png new file mode 100644 index 00000000000..c3b17514907 Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/ActivitiesTest.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/ApplicationValue.png b/esp/src/test-ui/tests/framework/documentation/ApplicationValue.png new file mode 100644 index 00000000000..47bb55d8d92 Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/ApplicationValue.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/ApplicationValues.png b/esp/src/test-ui/tests/framework/documentation/ApplicationValues.png new file mode 100644 index 00000000000..7aa4a575632 Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/ApplicationValues.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/BaseTableTest.png b/esp/src/test-ui/tests/framework/documentation/BaseTableTest.png new file mode 100644 index 00000000000..289db16ed45 Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/BaseTableTest.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/Common.png b/esp/src/test-ui/tests/framework/documentation/Common.png new file mode 100644 index 00000000000..0d2b76cc7bb Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/Common.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/Config.png b/esp/src/test-ui/tests/framework/documentation/Config.png new file mode 100644 index 00000000000..e33466b0fb8 Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/Config.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/DesignDocument.md b/esp/src/test-ui/tests/framework/documentation/DesignDocument.md new file mode 100644 index 00000000000..268d34458db --- /dev/null +++ b/esp/src/test-ui/tests/framework/documentation/DesignDocument.md @@ -0,0 +1,464 @@ +**The Class Design and Code Flow for ECL Watch Test Suite** + +**1. TestRunner.java** + +![img_2.png](TestRunner.png) + +The TestRunner class is responsible for setting up and executing automated tests using the TestNG framework in a +Selenium-based testing environment. It initializes the WebDriver, loads test classes, configures logging, and runs the +tests. + +**Methods:** + +1. main Method + +The entry point of the application. It performs the following steps: + +- Calls setupLogger to configure the logging system. +- Logs test execution details to a specified file. +- Calls setupWebDriver to initialize the WebDriver based on the environment (local or remote). +- Creates an instance of TestNG. +- Sets the test classes to be run by calling loadClasses. +- Adds a TestInjector listener to inject dependencies (logger and driver) into the tests. +- Runs the tests using TestNG. +- Quits the WebDriver session after the tests have completed. + +2. setupWebDriver Method + +Initializes and returns a WebDriver instance configured for headless Chrome operation: + +- Configures ChromeDriver to run in headless mode, disables sandbox security, and sets log level to errors only. +- Suppresses logs generated by ChromeDriver. +- Checks if the tests are running locally using Common.isRunningOnLocal. +- If local, sets up the driver to connect to a local Selenium server. +- If not local, initializes a standard ChromeDriver. + +3. loadClasses Method + +Loads the test classes specified in TestClasses.testClassesList: + +- Iterates over the testClassesList and loads each class by its fully qualified name. +- Adds the loaded class to the list classes. +- Catches and prints any ClassNotFoundException. + +4. setupLogger Method + +Configures the logger for logging test execution details: + +- Creates a logger for TestRunner. +- Sets up a FileHandler to log messages to a file specified by Config.LOG_FILE. +- Uses a SimpleFormatter to format the log messages. +- Adds the handler to the logger and sets the log level to ALL. +- Catches and prints any IOException. +- Turns off all logging from the Selenium WebDriver to reduce noise in the logs. + +**2. TestClasses.java** + +![img_4.png](TestClasses.png) + +The TestClasses class in the framework.config package is responsible for maintaining +a list of test classes used in the framework. This class provides a centralized and +immutable collection of test class metadata, which includes the name of each test +class and its fully qualified class name. This setup helps organize and reference +the test classes easily throughout the testing framework. By using the TestClasses +class, the framework can dynamically load and execute tests, enhancing modularity +and maintainability. + +**3. TestClass.java** + +![img_3.png](TestClass.png) + +The TestClass class in the framework.model package is a simple model class designed +to encapsulate metadata about a test class within the testing framework. It contains +the name of the test class and its fully qualified class name (path). This class +provides a structured way to store and retrieve information about each test class, +which can be utilized by other components in the framework for dynamically loading and +executing tests. + +**4. TestInjector.java** + +![img.png](TestInjector.png) + +The TestInjector class in the framework.setup package implements the +IInvokedMethodListener interface from TestNG. This class is designed to inject +dependencies (such as a logger and a WebDriver instance) into test methods before +they are invoked. It ensures that these dependencies are available to the tests when +they are executed. The TestInjector class provides a way to set up the necessary +environment for test execution by using holders to manage the logger and WebDriver +instances. + +**Methods:** + +1. constructor + +An instance of TestInjector is created with a Logger and a WebDriver. + +2. Before Invocation + +- Before a test method is invoked, the beforeInvocation method is called. +- It checks if the method is a test method. +- If it is a test method, it sets the logger and driver instances in their respective holders. + +3. After Invocation + +- After a test method is invoked, the afterInvocation method is called. +- Currently, this method does not perform any actions but can be extended for cleanup operations. + +**5. WebDriverHolder.java** + +![img.png](WebDriverHolder.png) + +The WebDriverHolder class in the framework.setup package is a utility class designed to +manage a singleton instance of WebDriver. This class allows the framework to store and +access the WebDriver instance globally, ensuring that all test methods can utilize the +same driver instance. This class is used in the TestInjector class in the beforeInvocation() method. + +**6. LoggerHolder.java** + +![img.png](LoggerHolder.png) + +The LoggerHolder class in the framework.setup package is a utility class designed to manage a +singleton instance of Logger. This class allows the framework to store and access the +Logger instance globally, ensuring that all test methods and other components can utilize +the same logger instance for consistent logging throughout the application. This class is +used in the TestInjector class in the beforeInvocation() method. + +**7. Config.java** + +![img.png](Config.png) + +The Config class in the framework.config package serves as a centralized configuration +repository for the application. It contains various constants that are used throughout +the framework, providing a single point of reference for configuration settings such as +file paths, IPs, and other constants. This approach enhances the maintainability and +readability of the code by avoiding hard-coded values scattered across different classes. + +**8. Common.java** + +![img.png](Common.png) + +The Common class in the framework.utility package provides a set of utility +methods that are frequently used throughout the testing framework. These +methods handle common tasks such as checking for text presence on a webpage, +opening a webpage, and determining the environment in which the code is +running (local or GitHub Actions). The class leverages constants from the +Config class to maintain consistency and facilitate configuration management. + +**Methods:** + +1. checkTextPresent Method + +Checks if the specified text is present on the current webpage and logs the result. + +- Retrieves the page source using driver.getPageSource(). +- Checks if the page source contains the specified text. +- Logs a success message if the text is found; otherwise, logs an error message and records it using the provided + logger. + +2. openWebPage Method + +Opens the specified URL in the browser and maximizes the window. + +- Navigates to the specified URL using driver.get(url). +- Maximizes the browser window using driver.manage().window().maximize(). +- Calls the sleep method to pause the execution for a short period to allow the page to load completely. + +3. sleep Method + +The sleep method pauses the execution of the program for a specified duration +(4 seconds in this case). This can be useful in scenarios where a delay is required, +such as waiting for a webpage to load completely before proceeding with further actions. + +4. isRunningOnLocal Method + +Determines if the code is running on a local environment. + +- Checks if the operating system name starts with the value of Config.LOCAL_OS. +- Checks if the user profile path starts with the value of Config.LOCAL_USER_PROFILE. +- Returns true if both conditions are met, indicating a local environment; otherwise, returns false. + +5. getUrl Method + +Constructs the full URL based on the environment (local or GitHub Actions). + +- Calls isRunningOnLocal to check the environment. +- If running locally, returns the URL prefixed with Config.LOCAL_IP. +- If running in GitHub Actions, returns the URL prefixed with Config.GITHUB_ACTION_IP. + +**9. TimeUtils.java** + +![img.png](TimeUtils.png) + +The TimeUtils class in the framework.utility package provides utility functions to handle +time strings and convert them into milliseconds. This is useful for standardizing time +representations and performing time-based calculations in a consistent manner. + +TIME_PATTERN: A regular expression pattern used to match various time formats. The supported formats are: + +- d days h:m:s.s +- h:m:s.s +- m:s.s +- s.s + +**Methods:** + +1. convertToMilliseconds Method + +This method converts a time string into milliseconds based on the matched pattern. If the +time string does not match any recognized format, it returns a predefined constant for +malformed time strings. + +- The method first attempts to match the input time string against the TIME_PATTERN. +- If the string matches the pattern, it initializes the time components (days, hours, minutes, seconds, milliseconds) to + zero. +- The method then extracts values based on the matching groups. +- If any parsing errors occur (e.g., NumberFormatException) or if the string does not match the pattern, the method + returns Config.MALFORMED_TIME_STRING. +- If the parsing is successful, the method calculates the total duration in milliseconds + +**10. NavigationWebElement** + +![img.png](NavigationWebElement.png) + +This NavigationWebElement class in the framework.model package, is a record class used to represent a navigation element +within a web application framework. It offers a concise way to store and manage information about such +elements. + +- The class is defined as a record which is a recent addition to Java that simplifies creating immutable data classes. +- It has three properties: + - name: A String representing the name or identifier of the navigation element in the menu bar(e.g., "Activities", " + ECL", "Files). + - hrefValue: A String representing the href attribute value of the element, which typically specifies the URL linked + to by the element. + - webElement: A WebElement object from the Selenium library. This holds the actual WebElement instance representing + the element in the web page. + +- Due to the record nature, a constructor is not explicitly defined. The compiler generates a constructor that takes + arguments for each property and initializes them. +- The NavigationWebElement class offers a structured way to manage data related to navigation elements in a web + application framework. + +**11. Java Classes for Representing Workunit JSON Data** + +This section details the class structure used to map JSON data file of list of "Workunit" +entities into Java objects. These classes provide a clear representation of the data and +allow for easy access to its values throughout the codebase. This structure is particularly +beneficial for writing test cases, as it simplifies working with the data in a well-defined +format. Below are the UML diagram of the classes used for JSON mapping to java objects for +workunits JSON file. + +![img.png](WUQueryRoot.png) +![img.png](WUQueryResponse.png) +![img.png](Workunits.png) +![img.png](ECLWorkunit.png) +![img.png](ApplicationValues.png) +![img.png](ApplicationValue.png) + +**12. ActivitiesTest** + +![img.png](ActivitiesTest.png) + +This ActivitiesTest class in the framework.pages package, implements a TestNG test (@Test) +for the Activities page of ECL Watch UI. It focuses on verifying the following aspects of the +Activities page: + +- Presence of specific text elements +- Functionality of navigation links and their corresponding sub-tabs + +**Class Variables:** + +- textArray: A static final String array containing expected text elements to be present on the Activities page (e.g., " + Target/Wuid", "Graph"). +- navNamesArray: A static final String array containing names used to locate the navigation link WebElements on the + Activities page (e.g., "Activities", "ECL", "Files). +- tabsListMap: A static final Map that defines the expected sub-tabs for each navigation link. The key is the navigation + link name, and the value is a List of expected sub-tabs. + +**Methods:** + +1. testActivitiesPage (Test Method) + +- Obtains the WebDriver instance (WebDriverHolder.getDriver()). +- Opens the Activities page using the URL from Config.ACTIVITIES_URL and Common.openWebPage. +- Retrieves a Logger instance for logging test results (LoggerHolder.getLogger()). +- Calls testForAllText to verify the presence of expected text elements on the page. +- Calls getNavWebElements to retrieve a list of NavigationWebElement objects representing navigation links. +- Calls testForNavigationLinks to verify the functionality of navigation links. + +2. testForAllText Method + +- Iterates through the textArray. +- For each text element, calls Common.checkTextPresent to check its presence on the Activities page using the provided + WebDriver, text element, page name ("Activities Page"), and Logger instance. + +3. testForNavigationLinks Method + +- Takes the WebDriver instance, a list of NavigationWebElement objects, and a Logger instance as arguments. +- Iterates through the list of NavigationWebElement objects: + - Clicks on the WebElement using the webElement().click() method. + - Calls testTabsForNavigationLinks to verify if the expected sub-tabs are present for the clicked link. + - Logs success/failure messages based on the verification result using the Logger instance. + +4. getCurrentPage Method + +- Iterates through the tabsListMap. +- For each entry (navigation link name and its corresponding sub-tabs): + - Checks if all sub-tabs from the list are present in the current page source using driver.getPageSource(). + - If all sub-tabs are found, returns the navigation link name (current page). +- If no matching navigation link is found, returns "Invalid Page". + +5. testTabsForNavigationLinks Method: + +- Takes the WebDriver instance and a NavigationWebElement object as arguments. +- Retrieves the expected sub-tabs list for the navigation element from tabsListMap. +- Gets the current page source using driver.getPageSource(). +- Iterates through the expected sub-tabs list: + - Checks if each sub-tab is present in the page source. + - If any sub-tab is missing, returns false. +- If all sub-tabs are found, returns true. + +6. getNavWebElements Method: + +- Creates an empty list to store NavigationWebElement objects. +- Iterates through the navNamesArray. +- For each navigation link name: + - Finds the WebElement using driver.findElement with By.name strategy. + - Extracts the href attribute value. + - Creates a new NavigationWebElement object with the name, href value, and WebElement reference. + - Adds the NavigationWebElement to the list. +- Returns the list of NavigationWebElement objects. + +**13. BaseTableTest** + +![img.png](BaseTableTest.png) + +This abstract class, `BaseTableTest`, in the framework.pages package, provides a framework for +testing web pages that display tabular data. It defines methods for common functionalities like: + +- Verifying the presence of expected text elements on the page. +- Comparing the content displayed in the table with corresponding data from a JSON file. +- Testing the sorting functionality of the table columns. +- Verifying links within the table cells and their navigation behavior. + +**Abstract Methods:** + +1. `getPageName`: Returns the name of the page under test. +2. `getPageUrl`: Returns the URL of the page under test. +3. `getJsonFilePath`: Returns the file path of the JSON file containing reference data. +4. `getColumnNames`: Returns an array of column names displayed in the table header. +5. `getColumnKeys`: Returns an array of unique keys used to identify table headers. +6. `getUniqueKeyName`: Returns the name of the unique key used to identify table rows. +7. `getUniqueKey`: Returns the unique key value for the current row (used for logging). +8. `getColumnKeysWithLinks`: Returns an array of column keys that contain links within the table cells. +9. `parseDataUIValue`: Parses and pre-processes a data value extracted from the UI table. +10. `parseDataJSONValue`: Parses and pre-processes a data value extracted from the JSON file. +11. `parseJson`: Parses the JSON file and returns a list of objects representing the data. +12. `getColumnDataFromJson`: Extracts a specific data value from a JSON object based on the provided column key. +13. `sortJsonUsingSortOrder`: Sorts the list of JSON objects based on a given column key and sort order. +14. `getCurrentPage`: Retrieves the name of the current page displayed in the browser. + +**Non-Abstract Methods:** + +1. `testPage`: The main test method that orchestrates all other functionalities to test the target web page. + +- Opens the target webpage using the URL obtained from `getPageUrl`. +- Calls `testForAllText` to verify the presence of expected text elements. +- Calls `testContentAndSortingOrder` to compare table data and test sorting functionality. +- Calls `testLinksInTable` to verify links within table cells and their navigation behavior. + +2. `waitForElement`: Waits for an element to be present on the page using explicit wait with a timeout. + +3. `testContentAndSortingOrder`: + +- Retrieves all objects from the JSON file using `getAllObjectsFromJson`. +- Clicks on the dropdown menu to select an appropriate number of items to display in the table. +- Calls `testTableContent` to compare the table data with JSON data. +- Iterates through each column: + - Calls `testTheSortingOrderForOneColumn` to test sorting functionality for the current column. + +4. `testTheSortingOrderForOneColumn`: + +- Gets the current sorting order for the specified column using `getCurrentSortingOrder`. +- Extracts data from the UI table and JSON file for the specified column. +- Sorts the JSON objects based on the current sorting order using `sortJsonUsingSortOrder`. +- Compares the sorted JSON data with the extracted UI data using `compareData`. + +5. `getCurrentSortingOrder`: Gets the current sorting order (ascending/descending/none) for a specified column. + +6. `getDataFromJSONUsingColumnKey`: Extracts a list of data values for a specified column from all JSON objects. + +7. `getDataFromUIUsingColumnKey`: Extracts a list of data values for a specified column from all table cells (UI). + +8. `ascendingSortJson`: Sorts a list of JSON objects in ascending order based on a specified column key. + +9. `descendingSortJson`: Sorts a list of JSON objects in descending order based on a specified column key. + +10. `testTableContent`: + +- Compares the number of items displayed in the UI table with the number of objects retrieved from the JSON file. +- Iterates through each column: + - Extracts data from the UI table and JSON file for the current column. + - Calls `compareData` to compare the extracted data. + +11. `getAllObjectsFromJson`: Parses the JSON file and returns a list of objects representing the data. Handles potential + exceptions during parsing. + +12. `compareData`: Compares a list of data values extracted from the UI table with the corresponding list from the JSON + file. + +- Iterates through each data pair: + - Calls `parseDataUIValue` and `parseDataJSONValue` to pre-process the data (if needed). + - Calls `checkValues` to perform the actual comparison and handle mismatches. + +13. `checkValues`: Compares two data values and logs an error message if they don't match. + +**14. ECLWorkUnitsTest** + +![img.png](ECLWorkUnitsTest.png) + +This class, `ECLWorkUnitsTest`, in the framework.pages package, extends the `BaseTableTest` +class and specifically implements test cases for the ECL Workunits page within the ECL Watch UI. +It inherits functionalities for common table testing procedures and specializes them for the +ECL Workunits data and behavior. + +**Override Methods:** + +1. `getPageName`: Returns the display name of the page under test ("ECL Workunits"). +2. `getPageUrl`: Returns the URL for the ECL Workunits page constructed using `Config.ECL_WORK_UNITS_URL`. +3. `getJsonFilePath`: Determines the file path of the JSON file containing ECL Workunit data based on the test execution + environment (local vs. GitHub Actions). +4. `getColumnNames`: Returns an array of column names displayed in the ECL Workunits table header. +5. `getColumnKeys`: Returns an array of unique keys used to identify ECL Workunit table headers. +6. `getColumnKeysWithLinks`: Returns an array specifying the column key that contains links within table cells ( + currently, only "Wuid" has links). +7. `getUniqueKeyName`: Returns the name of the unique key used to identify ECL Workunit table rows ("WUID"). +8. `getUniqueKey`: Returns the actual value of the unique key for the current row (used for logging). +9. `parseJson`: Parses the JSON file specific to ECL Workunits and returns a list of `ECLWorkunit` objects representing + the data. +10. `getColumnDataFromJson`: Extracts a specific data value from an `ECLWorkunit` object based on the provided column + key. +11. `parseDataUIValue`: Parses and pre-processes a data value extracted from the ECL Workunits UI table. +12. `parseDataJSONValue`: Parses and pre-processes a data value extracted from the ECL Workunits JSON file (if + necessary). +13. `sortJsonUsingSortOrder`: Sorts the list of `ECLWorkunit` objects based on a given column key and sort order, + considering the specific sorting behavior for the ECL Workunits table (default sort is descending by WUID). +14. `getCurrentPage`: Retrieves the title attribute of the "wuid" element to determine the current page displayed. + +**Additional Methods:** + +1. `getCostColumns`: Returns a list of column names that represent cost-related data (Compile Cost, Execution Cost, File + Access Cost). + +**Test Method:** + +1. `testingECLWorkUnitsPage`: Calls the inherited `testPage` method to execute the core test logic for the ECL Workunits + page. + +**Class Relationship Structure:** + +![img.png](relationship.png) + + + + + diff --git a/esp/src/test-ui/tests/framework/documentation/ECLWorkUnitsTest.png b/esp/src/test-ui/tests/framework/documentation/ECLWorkUnitsTest.png new file mode 100644 index 00000000000..8e7ab0792d8 Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/ECLWorkUnitsTest.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/ECLWorkunit.png b/esp/src/test-ui/tests/framework/documentation/ECLWorkunit.png new file mode 100644 index 00000000000..5bbf9018ae6 Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/ECLWorkunit.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/LoggerHolder.png b/esp/src/test-ui/tests/framework/documentation/LoggerHolder.png new file mode 100644 index 00000000000..547e7c857c7 Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/LoggerHolder.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/NavigationWebElement.png b/esp/src/test-ui/tests/framework/documentation/NavigationWebElement.png new file mode 100644 index 00000000000..b32e3dc1ae1 Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/NavigationWebElement.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/TestClass.png b/esp/src/test-ui/tests/framework/documentation/TestClass.png new file mode 100644 index 00000000000..6d9370dada3 Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/TestClass.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/TestClasses.png b/esp/src/test-ui/tests/framework/documentation/TestClasses.png new file mode 100644 index 00000000000..913e8d519fa Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/TestClasses.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/TestInjector.png b/esp/src/test-ui/tests/framework/documentation/TestInjector.png new file mode 100644 index 00000000000..e45e93682a7 Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/TestInjector.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/TestRunner.png b/esp/src/test-ui/tests/framework/documentation/TestRunner.png new file mode 100644 index 00000000000..066710df8b2 Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/TestRunner.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/TimeUtils.png b/esp/src/test-ui/tests/framework/documentation/TimeUtils.png new file mode 100644 index 00000000000..342180bc0fe Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/TimeUtils.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/WUQueryResponse.png b/esp/src/test-ui/tests/framework/documentation/WUQueryResponse.png new file mode 100644 index 00000000000..a84157c8b31 Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/WUQueryResponse.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/WUQueryRoot.png b/esp/src/test-ui/tests/framework/documentation/WUQueryRoot.png new file mode 100644 index 00000000000..2276a694af5 Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/WUQueryRoot.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/WebDriverHolder.png b/esp/src/test-ui/tests/framework/documentation/WebDriverHolder.png new file mode 100644 index 00000000000..f4c4ebf958f Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/WebDriverHolder.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/Workunits.png b/esp/src/test-ui/tests/framework/documentation/Workunits.png new file mode 100644 index 00000000000..0c50d24564b Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/Workunits.png differ diff --git a/esp/src/test-ui/tests/framework/documentation/relationship.png b/esp/src/test-ui/tests/framework/documentation/relationship.png new file mode 100644 index 00000000000..004a6e9da4d Binary files /dev/null and b/esp/src/test-ui/tests/framework/documentation/relationship.png differ diff --git a/esp/src/test-ui/tests/framework/model/ApplicationValue.java b/esp/src/test-ui/tests/framework/model/ApplicationValue.java new file mode 100644 index 00000000000..67f87f1da0a --- /dev/null +++ b/esp/src/test-ui/tests/framework/model/ApplicationValue.java @@ -0,0 +1,15 @@ +package framework.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ApplicationValue { + + @JsonProperty("Application") + private String application; + + @JsonProperty("Name") + private String name; + + @JsonProperty("Value") + private String value; +} diff --git a/esp/src/test-ui/tests/framework/model/ApplicationValues.java b/esp/src/test-ui/tests/framework/model/ApplicationValues.java new file mode 100644 index 00000000000..d7a1425d1e3 --- /dev/null +++ b/esp/src/test-ui/tests/framework/model/ApplicationValues.java @@ -0,0 +1,11 @@ +package framework.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +public class ApplicationValues { + + @JsonProperty("ApplicationValue") + private List applicationValue; +} diff --git a/esp/src/test-ui/tests/framework/model/ECLWorkunit.java b/esp/src/test-ui/tests/framework/model/ECLWorkunit.java new file mode 100644 index 00000000000..6a4cc340fe3 --- /dev/null +++ b/esp/src/test-ui/tests/framework/model/ECLWorkunit.java @@ -0,0 +1,100 @@ +package framework.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import framework.utility.TimeUtils; + +public class ECLWorkunit { + + @JsonProperty("Wuid") + private String wuid; + @JsonProperty("Owner") + private String owner; + + @JsonProperty("Cluster") + private String cluster; + + @JsonProperty("Jobname") + private String jobname; + + @JsonProperty("StateID") + private int stateID; + + @JsonProperty("State") + private String state; + + @JsonProperty("Protected") + private boolean isProtected; + + @JsonProperty("Action") + private int action; + + @JsonProperty("ActionEx") + private String actionEx; + + @JsonProperty("IsPausing") + private boolean isPausing; + + @JsonProperty("ThorLCR") + private boolean thorLCR; + + @JsonProperty("TotalClusterTime") + private long totalClusterTime; + + @JsonProperty("ApplicationValues") + private ApplicationValues applicationValues; + + @JsonProperty("ExecuteCost") + private double executeCost; + + @JsonProperty("FileAccessCost") + private double fileAccessCost; + + @JsonProperty("CompileCost") + private double compileCost; + + @JsonProperty("NoAccess") + private boolean noAccess; + + public String getWuid() { + return wuid; + } + + public String getOwner() { + return owner; + } + + public String getCluster() { + return cluster; + } + + public String getJobname() { + return jobname; + } + + public String getState() { + return state; + } + + public long getTotalClusterTime() { + return totalClusterTime; + } + + @JsonSetter("TotalClusterTime") + public void setTotalClusterTime(String totalClusterTime) { + this.totalClusterTime = TimeUtils.convertToMilliseconds(totalClusterTime); + } + + public double getExecuteCost() { + return executeCost; + } + + public double getFileAccessCost() { + return fileAccessCost; + } + + public double getCompileCost() { + return compileCost; + } + +} diff --git a/esp/src/test-ui/tests/framework/model/NavigationWebElement.java b/esp/src/test-ui/tests/framework/model/NavigationWebElement.java new file mode 100644 index 00000000000..cf095ad554f --- /dev/null +++ b/esp/src/test-ui/tests/framework/model/NavigationWebElement.java @@ -0,0 +1,14 @@ +package framework.model; + +import org.openqa.selenium.WebElement; + +public record NavigationWebElement(String name, String hrefValue, WebElement webElement) { + + @Override + public String toString() { + return "NavigationWebElement{" + + "name='" + name + '\'' + + ", hrefValue='" + hrefValue + '\'' + + '}'; + } +} diff --git a/esp/src/test-ui/tests/framework/model/TestClass.java b/esp/src/test-ui/tests/framework/model/TestClass.java new file mode 100644 index 00000000000..240cdd98a90 --- /dev/null +++ b/esp/src/test-ui/tests/framework/model/TestClass.java @@ -0,0 +1,16 @@ +package framework.model; + +public class TestClass { + + String name; + String path; + + public TestClass(String name, String path) { + this.name = name; + this.path = path; + } + + public String getPath() { + return path; + } +} diff --git a/esp/src/test-ui/tests/framework/model/WUQueryResponse.java b/esp/src/test-ui/tests/framework/model/WUQueryResponse.java new file mode 100644 index 00000000000..eb1a9aa3a7d --- /dev/null +++ b/esp/src/test-ui/tests/framework/model/WUQueryResponse.java @@ -0,0 +1,55 @@ +package framework.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class WUQueryResponse { + + @JsonProperty("Type") + private String type; + + @JsonProperty("LogicalFileSearchType") + private String logicalFileSearchType; + + @JsonProperty("Count") + private int count; + + @JsonProperty("PageSize") + private int pageSize; + + @JsonProperty("NextPage") + private int nextPage; + + @JsonProperty("LastPage") + private int lastPage; + + @JsonProperty("NumWUs") + private int numWUs; + + @JsonProperty("First") + private boolean first; + + @JsonProperty("PageStartFrom") + private int pageStartFrom; + + @JsonProperty("PageEndAt") + private int pageEndAt; + + @JsonProperty("Descending") + private boolean descending; + + @JsonProperty("BasicQuery") + private String basicQuery; + + @JsonProperty("Filters") + private String filters; + + @JsonProperty("CacheHint") + private long cacheHint; + + @JsonProperty("Workunits") + private Workunits workunits; + + public Workunits getWorkunits() { + return workunits; + } +} diff --git a/esp/src/test-ui/tests/framework/model/WUQueryRoot.java b/esp/src/test-ui/tests/framework/model/WUQueryRoot.java new file mode 100644 index 00000000000..c5a1c54993d --- /dev/null +++ b/esp/src/test-ui/tests/framework/model/WUQueryRoot.java @@ -0,0 +1,12 @@ +package framework.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class WUQueryRoot { + @JsonProperty("WUQueryResponse") + private WUQueryResponse wuQueryResponse; + + public WUQueryResponse getWUQueryResponse() { + return wuQueryResponse; + } +} diff --git a/esp/src/test-ui/tests/framework/model/Workunits.java b/esp/src/test-ui/tests/framework/model/Workunits.java new file mode 100644 index 00000000000..d52b00c5682 --- /dev/null +++ b/esp/src/test-ui/tests/framework/model/Workunits.java @@ -0,0 +1,15 @@ +package framework.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +public class Workunits { + + @JsonProperty("ECLWorkunit") + private List eclWorkunit; + + public List getECLWorkunit() { + return eclWorkunit; + } +} diff --git a/esp/src/test-ui/tests/framework/pages/ActivitiesTest.java b/esp/src/test-ui/tests/framework/pages/ActivitiesTest.java new file mode 100644 index 00000000000..bfbf5682c98 --- /dev/null +++ b/esp/src/test-ui/tests/framework/pages/ActivitiesTest.java @@ -0,0 +1,116 @@ +package framework.pages; + +import framework.config.Config; +import framework.setup.LoggerHolder; +import framework.model.NavigationWebElement; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.testng.annotations.Test; +import framework.utility.Common; +import framework.setup.WebDriverHolder; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.logging.Logger; + +public class ActivitiesTest { + + static final String[] textArray = {"Target/Wuid", "Graph", "State", "Owner", "Job Name"}; + static final String[] navNamesArray = {"Activities", "ECL", "Files", "Published Queries", "Operations"}; + static final Map> tabsListMap = Map.of( + "Activities", List.of("Activities", "Event Scheduler"), + "ECL", List.of("Workunits", "Playground"), + "Files", List.of("Logical Files", "Landing Zones", "Workunits", "XRef (L)"), + "Published Queries", List.of("Queries", "Package Maps"), + "Operations", List.of("Topology (L)", "Disk Usage (L)", "Target Clusters (L)", "Cluster Processes (L)", "System Servers (L)", "Security (L)", "Dynamic ESDL (L)") + //"DummyNavName", List.of("DummyTab1", "DummyTab2") + ); + @Test + public void testActivitiesPage() { + WebDriver driver = WebDriverHolder.getDriver(); + Common.openWebPage(driver, Common.getUrl(Config.ACTIVITIES_URL)); + + Logger logger = LoggerHolder.getLogger(); + + testForAllText(logger, driver); + + List navWebElements = getNavWebElements(driver); + + testForNavigationLinks(driver, navWebElements, logger); + } + + private void testForNavigationLinks(WebDriver driver, List navWebElements, Logger logger) { + + for (NavigationWebElement element : navWebElements) { + element.webElement().click(); + + if (testTabsForNavigationLinks(driver, element)) { + String msg = "Success: Navigation Menu Link for " + element.name() + ". URL : " + element.hrefValue(); + System.out.println(msg); + } else { + String currentPage = getCurrentPage(driver); + 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); + } + } + } + + private String getCurrentPage(WebDriver driver) { + + for (var entry : tabsListMap.entrySet()) { + + List tabs = entry.getValue(); + boolean allTabsPresent = true; + for (String tab : tabs) { + if (!driver.getPageSource().contains(tab)) { + allTabsPresent = false; + break; + } + } + + if (allTabsPresent) { + return entry.getKey(); + } + } + + return "Invalid Page"; + } + + private boolean testTabsForNavigationLinks(WebDriver driver, NavigationWebElement element) { + List tabsList = tabsListMap.get(element.name()); + String pageSource = driver.getPageSource(); + + for (String tab : tabsList) { + if (!pageSource.contains(tab)) { + return false; + } + } + + return true; + } + + private List getNavWebElements(WebDriver driver) { + + List navWebElements = new ArrayList<>(); + + for (String navName : navNamesArray) { + WebElement webElement = driver.findElement(By.name(navName)).findElement(By.tagName("a")); + String hrefValue = webElement.getAttribute("href"); + navWebElements.add(new NavigationWebElement(navName, hrefValue, webElement)); + } + + //navWebElements.add(new NavigationWebElement("DummyNavName", "http://192.168.0.221:8010/esp/files/index.html#/files", navWebElements.get(2).webElement())); + + return navWebElements; + } + + private void testForAllText(Logger logger, WebDriver driver) { + + for (String text : textArray) { + Common.checkTextPresent(driver, text, "Activities Page", logger); + } + } +} diff --git a/esp/src/test-ui/tests/framework/pages/BaseTableTest.java b/esp/src/test-ui/tests/framework/pages/BaseTableTest.java new file mode 100644 index 00000000000..6468196aff5 --- /dev/null +++ b/esp/src/test-ui/tests/framework/pages/BaseTableTest.java @@ -0,0 +1,310 @@ +package framework.pages; + +import framework.config.Config; +import framework.setup.LoggerHolder; +import framework.setup.WebDriverHolder; +import framework.utility.Common; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.time.Duration; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.function.Function; +import java.util.logging.Logger; + +public abstract class BaseTableTest { + + protected abstract String getPageName(); + + protected abstract String getPageUrl(); + + protected abstract String getJsonFilePath(); + + protected abstract String[] getColumnNames(); + + protected abstract String[] getColumnKeys(); + + protected abstract String getUniqueKeyName(); + + protected abstract String getUniqueKey(); + + protected abstract String[] getColumnKeysWithLinks(); + + protected abstract Object parseDataUIValue(Object dataUIValue, String columnName, Object dataIDUIValue, Logger logger); + + protected abstract Object parseDataJSONValue(Object dataJSONValue, String columnName, Object dataIDUIValue, Logger logger); + + protected abstract List parseJson(String filePath) throws Exception; + + protected abstract Object getColumnDataFromJson(T object, String columnKey); + + protected abstract void sortJsonUsingSortOrder(String currentSortOrder, List jsonObjects, String columnKey); + + protected abstract String getCurrentPage(WebDriver driver); + + protected void testPage() { + try { + WebDriver driver = WebDriverHolder.getDriver(); + Common.openWebPage(driver, getPageUrl()); + Logger logger = LoggerHolder.getLogger(); + + testForAllText(driver, logger); + testContentAndSortingOrder(driver, logger); + testLinksInTable(driver, logger); + + } catch (Exception ex) { + System.out.println(ex.getMessage()); + } + } + + private void testLinksInTable(WebDriver driver, Logger logger) { + + for (String columnKey : getColumnKeysWithLinks()) { + + List values = getDataFromUIUsingColumnKey(driver, columnKey); + + int i = 1; + + for (Object value : values) { + String name = value.toString().trim(); + //WebElement element = driver.findElement(By.xpath("//div[contains(text(), '"+name+"')]/..")); + WebElement element = waitForElement(driver, By.xpath("//div[contains(text(), '" + name + "')]/..")); + String href = element.findElement(By.tagName("a")).getAttribute("href"); + + String dropdownValueBefore = getSelectedDropdownValue(driver); + + element.click(); + + if (driver.getPageSource().contains(name)) { + String msg = "Success: " + getPageName() + ": Link Test Pass for " + i++ + ". " + name + ". URL : " + href; + System.out.println(msg); + } else { + String currentPage = getCurrentPage(driver); + 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; + System.err.println(errorMsg); + logger.severe(errorMsg); + } + + driver.navigate().to(getPageUrl()); + driver.navigate().refresh(); + + String dropdownValueAfter = getSelectedDropdownValue(driver); + + // Log error if the dropdown value has changed + if (!dropdownValueBefore.equals(dropdownValueAfter)) { + String dropdownErrorMsg = "Failure: " + getPageName() + ": Dropdown value changed after navigating back. Before: " + dropdownValueBefore + ", After: " + dropdownValueAfter; + System.err.println(dropdownErrorMsg); + logger.severe(dropdownErrorMsg); + } + } + } + } + + protected WebElement waitForElement(WebDriver driver, By locator) { + return new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.presenceOfElementLocated(locator)); + } + + private void testContentAndSortingOrder(WebDriver driver, Logger logger) { + List jsonObjects = getAllObjectsFromJson(logger); + + if (jsonObjects != null) { + int numOfItemsJSON = jsonObjects.size(); + clickDropdown(driver, numOfItemsJSON); + + if (testTableContent(driver, logger, jsonObjects)) { + for (int i = 0; i < getColumnKeys().length; i++) { + testTheSortingOrderForOneColumn(driver, logger, jsonObjects, getColumnKeys()[i], getColumnNames()[i]); + } + } + } + } + + private void testTheSortingOrderForOneColumn(WebDriver driver, Logger logger, List jsonObjects, String columnKey, String columnName) { + for (int i = 0; i < 3; i++) { + + String currentSortOrder = getCurrentSortingOrder(driver, columnKey); + List columnDataFromUI = getDataFromUIUsingColumnKey(driver, columnKey); + + sortJsonUsingSortOrder(currentSortOrder, jsonObjects, columnKey); + + List columnDataFromJSON = getDataFromJSONUsingColumnKey(columnKey, jsonObjects); + List columnDataIDFromUI = getDataFromUIUsingColumnKey(driver, getUniqueKey()); + + if (compareData(columnDataFromUI, columnDataFromJSON, columnDataIDFromUI, logger, columnName)) { + System.out.println("Success: " + getPageName() + ": Values are correctly sorted in " + currentSortOrder + " order by: " + columnName); + } else { + String errMsg = "Failure: " + getPageName() + ": Values are not correctly sorted in " + currentSortOrder + " order by: " + columnName; + System.err.println(errMsg); + logger.severe(errMsg); + } + } + } + + private String getCurrentSortingOrder(WebDriver driver, String columnKey) { + + WebElement columnHeader = driver.findElement(By.cssSelector("div[data-item-key='" + columnKey + "']")); + columnHeader.click(); + + Common.sleep(); + + columnHeader = driver.findElement(By.cssSelector("div[data-item-key='" + columnKey + "']")); + + return columnHeader.getAttribute("aria-sort"); + } + + private List getDataFromJSONUsingColumnKey(String columnKey, List jsonObjects) { + List columnDataFromJSON = new ArrayList<>(); + for (T jsonObject : jsonObjects) { + columnDataFromJSON.add(getColumnDataFromJson(jsonObject, columnKey)); + } + return columnDataFromJSON; + } + + private List getDataFromUIUsingColumnKey(WebDriver driver, String columnKey) { + List elements = driver.findElements(By.cssSelector("div[data-automation-key='" + columnKey + "']")); + List columnData = new ArrayList<>(); + for (WebElement element : elements) { + columnData.add(element.getText()); + } + return columnData; + } + + void ascendingSortJson(List jsonObjects, String columnKey) { + jsonObjects.sort(Comparator.comparing(jsonObject -> (Comparable) getColumnDataFromJson(jsonObject, columnKey))); + } + + void descendingSortJson(List jsonObjects, String columnKey) { + jsonObjects.sort(Comparator.comparing((Function) jsonObject -> (Comparable) getColumnDataFromJson(jsonObject, columnKey)).reversed()); + } + + private boolean testTableContent(WebDriver driver, Logger logger, List jsonObjects) { + System.out.println("Page: " + getPageName() + ": Number of Objects from Json: " + jsonObjects.size()); + + List columnDataIDFromUI = getDataFromUIUsingColumnKey(driver, getUniqueKey()); + + if (jsonObjects.size() != columnDataIDFromUI.size()) { + Common.sleep(); + columnDataIDFromUI = getDataFromUIUsingColumnKey(driver, getUniqueKey()); + } + + System.out.println("Page: " + getPageName() + ": Number of Objects from UI: " + columnDataIDFromUI.size()); + + if (jsonObjects.size() != columnDataIDFromUI.size()) { + String errMsg = "Failure: " + getPageName() + ": Number of items on UI are not equal to the number of items in JSON" + + "\nNumber of Objects from Json: " + jsonObjects.size() + + "\nNumber of Objects from UI: " + columnDataIDFromUI.size(); + System.out.println(errMsg); + logger.severe(errMsg); + return false; + } + + boolean pass = true; + + for (int i = 0; i < getColumnKeys().length; i++) { + List columnDataFromUI = getDataFromUIUsingColumnKey(driver, getColumnKeys()[i]); + List columnDataFromJSON = getDataFromJSONUsingColumnKey(getColumnKeys()[i], jsonObjects); + if (!compareData(columnDataFromUI, columnDataFromJSON, columnDataIDFromUI, logger, getColumnNames()[i])) { + pass = false; + } + } + + return pass; + } + + private List getAllObjectsFromJson(Logger logger) { + String filePath = getJsonFilePath(); + try { + return parseJson(filePath); + } catch (Exception e) { + System.err.println("Exception: " + e.getMessage()); + logger.severe("Failure: Exception: " + e.getMessage()); + } + + logger.severe("Failure: Error in JSON Parsing: " + filePath); + return null; + } + + private boolean compareData(List dataUI, List dataJSON, List dataIDUI, Logger logger, String columnName) { + + boolean pass = true; + + for (int i = 0; i < dataUI.size(); i++) { + + Object dataUIValue = dataUI.get(i); + Object dataJSONValue = dataJSON.get(i); + Object dataIDUIValue = dataIDUI.get(i); + + dataUIValue = parseDataUIValue(dataUIValue, columnName, dataIDUIValue, logger); + dataJSONValue = parseDataJSONValue(dataJSONValue, columnName, dataIDUIValue, logger); + + if (!checkValues(dataUIValue, dataJSONValue, dataIDUIValue, logger, columnName)) { + pass = false; + } + } + + if (pass) { + System.out.println("Success: " + getPageName() + ": Content test passed for column: " + columnName); + } + + return pass; + } + + private boolean checkValues(Object dataUIValue, Object dataJSONValue, Object dataIDUIValue, Logger logger, String columnName) { + if (!dataUIValue.equals(dataJSONValue)) { + String errMsg = "Failure: " + getPageName() + ": Incorrect " + columnName + " : " + dataUIValue + " in UI for " + getUniqueKeyName() + " : " + dataIDUIValue + ". Correct " + columnName + " is: " + dataJSONValue; + System.out.println(errMsg); + logger.severe(errMsg); + return false; + } + + return true; + } + + private void clickDropdown(WebDriver driver, int numOfItemsJSON) { + WebElement dropdown = driver.findElement(By.id("pageSize")); + dropdown.click(); + + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + List options = wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector(".ms-Dropdown-item"))); + + int selectedValue = Config.dropdownValues[0]; + + // the smallest dropdown value greater than numOfItemsJSON + for (int value : Config.dropdownValues) { + if (numOfItemsJSON < value) { + selectedValue = value; + break; + } + } + + System.out.println("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"))); + driver.navigate().refresh(); + Common.sleep(); + } + + private String getSelectedDropdownValue(WebDriver driver) { + WebElement dropdown = waitForElement(driver, By.id("pageSize")); + return dropdown.getText().trim(); + } + + private void testForAllText(WebDriver driver, Logger logger) { + for (String text : getColumnNames()) { + Common.checkTextPresent(driver, text, getPageName(), logger); + } + } +} + diff --git a/esp/src/test-ui/tests/framework/pages/ECLWorkUnitsTest.java b/esp/src/test-ui/tests/framework/pages/ECLWorkUnitsTest.java new file mode 100644 index 00000000000..b5837fb4d6b --- /dev/null +++ b/esp/src/test-ui/tests/framework/pages/ECLWorkUnitsTest.java @@ -0,0 +1,155 @@ +package framework.pages; + +import com.fasterxml.jackson.databind.ObjectMapper; +import framework.config.Config; +import framework.model.ECLWorkunit; +import framework.model.WUQueryResponse; +import framework.model.WUQueryRoot; +import framework.utility.Common; +import framework.utility.TimeUtils; +import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.testng.annotations.Test; + +import java.io.File; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Logger; + +public class ECLWorkUnitsTest extends BaseTableTest { + + @Test + public void testingECLWorkUnitsPage() { + testPage(); + } + + @Override + protected String getPageName() { + return "ECL Workunits"; + } + + @Override + protected String getPageUrl() { + return Common.getUrl(Config.ECL_WORK_UNITS_URL); + } + + @Override + protected String getJsonFilePath() { + return Common.isRunningOnLocal() ? Config.PATH_LOCAL_WORKUNITS_JSON : Config.PATH_GH_ACTION_WORKUNITS_JSON; + } + + @Override + protected String[] getColumnNames() { + return new String[]{"WUID", "Owner", "Job Name", "Cluster", "State", "Total Cluster Time", "Compile Cost", "Execution Cost", "File Access Cost"}; + } + + @Override + protected String[] getColumnKeys() { + return new String[]{"Wuid", "Owner", "Jobname", "Cluster", "State", "TotalClusterTime", "Compile Cost", "Execution Cost", "File Access Cost"}; + } + + @Override + protected String[] getColumnKeysWithLinks() { + return new String[]{"Wuid"}; + } + + @Override + protected String getUniqueKeyName() { + return "WUID"; + } + + @Override + protected String getUniqueKey() { + return "Wuid"; + } + + private List getCostColumns() { + return Arrays.asList("Compile Cost", "Execution Cost", "File Access Cost"); + } + + @Override + protected List parseJson(String filePath) throws Exception { + ObjectMapper objectMapper = new ObjectMapper(); + WUQueryRoot wuQueryRoot = objectMapper.readValue(new File(filePath), WUQueryRoot.class); + WUQueryResponse wuQueryResponse = wuQueryRoot.getWUQueryResponse(); + return wuQueryResponse.getWorkunits().getECLWorkunit(); + } + + @Override + protected Object getColumnDataFromJson(ECLWorkunit workunit, String columnKey) { + return switch (columnKey) { + case "Wuid" -> workunit.getWuid(); + case "Owner" -> workunit.getOwner(); + case "Jobname" -> workunit.getJobname(); + case "Cluster" -> workunit.getCluster(); + case "State" -> workunit.getState(); + case "TotalClusterTime" -> workunit.getTotalClusterTime(); + case "Compile Cost" -> workunit.getCompileCost(); + case "Execution Cost" -> workunit.getExecuteCost(); + case "File Access Cost" -> workunit.getFileAccessCost(); + default -> null; + }; + } + + @Override + protected Object parseDataUIValue(Object dataUIValue, String columnName, Object dataIDUIValue, Logger logger) { + if (getCostColumns().contains(columnName)) { + dataUIValue = Double.parseDouble(((String) dataUIValue).split(" ")[0]); + } else if (columnName.equals("Total Cluster Time")) { + long timeInMilliSecs = TimeUtils.convertToMilliseconds((String) dataUIValue); + if (timeInMilliSecs == Config.MALFORMED_TIME_STRING) { + String errMsg = "Failure: " + getPageName() + ": Incorrect time format for " + columnName + " : " + dataUIValue + " in UI for " + getUniqueKeyName() + " : " + dataIDUIValue; + System.out.println(errMsg); + logger.severe(errMsg); + return dataUIValue; + } + + return timeInMilliSecs; + } else if (dataUIValue instanceof String) { + dataUIValue = ((String) dataUIValue).trim(); + } + + return dataUIValue; + } + + @Override + protected Object parseDataJSONValue(Object dataJSONValue, String columnName, Object dataIDUIValue, Logger logger) { + if (columnName.equals("Total Cluster Time")) { + long timeInMilliSecs = (long) dataJSONValue; + if (timeInMilliSecs == Config.MALFORMED_TIME_STRING) { + String errMsg = "Failure: " + getPageName() + ": Incorrect time format for " + columnName + " in JSON for " + getUniqueKeyName() + " : " + dataIDUIValue; + System.out.println(errMsg); + logger.severe(errMsg); + return dataJSONValue; + } + + return timeInMilliSecs; + } + + return dataJSONValue; + } + + @Override + protected void sortJsonUsingSortOrder(String currentSortOrder, List workunitsJson, String columnKey) { + switch (currentSortOrder) { + case "ascending" -> ascendingSortJson(workunitsJson, columnKey); + case "descending" -> descendingSortJson(workunitsJson, columnKey); + case "none" -> descendingSortJson(workunitsJson, getUniqueKey()); + } + } + + @Override + protected String getCurrentPage(WebDriver driver) { + try { + WebElement element = waitForElement(driver, By.id("wuid")); + if (element != null) { + return element.getAttribute("title"); + } + } catch (NoSuchElementException e) { + return "Invalid Page"; + } + return "Invalid Page"; + } +} \ No newline at end of file diff --git a/esp/src/test-ui/tests/framework/setup/LoggerHolder.java b/esp/src/test-ui/tests/framework/setup/LoggerHolder.java new file mode 100644 index 00000000000..a62774a3533 --- /dev/null +++ b/esp/src/test-ui/tests/framework/setup/LoggerHolder.java @@ -0,0 +1,16 @@ +package framework.setup; + +import java.util.logging.Logger; + +public class LoggerHolder { + private static Logger logger; + + public static void setLogger(Logger logger) { + LoggerHolder.logger = logger; + } + + public static Logger getLogger() { + return logger; + } +} + diff --git a/esp/src/test-ui/tests/framework/setup/TestInjector.java b/esp/src/test-ui/tests/framework/setup/TestInjector.java new file mode 100644 index 00000000000..a075750a59e --- /dev/null +++ b/esp/src/test-ui/tests/framework/setup/TestInjector.java @@ -0,0 +1,30 @@ +package framework.setup; + +import org.testng.IInvokedMethod; +import org.testng.IInvokedMethodListener; +import org.testng.ITestResult; +import org.openqa.selenium.WebDriver; +import java.util.logging.Logger; + +public class TestInjector implements IInvokedMethodListener { + private final Logger logger; + private final WebDriver driver; + + public TestInjector(Logger logger, WebDriver driver) { + this.logger = logger; + this.driver = driver; + } + + @Override + public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { + if (method.isTestMethod()) { + LoggerHolder.setLogger(logger); + WebDriverHolder.setDriver(driver); + } + } + + @Override + public void afterInvocation(IInvokedMethod method, ITestResult testResult) { + // Optionally, clean up if necessary + } +} diff --git a/esp/src/test-ui/tests/framework/setup/WebDriverHolder.java b/esp/src/test-ui/tests/framework/setup/WebDriverHolder.java new file mode 100644 index 00000000000..d2887388db2 --- /dev/null +++ b/esp/src/test-ui/tests/framework/setup/WebDriverHolder.java @@ -0,0 +1,15 @@ +package framework.setup; + +import org.openqa.selenium.WebDriver; + +public class WebDriverHolder { + private static WebDriver driver; + + public static void setDriver(WebDriver driver) { + WebDriverHolder.driver = driver; + } + + public static WebDriver getDriver() { + return driver; + } +} diff --git a/esp/src/test-ui/tests/framework/utility/Common.java b/esp/src/test-ui/tests/framework/utility/Common.java new file mode 100644 index 00000000000..2fb12970a09 --- /dev/null +++ b/esp/src/test-ui/tests/framework/utility/Common.java @@ -0,0 +1,45 @@ +package framework.utility; + +import framework.config.Config; +import org.openqa.selenium.WebDriver; + +import java.time.Duration; +import java.util.logging.Logger; + +public class Common { + + public static void checkTextPresent(WebDriver driver, String text, String page, Logger logger) { + if (driver.getPageSource().contains(text)) { + String msg = "Success: " + page + ": Text present: " + text; + System.out.println(msg); + } else { + String errorMsg = "Failure: " + page + ": Text not present: " + text; + System.err.println(errorMsg); + logger.severe(errorMsg); + } + } + + public static void openWebPage(WebDriver driver, String url) { + + driver.get(url); + driver.manage().window().maximize(); + sleep(); + } + + public static void sleep() { + try { + Thread.sleep(Duration.ofSeconds(Config.WAIT_TIME_IN_SECONDS)); + } catch (InterruptedException e) { + System.err.println(e.getMessage()); + } + } + + public static boolean isRunningOnLocal() { + return System.getProperty("os.name").startsWith(Config.LOCAL_OS) && System.getenv("USERPROFILE").startsWith(Config.LOCAL_USER_PROFILE); + } + + public static String getUrl(String url) { + + return isRunningOnLocal() ? Config.LOCAL_IP + url : Config.GITHUB_ACTION_IP + url; + } +} diff --git a/esp/src/test-ui/tests/framework/utility/TimeUtils.java b/esp/src/test-ui/tests/framework/utility/TimeUtils.java new file mode 100644 index 00000000000..d15f72b2a13 --- /dev/null +++ b/esp/src/test-ui/tests/framework/utility/TimeUtils.java @@ -0,0 +1,63 @@ +package framework.utility; + +import framework.config.Config; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class TimeUtils { + private static final Pattern TIME_PATTERN = Pattern.compile( + "\\s*(\\d+)\\s+days\\s+(\\d+):(\\d+):(\\d+).(\\d+)|" + + "(\\d+):(\\d+):(\\d+).(\\d+)|" + + "(\\d+):(\\d+).(\\d+)|" + + "(\\d+).(\\d+)\\s*"); + + private static final long MILLISECONDS_IN_A_SECOND = 1000; + private static final long MILLISECONDS_IN_A_MINUTE = 60 * MILLISECONDS_IN_A_SECOND; + private static final long MILLISECONDS_IN_AN_HOUR = 60 * MILLISECONDS_IN_A_MINUTE; + private static final long MILLISECONDS_IN_A_DAY = 24 * MILLISECONDS_IN_AN_HOUR; + + public static long convertToMilliseconds(String time) { + Matcher matcher = TIME_PATTERN.matcher(time); + if (matcher.matches()) { + int days = 0; + int hours = 0; + int minutes = 0; + int seconds = 0; + int milliSeconds = 0; + + try { + if (matcher.group(1) != null) { // Matches d days h:m:s.s + days = Integer.parseInt(matcher.group(1)); + hours = Integer.parseInt(matcher.group(2)); + minutes = Integer.parseInt(matcher.group(3)); + seconds = Integer.parseInt(matcher.group(4)); + milliSeconds = Integer.parseInt(matcher.group(5)); + } else if (matcher.group(6) != null) { // Matches h:m:s.s + hours = Integer.parseInt(matcher.group(6)); + minutes = Integer.parseInt(matcher.group(7)); + seconds = Integer.parseInt(matcher.group(8)); + milliSeconds = Integer.parseInt(matcher.group(9)); + } else if (matcher.group(10) != null) { // Matches m:s.s + minutes = Integer.parseInt(matcher.group(10)); + seconds = Integer.parseInt(matcher.group(11)); + milliSeconds = Integer.parseInt(matcher.group(12)); + } else if (matcher.group(13) != null) { // Matches s.s + seconds = Integer.parseInt(matcher.group(13)); + milliSeconds = Integer.parseInt(matcher.group(14)); + } + } catch (NumberFormatException e) { + return Config.MALFORMED_TIME_STRING; + } + + return days * MILLISECONDS_IN_A_DAY + + hours * MILLISECONDS_IN_AN_HOUR + + minutes * MILLISECONDS_IN_A_MINUTE + + seconds * MILLISECONDS_IN_A_SECOND + + milliSeconds; + + } else { + return Config.MALFORMED_TIME_STRING; + } + } +}