Selenium Webdriver:如何在终端中 运行 testNG.xml 文件(在 MAC 中)?
Selenium Webdriver : How to run testNG.xml file in Terminal (in MAC)?
我在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 机器) 的 运行ning 代码和一些建议,这些不是 maven 项目意味着简单项目,转到库部分和 运行命令。
是的,您可以从终端运行 testng.xml 文件。你应该在你的机器上安装 maven
。以下命令会有所帮助。
$ brew install maven
之后,您可以简单地使用 mvn
命令在您的项目中执行 maven 目标。如果您相应地配置了 Pom.xml 文件,则以下命令将执行您的 testng.xml 文件
$ cd path/to/your/project
$ mvn test
正如我所说,我的 testng 文件在构建文件夹中,所以我必须在 <suiteXmlFile>build/${suiteFile}</suiteXmlFile>
中提供路径
在 Pom.xml
中做了一些更改
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>build/${suiteFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
命令 运行:
$ cd path/to/your/project
$mvn test -DsuiteFile=testng.xml
或
$mvn clean test -DsuiteFile=testng.xml
参考youtube link: https://www.youtube.com/watch?v=lQCyVy-g1e8&t=436s
注:
如果您的 testng.xml
文件不属于任何文件夹并且您只想每次调用 testng.xml
,则项目中没有其他 xml 文件。
简单地说<suiteXmlFile>testng.xml</suiteXmlFile>
运行 命令
$ cd path/to/your/project
$mvn test
我在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 机器) 的 运行ning 代码和一些建议,这些不是 maven 项目意味着简单项目,转到库部分和 运行命令。
是的,您可以从终端运行 testng.xml 文件。你应该在你的机器上安装 maven
。以下命令会有所帮助。
$ brew install maven
之后,您可以简单地使用 mvn
命令在您的项目中执行 maven 目标。如果您相应地配置了 Pom.xml 文件,则以下命令将执行您的 testng.xml 文件
$ cd path/to/your/project
$ mvn test
正如我所说,我的 testng 文件在构建文件夹中,所以我必须在 <suiteXmlFile>build/${suiteFile}</suiteXmlFile>
在 Pom.xml
中做了一些更改<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>build/${suiteFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
命令 运行:
$ cd path/to/your/project
$mvn test -DsuiteFile=testng.xml
或
$mvn clean test -DsuiteFile=testng.xml
参考youtube link: https://www.youtube.com/watch?v=lQCyVy-g1e8&t=436s
注:
如果您的 testng.xml
文件不属于任何文件夹并且您只想每次调用 testng.xml
,则项目中没有其他 xml 文件。
简单地说<suiteXmlFile>testng.xml</suiteXmlFile>
运行 命令
$ cd path/to/your/project
$mvn test