将变量从jenkins传递到testng.xml [英] Pass variable from jenkins to testng.xml
问题描述
我想根据jenkins传递的变量来运行测试用例 例如,选择要运行的测试用例: testcaseOne,testcaseTwo
I want to run test cases depending on variables passed from jenkins for example, choose testcases you want to run : testcaseOne, testcaseTwo
在pom.xml(maven)中:
in pom.xml (maven) :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<chooseCase>${chooseCase}</chooseCase> <--this dont work
</systemPropertyVariables>
<parallel>tests</parallel>
<threadCount>10</threadCount>
</configuration>
</plugin>
我有两个testng @test方法:
I have two testng @test methods:
@Test(groups="caseOne")
@Test(groups="caseTwo")
还有我的testng.xml文件:
And my testng.xml file:
<test name="Test">
<groups>
<run>
<include name="${chooseCase}"/>
</run>
</groups>
<classes>
<class name="AppTest"/>
<class name="AppTest2"/>
</classes>
</test> <!-- Test -->
如何根据我要运行的测试数量和数量来传递此参数? 也许有完全不同的方法可以做到这一点?
How to pass this parameter depending on what and how many tests i want to run ? Maybe there is totally different way to do this ?
推荐答案
您可以在您的testng.xml文件中使用BeanShell脚本
You can use BeanShell script in your testng.xml file http://testng.org/doc/documentation-main.html#beanshell and read system variables in it, something like:
<test name="Test">
<method-selectors>
<method-selector>
<script language="beanshell">
<![CDATA[
String myTestGroup = System.getProperty("chooseCase");
groups.containsKey(myTestGroup);
]]>
</script>
</method-selector>
</method-selectors>
<classes>
<class name="AppTest"/>
<class name="AppTest2"/>
</classes>
</test>
这篇关于将变量从jenkins传递到testng.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!