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 ?
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
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);
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.
© 2022 - 2024 — McMap. All rights reserved.