Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

maven

testng

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 ?

like image 908
Manju_Asthuthe Avatar asked May 10 '18 06:05

Manju_Asthuthe


People also ask

Can we run TestNG xml via command prompt?

xml file via command line allows user to run multiple testng xml files simultaneously. Before running a testng. xml suite through the command prompt, we need to compile our project code. We can find the compiled code by eclipse under a folder named “bin” inside the corresponding java project.


2 Answers

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

like image 62
Krishnan Mahadevan Avatar answered Oct 11 '22 10:10

Krishnan Mahadevan


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);
like image 25
Kovacic Avatar answered Oct 11 '22 09:10

Kovacic