[英]How to read in arguments passed via ant to testng.xml
這是場景:
有一個用一個參數調用ant的shell腳本 。 螞蟻依次執行傳遞相同參數的testng.xml (套件文件),而testng傳遞相同參數之內執行測試 。
就我而言,我正在傳遞瀏覽器字符串,例如(firefox,iexplore)參數,它將指定將在哪個瀏覽器測試上運行。 我希望能夠將測試結果輸出告訴我測試運行在哪個瀏覽器上。
我這樣從ant的命令行中獲取參數:
...
<sysproperty key="browser" value="${browser}"/>
我在想,既然螞蟻調用了testng.xml,我可以在testng.xml中做同樣的事情
我去了testng.xml並做了類似的事情:
<suite name="AcceptanceSuite_${browser}">
<test name="Acceptance Test_${browser}" >
我希望我不會失去任何人。 這並不是最好的解釋方式,而只是需要在testng.xml中捕獲此參數並將其包含在套件名稱中
在build.xml文件中,在testng標記中設置proxyCommandCommandSystemProperties = 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文件中,在參數標記中添加“鍵”和“值”,如下所示:
<parameter name="property" value="${property}"></parameter>
從命令行運行ant並傳遞參數值,如下所示:
ant -Dproperty=true execute
這應該工作。
我認為如果將delegateCommandSystemProperties
命令系統屬性設置為true
並將<sysproperty>
嵌套在<testng>
則它應該與<sysproperty>
<testng>
不知道您是否嵌套了<sysproperty>
?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.