How to pass test data from maven goal.

How to pass Test Data in @Parameters Annotation From maven Goal

In below example, @Parameter annotation has two keywords, those keyword value we are passing from maven goal such as Dbrowser and Dskill.

One more parameter, we are passing from maven gole which is the xml file name which we are going to execute as Dfilename.

Java Code-

public class Testing_parameterFromMavenGoal {
@Parameters({"browser","skill"})
@Test
public void testNGParameterFromMavenGoal(String browser, String skill)
{
System.out.println("The Parameter is :-"+browser+":"+skill);
}
}

POM.xml

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${fileName}.xml</suiteXmlFile> 
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
  

Maven Goal-

    
test -Dskill=Selenium -Dbrowser=Chrome -DfileName=parameter

XML Code-

    
<?xml version="1.0" encoding="UTF-8"?>
<suite name="parameter">
<test name= "param">
<classes>
<class name="org.Testngpro.Testing_parameterFromMavenGoal"></class>
</classes>
</test>
</suite>

Outcome-


T E S T S
-------------------------------------------------------
Running TestSuite
The Parameter is :-Chrome:Selenium
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.739 sec - in TestSuite

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

You Can Also View Related Topics

No comments:

Post a Comment