0

这是场景:

有一个用一个参数调用ant的shell 脚本。ant 依次执行testng.xml(套件文件)并传递相同的参数,而 testng 依次在传递相同的参数内执行测试

就我而言,我正在传递浏览器字符串eg.(firefox, iexplore) 参数,该参数将指定将在哪个浏览器测试上运行。我希望能够让我的测试结果输出告诉我测试在哪个浏览器中运行。

我通过以下方式从 ant 命令行中获取参数:

...

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

我在想既然 ant 调用 testng.xml,我可以在 testng.xml 中做同样的事情

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

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

我希望我没有失去任何人。不是最好的解释事物,但只需要在 testng.xml 中捕获此参数并将其包含在套件名称中

4

2 回答 2

4

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

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

在 testng 文件中,在参数标签中添加“key”和“value”,如下所示:

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

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

ant -Dproperty=true execute

这应该有效。

于 2015-06-13T07:51:36.863 回答
1

我认为 <sysproperty>如果您设置 并嵌套在其中delegateCommandSystemProperties,它应该可以使用true<sysproperty><testng>

不确定您是否嵌套了<sysproperty>?

于 2010-10-15T06:21:22.887 回答