Pass parameter values to testng.xml using pom.xml

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Pass parameter values to testng.xml using pom.xml

ct.gallop
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

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Pass parameter values to testng.xml using pom.xml

⇜Krishnan Mahadevan⇝

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/

 

From: <[hidden email]> on behalf of <[hidden email]>
Reply-To: <[hidden email]>
Date: Tuesday, July 31, 2018 at 1:28 AM
To: testng-users <[hidden email]>
Subject: [testng-users] Pass parameter values to testng.xml using pom.xml

 

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

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.