how to pass parameter to testng.xml from command line with maven
Asked Answered
S

3

9

I am running appium test using testng want to pass app path to desired capabilities as parameter to testng.xml file how can i do this from command line with maven ?

Scalf answered 10/5, 2018 at 6:11 Comment(0)
C
7

Lets say you have a suite xml file which looks like below

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="sample_suite" verbose="1" parallel="false" thread-count="2">
  <test name="sample_test">
    <parameter name="name" value="Krishnan"/>
    <classes>
      <class name="ParameterisedSampleTestClass" />
    </classes>
  </test>
</suite>

And you would like to change the value of the parameter name to a different value other than Krishnan (which is what is defined in the suite xml file)

You basically do this by passing the JVM argument -Dname=John.

TestNG by default supports changing parameter values and accepts values at run via JVM arguments.

You just need to use the same name as your parameter name, for the JVM argument.

You can find more details in my blog post here

Cathepsin answered 10/5, 2018 at 8:36 Comment(1)
Thanks Krishnan :)Scalf
J
2

You can achieve this by providing JVM argument as Krishnan mention in post bellow and nice blog in link:

mvn -Dbrowser="chrome" test

and gather them in your code (eg. java) via

String broswser = System.getProperty(browser);

and then turn into desired capabilities afterwards:

DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapability.setBrowserName(browser);
Jura answered 10/5, 2018 at 9:48 Comment(2)
Thank you KovacicScalf
Glad I could help.Jura
A
0

The idea of using the -D JVM switch to send the parameter works great. However, it will not override a parameter that is defined in your testng.xml. You must remove it from the testng.xml for the JVM switch to pass it to your code.

Amphibolite answered 16/1 at 15:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.