我已经在MAC系统中创建了一个Maven-testNG项目。我已经创建了一个testSuite,现在我想使用Terminal运行testNG.xml文件。有什么方法可以运行此xml文件吗?
testNG.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" verbose="2">
<test name="Test">
<classes>
<class name="com.Live.testcase.TC0001_Signup" />
<class name="com.Live.testcase.TC0002_SoleProprietorship" />
<class name="com.Live.testcase.TC0003_Login" />
<class name="com.Live.testcase.TC0004_ForgotPassword" />
<class name="com.Live.testcase.TC0005_LLC" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.learnautomation</groupId>
<artifactId>com.learnautomation.selenium</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<suitXmlFile>src/main/resources/testng.xml</suitXmlFile>
<skipTests> false </skipTests>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.13</version>
</dependency>
<!-- https://mvnrepository.com/artifact/jexcelapi/jxl -->
<dependency>
<groupId>jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.4.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.1.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.10-FINAL</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
</project>
注意:我在互联网上看到了很多选择。主要是关于通过命令行(Windows计算机)运行代码,并且一些不是maven项目的建议意味着简单的项目,请转到库部分并运行命令。
是的,您可以从终端运行testng.xml文件。您应该在计算机中安装maven
。遵循以下命令将有所帮助。
$ brew install maven
之后,您可以简单地使用mvn
命令在您的项目中执行Maven目标。如果您已经相应地配置了Pom.xml文件,则以下命令将执行您的testng.xml文件。
$ cd path/to/your/project
$ mvn test