Specifying "parameter" as parameter from command line.

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Specifying "parameter" as parameter from command line.

Tarun Kumar-4
I have a parameter - <parameter name="appURL" value="http://www.gutegutscheine.de/" />

Which is used for test execution.

1. Is it possible to have it passed from command line while using testng comnnad line execution? I noticed command line parameter and the one available with ant but could not find it.
2. Many of my classes use this parameter and I wonder if my classes would still be able to use it when specifying it from command line.

Thanks
Tarun K

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/WwS5dqvFwmoJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: Specifying "parameter" as parameter from command line.

Cédric Beust ♔-2
Yes, you can specify it as a system property to the JVM (java -Dparameter=value) and TestNG will turn it into a parameter.

-- 
Cédric




On Sun, Aug 14, 2011 at 9:32 AM, Tarun Bhadauria <[hidden email]> wrote:
I have a parameter - <parameter name="appURL" value="http://www.gutegutscheine.de/" />

Which is used for test execution.

1. Is it possible to have it passed from command line while using testng comnnad line execution? I noticed command line parameter and the one available with ant but could not find it.
2. Many of my classes use this parameter and I wonder if my classes would still be able to use it when specifying it from command line.

Thanks
Tarun K

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/WwS5dqvFwmoJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: Specifying "parameter" as parameter from command line.

Tarun Kumar-4
Dumb question 1 -

I am using "ant" to execute tests, so I execute "run" target as -

ant run

Now I want to pass URL parameter from ant instead of testng,xml file, so I tried -

ant -Durl = "yahoo.com" run

And this results in test failure as my test method expecting "url" parameter can not access it. And I don't have "url" parameter defined in testng.xml file also...
Now how would I establish the correspondence b/w ant and testng test methods so that my test methods take the parameter which is passed from command line.

Thanks
Tarun K




--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/mMfLSPnWVx0J.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: Specifying "parameter" as parameter from command line.

Cédric Beust ♔-2
Are you specifying delegateCommandSystemProperties="true"?

    <testng outputdir="${testng.report.dir}"
        classpathref="run.cp"
        useDefaultListeners="true"
        delegateCommandSystemProperties="true"
        outputDir="${testng.report.dir}">
      <xmlfileset dir="${test.resources.dir}" includes="testng-single.xml"/>
     </testng>

-- 
Cédric




On Tue, Aug 16, 2011 at 1:26 AM, Tarun Bhadauria <[hidden email]> wrote:
Dumb question 1 -

I am using "ant" to execute tests, so I execute "run" target as -

ant run

Now I want to pass URL parameter from ant instead of testng,xml file, so I tried -

ant -Durl = "yahoo.com" run

And this results in test failure as my test method expecting "url" parameter can not access it. And I don't have "url" parameter defined in testng.xml file also...
Now how would I establish the correspondence b/w ant and testng test methods so that my test methods take the parameter which is passed from command line.

Thanks
Tarun K




--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/mMfLSPnWVx0J.

To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: Specifying "parameter" as parameter from command line.

Tarun Kumar-4
thank you, works best

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/eNK_nm-gftwJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: Specifying "parameter" as parameter from command line.

jchesshir
This post has NOT been accepted by the mailing list yet.
I just wanted to add that this only works if the parameter has not already been specified in your testng.xml.  If it has, TestNG will choose the value in the file over the property set from the command line.
Reply | Threaded
Open this post in threaded view
|

Re: Specifying "parameter" as parameter from command line.

jchesshir
This post has NOT been accepted by the mailing list yet.
Did a little more searching, and came up with a way to handle the problem I just stated above that covers all of my use cases.  

In the Java code that defines the parameter, make the parameter optional and give it the most commonly used value as its default.  You can then strip out the parameter wherever it exists in your testng.xml file.  That done, TestNG will accept properties handed to it by the calling program (whether the command line, Maven, Ant, etc.), but if you don't, the tests will still run with the default value.

I'm sure there are use cases where this might not be sufficient, but it covers all of the cases I need to be more efficient.