How to get ANT Parameter reference in TestNG.xml

1,155 views
Skip to first unread message

somesh bansal

unread,
Oct 16, 2012, 10:28:48 AM10/16/12
to testng...@googlegroups.com
Hello,

I am passing some parameters from ANT build.xml in <testng> and want to get reference in testNG.xml but unable to do that

This link has got same issue 

Request to provide your valuable comments

Awaiting response
Somesh

Yevhen Bilevych

unread,
Oct 16, 2012, 11:32:15 AM10/16/12
to testng...@googlegroups.com
Hi Somesh,

Haven't managed to pass parameters that way.

Managed to pass from Ant to TestNG parameters.
e.g. if your ant task contains
<sysproperty key="browser" value="${browser}"/>
and your test contains
    @Parameters({ "browser",...})
    @Test
    public void someTest(
then value will be passed into test.
Please note that corresponding parameter tag in testng.xml file
<parameter name="selenium" value="firefox" />
should be removed!

Thanks,
Yevhen
--
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/-/4socdLrPDmMJ.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Abhishek Singh

unread,
Oct 17, 2012, 5:25:29 AM10/17/12
to testng...@googlegroups.com
Hi,

please use this code to access testng.xml through ANT.

<target name="run" depends="compile">
        <testng haltonfailure="true"
            useDefaultListeners="false"
            listeners="org.uncommons.reportng.HTMLReporter"
            classpath ="${test.classpath}:${build.dir}">
            <xmlfileset dir="${basedir}/Suite" includes="testng.xml"/>
        </testng>
    </target>

Somesh Bansal

unread,
Oct 25, 2012, 4:09:04 AM10/25/12
to testng...@googlegroups.com
Hello Yevhen,

Thanks for response & sorry for delay!!

I am able to pass parameter to 'test' method but here I am only looking to get parameter reference in testNG.xml so as to dynamically generate Suite Name's as mentioned in link too

Awaiting response
Somesh

Di Zhu

unread,
Dec 10, 2014, 1:53:05 AM12/10/14
to testng...@googlegroups.com
Hello,

Now, I face the same problems as you. Have you figured it out?? I search the internet. However, most of them are passing argument to test class. I just want to pass parameter from build.xml to testNG.xml so I can dynamically type in the group I want to run in testNG.

Awaiting response
Judy

在 2012年10月25日星期四UTC+8下午4时09分08秒,somesh bansal写道:

Hubert Grzeskowiak

unread,
Dec 11, 2014, 12:58:25 PM12/11/14
to testng...@googlegroups.com
Hi,
I don't think you can have any variables or properties in testng.xml. However, you can set the suite name dynamically. Example here: https://bpaste.net/show/51088f3a089a
If you pass the parameter to beforeSuite defined as parameter or Java property (ANT properties are automatically set as Java properties AFAIK) you can use that to set test or suite name. This WILL affect how the test is shown in e.g. Eclipse TestNG Results, but will not change the name of the directory where results are saved.

Cheers
Hubert Grzeskowiak

Di Zhu

unread,
Dec 11, 2014, 9:13:34 PM12/11/14
to testng...@googlegroups.com
Hi,

Thank you very much for your reply. Maven seems can solve my problem. I am working towards it recently.

Best Regards,
Judy

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/NNRCKICdDG8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users...@googlegroups.com.

To post to this group, send email to testng...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages