This is a test automation framework for web applications on different browsers like Google Chrome, Mozilla Firefox, Microsoft Edge, Internet Explorer and Safari in real-time. It provides rich features like Test Execution, Test Reporting, and Test details sharing via mail. The automation framework includes 170+ pre-built keywords using which an Automation Engineer can easily perform the web automation.
Steps to develop and execute automation scripts using snj-selenium-java
Manage TestRunner class
Once the TestRunner class ready under snj.selenium.runner package, you can use below code snippet in TestRunner class:
@Listeners(AutomationReport.class)
public class TestRunner extends AutomationEngine {
@BeforeClass
@Parameters({ "browserName", "gridIP", "gridPort" })
public void setup(String browserName, String gridIP, String gridPort) throws Exception {
startBrowser(browserName, gridIP, gridPort);
}
@AfterSuite
public void tearDownMethod() throws AutomationException, InterruptedException {
WebActions webObj = new WebActions();
webObj.closeBrowser(driver);
}
}
Manage Test Suite Class
You can create multiple test suite classes under snj.selenium.testcases package, you can use below code snippet as sample test case in test suite class:
public class SampleTest extends TestRunner {
public SampleTest() throws AutomationException {
super();
}
@Test(enabled = true)
public void TC001_sampleTestCase() throws AutomationException {
new WebActions().loadWebApplication(driver, "https://www.google.com");
new UIActions().type(driver, SampleObjects.txt_searchbox, "JourneyOfQuality");
new AutomationReport().trackSteps("Data Entered");
}
}
Manage Test Helper Class
You can create multiple test helper classes under snj.selenium.testhelpers package. Test helper class can hold the actual automation step flow based on the application feature. Test helper methods should be re-usable in other test suite classes. Once you create the methods in test helper class, you can call those methods in test suite classes.
Manage Test Object Class
You can create multiple test object classes under snj.selenium.testobjects package. Test Object class can hold the object locator values like XPath, Id etc. These object creation based on your application page/screen. You can use the objects in test helper class to perform the actions on the object. Following is a sample snippet:
public class SampleObjects {
public static String txt_searchbox = "//input[@title='Search']";
}
Manage testng.xml
You can use the following code in testng.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Execution for Test Suites">
<parameter name="browserName" value="chrome" />
<parameter name="gridIP" value="xxx.xxx.xxx.xxx" />
<parameter name="gridPort" value="xxxx" />
<classes>
<class name="snj.selenium.testcases.SampleTest" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
NOTE: If you need run on different browsers, you can mention firefox or edge or ie or safari or headless for the browserName parameter in the above testng.xml code. If you need to run as Selenium Grid mode, just specify the values for gridIP and gridPort. For local execution, you just leave gridIP and gridPort as blank but need the browserName parameter value. For more about Selenium Grid setup, please visit https://journeyofquality.com/2022/01/26/a-variant-selenium-grid-4/
Perform Lighthouse Audit
This automation framework supports the lighthouse audit on the website with different categories such as performance, accessibility, SEO, best practices, and PWA. You can use startLighthouseAudit keyword of the UtilityActions class. Once the audit is completed the framework will generate the audit report in the \Reports\Lighthouse_Audit folder of the project structure. The prerequisites for the Lighthouse audit is to install the lighthouse node module package on your system. For more details about Lighthouse setup, please visit https://journeyofquality.com/2021/12/21/turn-on-your-lighthouse/. Below is the sample code for reference:
new UtilityActions().startLighthouseAudit(driver.getCurrentUrl(), "performance,seo", "no");
Perform Accessibility Testing
This automation framework supports the accessibility testing on website to track the violations, violation impact, and help details to solve the violations. You can use startAccessibilityAudit keyword of the UtilityActions class in the test suite class to start the track violations. Once the execution is completed the framework will generate the accessibility test summary report in the \Reports\Accessibility_Audit\Summary folder of the project structure. In addition to the summary report, there are detailed text and JSON reports will generate in the \Reports\Accessibility_Audit\Details folder of the project structure.
Collect Page Load Performance
This automation framework support to collect the page load time for a better performance tracking of an application. You can use collectLoadTime keyword of the UtilityActions class in the test suite class to collect the page load time. Once the execution is completed the framework will generate the performance test summary report in the \Reports\Performance_Audit folder of the project structure.
Image Comparison
This automation framework support to compare the actual image against the expected image at runtime. You can use compareImages keyword of the ValidationActions class in the test suite class to compare the images. Once the execution is completed the framework will generate the image comparison report in the \Reports\Image_Comparision folder of the project structure. More details at https://journeyofquality.com/2023/01/13/image-comparison-during-automation/
Video Recording
This automation framework support to generate the video recording of the automation workflow. You can use startRecording keyword of the UtilityActions class in the test suite class to start the recording and stop the recording by using the keyword stopRecording of the UtilityActions. Once the execution is completed the framework will generate the video report in the \Reports\Automation_Videos folder of the project structure.
I hope this automation framework will help to kickstart your automation scripting from the base level.
Get your latest releases from https://github.com/sanoj-s/snj-selenium-java/releases
make it perfect!