使用maven在Testng.xml上动态选择测试用例
我在testng.xml文件中定义了一组测试套件,我正在从pom.xml文件传递一个参数来调用testng文件 但是,我需要一个解决方案,在这个解决方案中,我可以将一个参数作为环境变量传递,以决定要从testng.xml执行哪个套件 我最初的想法是拥有多个testng.xml文件,但拥有多个文件似乎不是最好的解决方案使用maven在Testng.xml上动态选择测试用例,maven,selenium,testng,Maven,Selenium,Testng,我在testng.xml文件中定义了一组测试套件,我正在从pom.xml文件传递一个参数来调用testng文件 但是,我需要一个解决方案,在这个解决方案中,我可以将一个参数作为环境变量传递,以决定要从testng.xml执行哪个套件 我最初的想法是拥有多个testng.xml文件,但拥有多个文件似乎不是最好的解决方案 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Suite">
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Sanity">
<classes>
<class name="com.ibm.wce.scbn.cc.runner.Sanity" />
</classes>
</test>
</suite>
<suite name="Suite">
<test name="Regression">
<classes>
<class name="com.ibm.wce.scbn.cc.runner.Reg" />
</classes>
</test>
</suite>
Pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<!-- TestNG Suite XML files list for test execution -->
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
org.apache.maven.plugins
maven surefire插件
3.0.0-M3
${suiteXmlFile}
VM参数:mvn clean install-DsuiteXmlFile=testng.xml,testng2.xml我认为您正在maven中查找
配置文件。寻找更多信息
在pom.xml中,添加配置文件
部分,然后将插件
放入构建中的
标签,如下所示
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<pluginManagement>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>suite1.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>suite1</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng-customsuite.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>suite2</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>suite2.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
....
</dependencies>
src
src
**/*.爪哇
org.apache.maven.plugins
,这似乎表明您正在尝试的操作可能不可能,但您可以尝试第二种解决方案。这就是我从官方网站复制粘贴的上述文本时的意思。谢谢您提供的信息。上述方法需要多个testng xml文件。然而,我的要求是在testng.xml中定义套件1、2、3、4。在运行时,我想选择suite1或Suite2或两者同时选择定义单独的xml文件有什么问题?您仍然可以从一个主套件文件运行这些套件