hariselva | Feb. 26, 2020, 7:34 a.m.
- TestNG is one of the popular framework in the UI Automation.
- TestNG can be used for generic unit testing purpose.
- In this post, we discussed about using Maven parameters to TestNG test suites.
Sample pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<forkCount>0</forkCount>
<printSummary>true</printSummary>
<param>${param1}</param>
<param>${param2}</param>
<parallel>instances</parallel>
<threadCount>10</threadCount>
<properties>
<property>
<name>dataproviderthreadcount</name>
<value>10</value>
</property>
<property>
<name>reporter</name>
<value>config.ListenerTestReporter</value>
</property>
</properties>
</configuration>
</plugin>
Sample TestNG.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="AUTOMATION" parallel="instances" data-provider-thread-count="10" thread-count="10" verbose="2">
<listeners>
<listener class-name="config.ListenerTest"></listener>
</listeners>
<test name="Custom_test">
<parameter name = "param1" value="${param1}"/>
<parameter name = "param2" value="${param2}"/>
<classes>
<class name="${packagename.TestPlanName}">
<methods>
<include name="${testMethod}"></include>
</methods>
</class>
</classes>
</test> <!-- Automation -->
</suite> <!-- Suite -->
Maven command to use:
mvn test -Dparam1= -Dparam2= Dtest=packagename.TestPlanName#testMethod
Maven command passes the parameters param1 and param2 to the TestNG.xml file using pom.xml maven surefire plugin. In this way, we shall control the parameters to be used in TestNG framework from the maven commands.
Maven can be integrated into any CI/CD tool. The above scenarios help us in controlling the Test automation parameters outside of the project.