- Based on POM design pattern
- Data Driven Testing approach
- Used for functional UI testing
- Gradle build tool 7.4.2
- Java 17 (if you are using Windows set
JAVA_HOME
environment variable to point to jdk root folder e.g.C:\Program Files\Java\jdk-17.0.2
)
- Dependencies are managed by Gradle and they are declared in
build.gradle
in root project folder - Selenium = '4.1.3' - For browser automation
- WebDriverManager = '5.1.0' - Download, setup, and maintenance of the drivers required by Selenium WebDriver
- TestNG = '7.5' - Testing framework on which the tests are being executed
- Apache POI = '5.2.2' - Library for parsing and working with Excel files in Java
- log4j = '2.17.2' - Logging library
src/test/java/containers
used for storing test session data and instantiated page object modelssrc/test/java/helpers
generic functions, annotation processors and UI helper functionssrc/test/java/poms
page object models representing actual web pagessrc/test/java/providers
data providers for Data Driven Testing approachsrc/test/java/runners
TestNG runners
- Before running tests make sure you have entered correct test parameters in
src/test/resources/testParameters.xlsx
Excel file (supported browser are eitherchrome
orfirefox
) - After providing test parameters then you can enter keywords for each search engine in
src/test/resources/testData.xlsx
Excel file (note that Excel sheet name represents search engine) - If you have locally set up gradle binary then you can
cd
into project root and run the tests by commandgradle clean test
- If you do not have installed gradle binary locally then you can
cd
into project root folder and usegradlew
(gradle wrapper) instead./gradlew clean test
- Logs can be found in
/logs/SearchEngine.log
file - It will be generated after test execution
- Common results will be logged only if the same keyword is used for both search engines
- Note that if you execute tests in a row few times it will append results to a log file
- Framework was developed in a way that allows new contributors to a project to easily add tests without any overlapping or potential conflicts
- Example workflow (adding a new search engine) would be the following:
- Add search engine test data in
src/test/resources/testData.xlsx
file - Add data provider class in
src/test/java/providers
e.g.NewSearchEngineDataProvider.java
public class NewSearchEngineDataProvider {
@DataProvider(name = "NewSearchEngine")
public static Object[][] getDuckDuckGoKeywordsData() {
// NewSearchEngine is sheet name in testData.xlsx file
return ExcelHelper.getTestData("NewSearchEngine");
}
}
- Add new Page Object Model class in
src/test/java/poms
package e.g.NewSearchEngineHomePage.java
(which extendsBasePageObject.java
class) and all corresponding methods to that particular web page
public class NewSearchEngineHomePage extends BasePageObject {
@FindBy(css = "input[name=\"q\"]")
WebElement searchInput;
public NewSearchEngineHomePage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
public void searchByKeyword(String keyword) {
}
}
- Add newly created pom to a
src/test/java/containers/PomContainer.java
class
public class PomContainer {
public GoogleHomePage googleHomePage;
public DuckDuckGoHomePage duckDuckGoHomePage;
public NewSearchEngineHomePage newSearchEngineHomePage;
public PomContainer(WebDriver driver) {
this.googleHomePage = annotatePOM(new GoogleHomePage(driver));
this.duckDuckGoHomePage = annotatePOM(new DuckDuckGoHomePage(driver));
this.newSearchEngineHomePage = annotatePOM(new NewSearchEngineHomePage(driver));
}
}
- Add new test runner class in
src/test/java/runners
package e.g.NewSearchEngineTestRunner.java
and it will extendHooks.java
class
public class NewSearchEngineTestRunner extends Hooks {
@Test(dataProvider = "NewSearchEngine", dataProviderClass = NewSearchEngineDataProvider.class)
public void searchNewSearchEngine(String keyword) {
pages.newSearchEngineHomePage.searchByKeyword(keyword);
}
}
- Final step add
<class name="runners.NewSearchEngineTestRunner" />
insrc/test/testng.xml
file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="All Test Suite">
<test verbose="2" preserve-order="true" name="/home/mint/JavaProjects/AutomationFramework/src/test">
<classes>
<class name="runners.GoogleTestRunner" />
<class name="runners.DuckDuckGoTestRunner" />
<class name="runners.NewSearchEngineTestRunner" />
</classes>
</test>
</suite>