In today’s newsletter we are going to discuss
Introduction
Maven & TestNG Project Setup
Implement Page Object Model (POM)
Configure TestNG
Run Tests
GitHub Repo
Introduction
Test Automation Framework helps software testing teams streamline the test automation process, improve test efficiency, and enhance test coverage.
An effective test automation framework should be designed to meet specific testing needs, promote code reusability, and ensure the reliability of automated tests.
Prerequisite
In this newsletter, we will be using:
Java as the programming language
TestNG as the assertion framework
Maven as the build automation tool
Selenium WebDriver as the browser automation tool
Eclipse as the IDE
Maven & TestNG Project Setup
Click on “Create New Project” and select “Maven Project”.
Filter by “maven-archetype-quickstart” and select the one with groupId “org.apache.maven.archetypes” and click “Finish”.
Basic folder structure should be ready
Convert Project to TestNG project
Add TestNG and Selenium as dependency
Implement POM
The Page Object Model (POM) is a design pattern commonly used in Selenium automation to enhance test script maintainability and reusability.
In the POM, each web page is represented as a separate class.
Adding Base Classes
1. Base Page
We will first create a BasePage class. All page object classes will extend the BasePage, thus inheriting all the base methods.
Our BasePage class will have a constructor which takes a WebDriver object to initialize a driver object.
2. Base Test
The BaseTest class sets up and tears down the WebDriver using the “@BeforeSuite” and “@AfterSuite” annotations from TestNG.
The WebDriver is initialized in the ‘beforeSuite’ method and closed in the ‘afterSuite’ method.
Adding Page Objects
1. LoginPage
By extending base page in your page object class, you can access these common elements and methods without duplicating code.
2. LoginTest
The LoginTest class extends BaseTest, which means it inherits the setup and teardown methods defined in BaseTest. This ensures that a new WebDriver instance is created before the test and closed afterward.
Configure TestNG
Create a TestNG XML configuration file (e.g., testng.xml) to define your test suite and test classes. You can learn more about TestNG here.
Run Tests
Run your tests using the following Maven command.
GitHub Repository
You can find code of this newsletter issue at this GitHub Repository
“The only thing standing between you and outrageous success is continuous progress” - Dan Waldschmidt
Let’s Connect on Social Media
Connect with me on LinkedIn (5.2K+ Followers) and Twitter.
Well explained really......
Very well explained about the Test Automation framework...from the set-up to adding dependencies and with perfectly examples..... everytime I go through Your newsletter, I learn something new as well as brush up my knowledge because you made things simpler which helps us to understand easily and more in depth...... I can say that this is the best newsletter about testing/Java-selenium I am following 💯.... Thanks for sharing amazing newsletter 👏