How to read in arguments passed via ant to testng.xml

六眼飞鱼酱① 提交于 2020-01-03 05:33:08

问题


Here is the scenario:

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.

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}"/>

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

I went to testng.xml and did something like:

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

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


回答1:


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>

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

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

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

ant -Dproperty=true execute

This should work.




回答2:


I think it should work with <sysproperty> if you set delegateCommandSystemProperties to true and nest the <sysproperty> within <testng>

Not sure if you have nested the <sysproperty> ?



来源:https://stackoverflow.com/questions/3937817/how-to-read-in-arguments-passed-via-ant-to-testng-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!