Pass parameter values to testng.xml using pom.xml

4,503 views
Skip to first unread message

ct.g...@gmail.com

unread,
Jul 30, 2018, 3:58:18 PM7/30/18
to testng-users
Hi,

I want to pass parameters from maven goal to testng.xml. Suggest me how to do this. I have tried below code but no luck.

Pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<automation.name>${automation.name}</automation.name>
<browser.name>${browser.name}</browser.name>
<browser.version>${browser.version}</browser.version>
<environment>${environment}</environment>
<platform.name>${platform.name}</platform.name>
<base.url>${base.url}</base.url>
</systemPropertyVariables>
<parallel>methods</parallel>
<threadCount>5</threadCount>
<suiteXmlFiles>
<suiteXmlFile>${testset}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>

testng.xml
<test name="First Test" >
<parameter name="automationName" value="${automation.name}"/>
<parameter name="browser" value="${browser.name}"/>
<parameter name="browserVersion" value="${browser.version}"/>
<parameter name="platformName" value="${platform.name}"/>
<parameter name="environment" value="${environment}"/>
<classes>
<class name="com.salesforce.stepdefinitions.HomePage_Steps" />
</classes>
</test>

Maven goal:
clean compile test -Dtestset=testng.xml -Dbase.url=https://login.salesforce.com -Dautomation.name=BDD_Demo -Dplatform.name="windows 7" -Dbrowser.name=chrome -Dbrowser.version="59.0" -Denvironment=local

When execute above maven goal i can able to get value using System.getProperty() but the property is not passing from pom.xml to testng.xml.

System.out.println(automationName);
System.out.println(browser);
System.out.println(platformName);
System.out.println(environment);
System.out.println(System.getProperty("testset"));
System.out.println(System.getProperty("automation.name"));
System.out.println(System.getProperty("browser.name"));
System.out.println(System.getProperty("browser.version"));
System.out.println(System.getProperty("environment"));
System.out.println(System.getProperty("platform.name"));
System.out.println(System.getProperty("base.url"));

O/P:
${automation.name}
${browser.name}
${platform.name}
${environment}
testng.xml
BDD_Demo
chrome
59.0
local
windows 7
https://login.salesforce.com

Here instead of ${automation.name} it should print BDD_Demo.

Thanks,
Raju

Krishnan Mahadevan

unread,
Jul 30, 2018, 10:54:24 PM7/30/18
to testng...@googlegroups.com

TestNG has the ability to visualize a parameter name as a JVM argument as well.

 

So from your example:

 

    <parameter name="automationName" value="${automation.name}"/>
    <
parameter name="browser" value="${browser.name}"/>
    <
parameter name="browserVersion" value="${browser.version}"/>
    <
parameter name="platformName" value="${platform.name}"/>
    <
parameter name="environment" value="${environment}"/>

All the above can be looked at as JVM arguments. So you could just do -DautomationName=foo -Dbrowser=firefox -DbrowserVersion=60 -DplatformName=WINDOWS -Denvironment=QA

 

For more details please take a look at my blog post: https://rationaleemotions.wordpress.com/2017/09/29/dynamic-parameterization-in-testng/

 

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages