Selenium with Java Automation Framework

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

  1. Java – It uses Java programming language.

  2. TestNG – It uses TestNG as a testing framework. You can learn more about TestNG from our – TestNG tutorial.

  3. 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.

  4. Hybrid Framework – It will be a hybrid framework with a combination of the modular and data-driven framework.

  5. Page Object Model – The framework will use the Page Object Model design pattern in Selenium.

  6. Page Factory – It will use page factory implementation of the page object model in Selenium.

  7. Screenshot on failure – The framework will have the capability to capture screenshots in case of failed tests.

  8. Test data in Excel – The framework will have a utility class that will read test data from an excel file.

  9. 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.

Selenium with Java automation 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.

Util Package

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.

Resources folder

Inside the resources folder, we can have different configuration files like log4j2.xml file.

Logs folder

The logs folder contains all the log files generated while running the test scripts.

TestData folder

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.

Pom.xml file

The pom.xml contains all the dependencies used in the project.

TestNG.xml

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.

Queries

Feel free to use this Selenium with Java automation framework in your project. For any queries, you can connect with me via Linkedin.


Leave a Comment