Request a Call Back
X
Fields marked with an * are required
Testng Maven Dependency - How to Execute testng.xml - Habilelabs

Apache Maven is a Build Automation tool that preferred to be used over Java projects. It is a robust project management tool based upon POM (Project Object Model). It uses a surefire plugin to execute the TestNG.xml file. It can also handle profiling. When we use Maven, there is no need to download JARs. It downloads JARs (by default) by defining its dependency in the POM.xml file. 

Table Of Contents to Execute TestNG File:

  • Project Hierarchy
  • TestScript Content
  • TestNG.xml file
  • POM.xml file
  • Execute Test Script

Project Hierarchy-

Maven Project Hierarchy contains test script in the “src/test/java” folder, dependency Jars in “Maven Dependencies”, Reports in “target” folder and POM.xml & TestNG.xml files in the root directory. The Project Hierarchy is given below:

TestScript Content-

Testing steps are written in TestScript. In the above-given hierarchy, AppTest.java is the TestScript. For Coding, the TestNG third party framework is used. Junit can also be used at the place of TestNG. TestScript AppTest.java will open “www.gmail.com” in the browser.

TestNG.xml file-

To execute this TestScript written in the ‘TestNg’ framework, we use the TestNG.xml file. In this file, we define suite, test, and class. We can also define groups in which we define include-group and exclude-group. TextNG.xml file is given below:

POM.xml file-

A Page Object Model or POM is the fundamental unit of work in Maven. It is an XML file that has properties, dependencies, plugins and project information. All required JAR files can be downloaded by mentioning their dependencies. For compiling the code, we use a maven compiler plugin and for execution, we use maven surefire plugin. You can find the properties, dependencies, plugins and project information below which will be written in the POM.xml file to execute TestNG script.

#Define project in POM.xml File:

#Define Properties in POM.xml:

#Define Dependencies in POM.xml:

#Define maven-surefire-plugin, maven-compiler-plugin and testng.xml in POM.xml:

As well as you can protractor is an end-to-end testing framework for web applications and built on top of WebDriverJS

Execute Test Script:

For executing TestScript, right-click on it and it will open a menu. Now, click on ‘Run As’ and then select ‘Run Configuration’. Please see the image below:

Path: testfile>Run As>Run Configurations-

Run Configurations:

The Run configuration UI will open. We will select “Maven build “Option and click on the icon “New Launch Configuration” then Maven configuration will appear. We will select the Base Directory from the workspace then write the Goals “clean test”. Now, select current JRE from JRE Tab and click on the ‘Run’ button as shown in the image below:

Conclusion:

So, you can see that test script Testing with Apache Maven is quite easy. In case, you are having any trouble regarding the same, do let me know in the comment box provided below. Also, share it with your friends and colleagues and stay connected with us. You can contact us (Habilelabs – premier software development company) which provides high-quality web app development and mobile app development services.