我有一个用Intellij想法编写的maven项目(appium/java)。要运行测试,我必须运行testng.xml文件。我想从命令行运行我的测试脚本。我该怎么做?我找到了从命令行运行testng.xml的各种链接,但没有一个解决方案对我有用。提前致谢
由于您的项目是一个 maven 项目,因此您可以在导航到项目路径后从命令行使用 mvn 清理测试选项。这将运行 testng.xml 文件中的测试
如果您有多个测试 xml 文件,您可以使用 Surefire 插件。到你的pom.xml你需要添加类似的东西:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFiles}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
添加所需数量的 suiteXmlFile 标签,它应该指向你的 test1.xml、test2.xml 等的位置,然后在命令行中使用命令
mvn clean test -DsuiteXmlFile.suiteXmlFiles=path/to/test1.xml
如果要运行多个测试 xml 文件,可以使用命令
mvn clean test -DsuiteXmlFile.suiteXmlFiles=path/to/test1.xml,path/to/test2.xml
希望这有帮助
如果您使用 testng.xml 文件运行您的 appium 案例,那么您可以使用 maven 的 surefire 插件使用 maven 运行您的 testng 文件。和 maven 您可以使用命令行运行。
所以基本上你可以运行maven命令,它将使用surefire插件在内部运行你的tesng.xml文件。在构建部分的pom文件中添加万无一失的插件,如下所示。然后运行 mvn 测试命令它将工作。
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>Give your testng.xml file path</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>