如何读取通过ant传递给testng.xml的参数 [英] How to read in arguments passed via ant to testng.xml

查看:83
本文介绍了如何读取通过ant传递给testng.xml的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是场景:

具有一个 shell脚本,该脚本使用一个参数调用 ant .蚂蚁依次执行 testng.xml (套件文件),并传递相同的参数,而testng依次执行 test ,传递相同的参数.

Have a shell script that calls ant with one argument. The ant in turn executes testng.xml (suite file) passing the same argument and testng in turn executes the test within passing the same argument.

在我的情况下,我正在传递浏览器字符串,例如(firefox,iexplore)参数,该参数将指定运行哪个浏览器测试.我希望能够将测试结果输出告诉我该测试在哪个浏览器中运行.

In my case, I am passing the browser string eg.(firefox, iexplore) argument that will specify which browser test will run on. I want to be able to have my test result output tell me which browser the test run in.

我是这样从蚂蚁的命令行中获取参数的:

I grab the argument from command line in ant by so:

...

<sysproperty key="browser" value="${browser}"/>

我一直在想,由于ant调用了testng.xml,所以我可以在testng.xml中做同样的事情

I was thinking that since ant calls testng.xml, i can do the same in testng.xml

我去了testng.xml并做了类似的事情:

I went to testng.xml and did something like:

<suite name="AcceptanceSuite_${browser}">
<test name="Acceptance Test_${browser}" >

我希望我不会失去任何人.这并不是最好的解释方式,而只是需要在testng.xml中捕获此参数,并将其包含在套件名称

I hope i didnt lose anybody. Not the best in explaining things but simply need away of capturing this argument in testng.xml and including that in the suite name

推荐答案

在build.xml文件中,在testng标记中设置proxyCommandSystemProperties = true并添加 在testng标签下的<sysproperty key="property" value="${property}"/>如下:

In build.xml file, set delegateCommandSystemProperties=true in testng tag and add <sysproperty key="property" value="${property}"/> under testng tag as follows:

<target name="execute" depends="compile">
        <testng delegateCommandSystemProperties="true">
            <sysproperty key="property" value="${property}"/>
            <xmlfileset dir="${basedir}" includes="testng.xml" />
        </testng>
    </target>

在testng文件中,在参数标记中添加"key"和"value",如下所示:

In testng file add "key" and "value" in parameter tag as follows:

<parameter name="property" value="${property}"></parameter>

从命令行运行ant并传递参数值,如下所示:

Run ant from command-line and pass parameter value as follows:

ant -Dproperty=true execute

这应该有效.

这篇关于如何读取通过ant传递给testng.xml的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆