How to override testNg suite level parameter values through command line?

586 views
Skip to first unread message

Gagandeep Singh

unread,
Jan 28, 2020, 7:01:35 PM1/28/20
to testng-users
<suite name ="Smoke Suite" >
<parameter name="cloudUsername" value="Demo"/>
<test name ="Smoke Tests" verbose ="2">
<classes>
<class name ="it.org.techtime.cloud.confluence.apps.googlemapsembed.selenium.smoke.test.SmokeTest"/>
</classes>
</test>
</suite>

In the above suite file I have declared "cUserName" at the suite level and when I try to override the value through command-line using the following command atlas-mvn test -PseleniumTestsStandalone -DcUserName=RANDOM, the value doesn't changes. Can anyone please explain why? and how I can achieve this without declaring the parameter at test level!

TIA

⇜Krishnan Mahadevan⇝

unread,
Jan 30, 2020, 11:50:36 PM1/30/20
to testng...@googlegroups.com
Am going to conveniently assume that there are no typos here ?

Your suite file has this defined:

<parameter name="cloudUsername" value="Demo"/>

So you should be passing it as -DcloudUsername=RANDOM

But your post says you are using something else.


So its not clear what is not working and working here. Please elaborate what works and what doesnt work for you.

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 Scribblings @ https://rationaleemotions.com/


--
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 testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/77e2bb0f-b4c4-41b0-bc26-678e1b215894%40googlegroups.com.

Gagandeep Singh

unread,
Feb 2, 2020, 4:30:35 PM2/2/20
to testng-users
Sorry my bad. I apologise for the typo. The typo is in the question not in actual script. -DcloudUsername=RANDOM this is exactly How I'm running the code on my side. There is no type in actual post (sorry, can't edit the post). It seems like a bug to me. I am surprised as well that why its not possible to override suite level parameter and yes I have already gone through your article, thank you so much for that. I followed your article to implement the same. Everything works fine on test level or class level parameter tag but not at suite or may be its my configuration. Can someone please try this and confirm the same? 

TIA

On Friday, January 31, 2020 at 5:50:36 PM UTC+13, Krishnan Mahadevan wrote:
Am going to conveniently assume that there are no typos here ?

Your suite file has this defined:

<parameter name="cloudUsername" value="Demo"/>

So you should be passing it as -DcloudUsername=RANDOM

But your post says you are using something else.


So its not clear what is not working and working here. Please elaborate what works and what doesnt work for you.

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 Scribblings @ https://rationaleemotions.com/


On Wed, Jan 29, 2020 at 5:31 AM Gagandeep Singh <singh....@gmail.com> wrote:
<suite name ="Smoke Suite" >
<parameter name="cloudUsername" value="Demo"/>
<test name ="Smoke Tests" verbose ="2">
<classes>
<class name ="it.org.techtime.cloud.confluence.apps.googlemapsembed.selenium.smoke.test.SmokeTest"/>
</classes>
</test>
</suite>

In the above suite file I have declared "cUserName" at the suite level and when I try to override the value through command-line using the following command atlas-mvn test -PseleniumTestsStandalone -DcUserName=RANDOM, the value doesn't changes. Can anyone please explain why? and how I can achieve this without declaring the parameter at test level!

TIA

--
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 testng...@googlegroups.com.

⇜Krishnan Mahadevan⇝

unread,
Feb 2, 2020, 11:32:38 PM2/2/20
to testng...@googlegroups.com
I looked at the codebase. TestNG reads the parameter values from JVM arguments if and only if it finds no value in the suite xml file.
So for your case, you would need to remove the reference of 

<parameter name="cloudUsername" value="Demo"/>

from your suite file and then try again.

To ensure that one is able to alter parameters all the time from JVM arguments (irrespective of whether it was defined or not), I have created an issue https://github.com/cbeust/testng/issues/2238 and also raised a PR to fix this.

The fix should be available in the next upcoming release of TestNG (viz., 7.2.0)

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 Scribblings @ https://rationaleemotions.com/

To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/fb9b0919-0710-4434-bbb0-caadc6bf67a8%40googlegroups.com.

Gagandeep Singh

unread,
Feb 6, 2020, 9:12:46 PM2/6/20
to testng-users
Thank you for your response Krishnan. Just for your information, its possible override the parameter through command line if its declared under the test or class tag in suite.xml file but just not possible if it's declared under suite tag.

<suite name ="Smoke Suite" >
    <parameter name="cloudUsername" value="Demo"/>    You CANT override tis value through command line, remove this tag to override the value.
    <test name ="Smoke Tests" verbose ="2">
     <parameter name="cloudUsername" value="Demo1"/>    You CAN override tis value through command line even if its declared
        <classes>
<class name ="it.org.techtime.cloud.confluence.apps.googlemapsembed.selenium.smoke.test.SmokeTest"/>
            <parameter name="cloudUsername" value="Demo2"/>    You CAN override tis value through command line even if its declared
</classes>
</test>
</suite>


 

On Monday, February 3, 2020 at 5:32:38 PM UTC+13, Krishnan Mahadevan wrote:
I looked at the codebase. TestNG reads the parameter values from JVM arguments if and only if it finds no value in the suite xml file.
So for your case, you would need to remove the reference of 

<parameter name="cloudUsername" value="Demo"/>

from your suite file and then try again.

To ensure that one is able to alter parameters all the time from JVM arguments (irrespective of whether it was defined or not), I have created an issue https://github.com/cbeust/testng/issues/2238 and also raised a PR to fix this.

The fix should be available in the next upcoming release of TestNG (viz., 7.2.0)

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 Scribblings @ https://rationaleemotions.com/


Reply all
Reply to author
Forward
0 new messages