Let’s face it, creating an automation framework from scratch is considered to be the most important aspect of automation.
If you’re new to the world of automation testing, it can be hard for you to create an automation framework for achieving your desired test automation goals.
In this post, we’re going to learn exactly how to create and implement an automation framework for nearly any type of automation project.
By the end of this article, you should feel less overwhelmed and more confident about how you can create and use a complete Selenium with Java automation framework.
So, let’s begin.
Features & Capabilities of the Framework
- Java – It uses Java programming language.
- TestNG – It uses TestNG as a testing framework. You can learn more about TestNG from our – TestNG tutorial.
- Maven-based – It will be maven-based. So all the dependencies will be in a POM file and the test suite can be triggered using maven commands.
- Hybrid Framework – It will be a hybrid framework with a combination of the modular and data-driven framework.
- Page Object Model – The framework will use the Page Object Model design pattern in Selenium.
- Page Factory – It will use page factory implementation of the page object model in Selenium.
- Screenshot on failure – The framework will have the capability to capture screenshots in case of failed tests.
- Test data in Excel – The framework will have a utility class that will read test data from an excel file.
- Logging – Log4j is used for logging.
Demo site – I will be using the Saucedemo website for the sample test scripts.
Structure of the framework
Let’s talk about the structure of the framework and the different files & folders in the framework.
TestBase.java inside Base Package
This is the base file that performs set-up and tear-down operations like – browser configurations, implicit and explicit waits handling, cookies deletion, etc. Each test class must extend this class.
Page Classes inside Pages Package
The ‘pages’ package contains all the page classes. Each page class contains the web elements and actions that can be performed on those classes.
Test Classes inside Test Package
The ‘test’ package contains all the test classes. Each test class extends the TestBase.java class and contains the test scripts.
In the util package, we can have all the utilities e.g. in this framework, I have an ExcelUtil file that reads data from an excel file and converts it into 2D array.
Inside the resources folder, we can have different configuration files like log4j2.xml file.
The logs folder contains all the log files generated while running the test scripts.
The testData folder contains the test data for the test scripts e.g. we can have credentials and other sets of test data that are used by our test scripts.
The pom.xml contains all the dependencies used in the project.
TestNG.xml file contains the testNG configurations using which we can run a particular method, group, or test class and at the same time configure the tests to run in parallel.
Download the Framework
You can download the framework from Github – ArtOfTestingAutomationFramework and import it as a maven project.
Feel free to use this Selenium with Java automation framework in your project. For any queries, you can connect with me via Linkedin.
Kuldeep is the founder and lead author of ArtOfTesting. He is skilled in test automation, performance testing, big data, and CI-CD. He brings his decade of experience to his current role where he is dedicated to educating the QA professionals. You can connect with him on LinkedIn.