Java Selenium Webdriver:如何在终端(MAC)中运行testNG.xml文件?
我在MAC系统中创建了一个Maven testNG项目。我已经创建了一个testSuite,现在我想使用终端运行testNG.xml文件。有没有办法运行这个xml文件 testNG.xmlJava Selenium Webdriver:如何在终端(MAC)中运行testNG.xml文件?,java,xml,maven,selenium,testng,Java,Xml,Maven,Selenium,Testng,我在MAC系统中创建了一个Maven testNG项目。我已经创建了一个testSuite,现在我想使用终端运行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"> &
<?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 -->
<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>
<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>
Pom.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 -->
<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>
<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>
4.0.0
com.learnautomation
com.learnautomation.selenium
0.0.1-快照
src/main/resources/testng.xml
假的
org.apache.maven.plugins
maven编译器插件
3
1.8
1.6
1.6
org.apache.maven.plugins
maven surefire插件
3.0.0-M3
真的
${suiteXmlFile}
org.seleniumhq.selenium
硒爪哇
3.141.59
org.seleniumhq.selenium
硒服务器
3.14.0
org.apache.poi
poi
3.13
杰克谢拉皮
jxl
2.4.2
org.testng
testng
6.14.3
测试
com.aventstack
扩展端口
3.1.5
假如
org.apache.poi
poi ooxml
3.10-决赛
log4j
log4j
1.2.17
注意:我在互联网上看到了很多选择。主要是关于通过命令行(windows机器)运行代码的问题。还有一些建议不是maven project意味着简单的project,请转到库部分并运行命令。是的,您可以从终端运行testng.xml文件。您的计算机中应该安装了
maven
。下面的命令会有帮助
$ brew install maven
之后,您可以简单地使用mvn
命令在项目中执行maven目标。如果您已经相应地配置了Pom.xml文件,那么下面的命令将执行testng.xml文件
$ cd path/to/your/project
$ mvn test
正如我所说,我的testng文件位于build文件夹中,因此我必须在
build/${suiteFile}
在Pom.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 -->
<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>
<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>
org.apache.maven.plugins
注意:
如果您的testng.xml
文件不属于任何文件夹,并且您每次都只想调用testng.xml
,则project中没有其他xml文件
简单地说testng.xml
运行命令
$cd path/to/your/project
$mvn测试
mvn测试-DsuiteXmlFile=YourTestSuiteFileName
将是合适的命令。是。但是Pom.xml已经有了
标记。所以没有必要在命令中再次提及。1<代码>mvn清洁安装
2<代码>mvn测试任何东西都应该有效。但如果我使用mvn clean install,则应该安装maven,并且.m2路径应该设置为showing error。如果我使用mvn测试,则显示错误,您已将
设置为src/main/resources/testng.xml。请确保您的xml文件位于此处,然后重试。