Grill
Grill

Reputation: 21

MVN Selenium Testng -- how to pass parameters from command line to testsuite.xml via pom.xml

I have a Selenium project that uses Maven+Testng. I pass certain parameters to a particular profile in pom like so --

mvn -PprofileName -Dparam1=%p% -Dparam2=%q% -Dparam3=%r% test

This profile in turn references a particular xml file like so --

<suiteXmlFiles>
                                  <suiteXmlFile>C:\path\to\xml\file\testsuite.xml</suiteXmlFile>
</suiteXmlFiles>

Now, the parameters get passed just fine from the command line to the pom and it even opens the testsuite.xml and runs all the tests in it. However, this works only if I have the said paramters hardcoded in the testsuite.xml file.

HOW do I ensure that these parameters get transferred over to the testsuite.xml from the pom? I've tried something like below, but it doesn't work (i didn't have any high hopes that it would work, but I tried anyway)

<parameter name="param1"  value="$p" />
<parameter name="param2"  value="$q" />
<parameter name="param3"  value="$r" />

Any help would be greatly appreciated. Thanks.

Upvotes: 2

Views: 4028

Answers (1)

niharika_neo
niharika_neo

Reputation: 8531

Here's one way of doing this

You can pass in mvn test -Dcustomproperty=yourvalue and access it via System.getProperty("customproperty") in your code.

Upvotes: 2

Related Questions