Sample Selenium Framework with TestNG[ 2024 ]
Sample Selenium Framework with TestNG
Designing a Selenium automation framework requires a well-defined approach that considers both short-term and long-term goals to maximize the benefits of automation. The main advantages of an automation framework include increased test coverage, improved efficiency of test resources, enhanced quality and reliability of the software application under test (AUT), and better maintainability of the automation code.
An effective web application automation using Selenium is with the Page Object Model. Page objects offer minimum changes to the test scripts when the application under test code changes.
What is a Page Object?
A page object wraps an HTML application page with an automation-specific API ( application programming interface ), allowing you to manipulate page elements without knowing the test application HTML code. To learn more about Page objects, see the below links:
TestNG Framework
TestNG is a test framework usually for large-scale end-to-end testing needs. It uses Java, and test methods are written using @Test annotation.
Automation Process
Most companies adopt Agile testing techniques to achieve test automation. User stories provide most of the input for automation tests. Automation Engineers work closely with the Manual QA and Development teams to derive automation scenarios and testing scope.
What needs to be automated?
Plan to automate repeated tests and replace important tests that are difficult to execute manually. We might ask these questions about what needs to be automated.
- Is the scenario repeatable?
- Does it need manual intervention?
- Are test Data available?
- Is the test a candidate for the Regression test?
- Is the expected result clear for the Test scenario?
Sample automation code flow
We can divide the effort into two main parts concerning the Selenium Automation Framework.
- Framework development
- Test Scripts Authoring using the framework.
The framework development effort involves developing Page Objects, common functions, Test configuration, handling test data, logging and reporting utilities, and any functionality common to entire scripts. Test scripts are developed based on test scenarios provided and identified by the Manual team.
Automation Tools generally required for our sample automation framework:
Automation Code Repository | Perforce or GitHub or SVN |
Framework | TestNG Framework |
Tools | Eclipse IDE or IntelliJ IDE, Selenium WebDriver, TestNG API, Surefire Maven Plugin, Log4J, JXL( Excel Java API ), Jackson mapper, SnakeYAML, etc |
Language | Java 1.8 |
Build Tool | Maven, Gradle Tool. |
Continuous Integration | Jenkins, CircleCI, etc. |
Tools
- https://www.testingdocs.com/downloading-and-extracting-eclipse-ide/
- https://www.testingdocs.com/testng-framework-basics/
- https://www.testingdocs.com/getting-started-with-git-version-control/
- https://www.testingdocs.com/getting-started-with-jenkins/
- https://www.testingdocs.com/what-is-maven/
The sample framework, which contains major components of our sample selenium automation framework using TestNG, is shown below. The figure illustrates the tasks involved from the collection of automation scenarios to the end of report generation.
Sample Selenium framework diagram
A sample automation framework with major components.
See also
For more information, please visit Selenium’s official website: