运行 使用 Maven 的 TestNG
Running TestNG with Maven
我正在尝试 运行 TestNG/Selenium 一个特定的测试套件,但我无法 运行 进行测试。我运行ning的命令是:
mvn test -Dsuitefile=admin_tests.xml
admin_tests.xml 包含:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https:://testng.org/testng-1.0.dtd">
<suite name="Administration - All">
<test name="Users tab tests" thread-count="1">
<packages>
<package name="appOne.testcases.ui.admin.users.*"/>
</packages>
</test>
<test name="User roles tab tests" thread-count="1">
<packages>
<package name="appOne.testcases.ui.admin.userRoles.*"/>
</packages>
</test>
</suite>
目录结构为:
/test-suites/admin_tests.xml
/src/test/java/appOne/testcases/ui/admin/users/users_testcase1.xml
/src/test/java/appOne/testcases/ui/admin/users/users_testcase2.xml
/src/test/java/appOne/testcases/ui/admin/users/users_testcase3.xml
/src/test/java/appOne/testcases/ui/admin/userRoles/userRoles_testcase1.xml
/src/test/java/appOne/testcases/ui/admin/userRoles/userRoles_testcase2.xml
/src/test/java/appOne/testcases/ui/admin/users/userRoles_testcase3.xml
任何帮助将不胜感激,因为我不明白我做错了什么。当我 运行 命令时,我得到 0 个测试 运行.
pom.xml 是:
version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
<artifactId>automation</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.22.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.http-client/google-http-client-gson -->
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-gson</artifactId>
<version>1.41.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.1.1</version>
</dependency>
<!-- Dependency for TestRail APIClient -->
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
</properties>
</project>
首先你需要修复你的套件文件。您在 DOCTYPE
中有 https:://
,因此您需要将其修复为 https://
那么你不能只设置任何 属性。你必须告诉 surefire 插件你将使用那个来指定你的套件。将以下部分添加到您的 pom.xml
:
...
<properties>
...
<maven-surefire-plugin.version>3.0.0-M6</maven-surefire-plugin.version>
...
</properties>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suitefile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
最后,由于您来自项目根目录 运行 mvn
,因此您应该指定项目根目录的路径,以便您应该从
开始一切
mvn test -Dsuitefile=test-suites/admin_tests.xml
我正在尝试 运行 TestNG/Selenium 一个特定的测试套件,但我无法 运行 进行测试。我运行ning的命令是:
mvn test -Dsuitefile=admin_tests.xml
admin_tests.xml 包含:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https:://testng.org/testng-1.0.dtd">
<suite name="Administration - All">
<test name="Users tab tests" thread-count="1">
<packages>
<package name="appOne.testcases.ui.admin.users.*"/>
</packages>
</test>
<test name="User roles tab tests" thread-count="1">
<packages>
<package name="appOne.testcases.ui.admin.userRoles.*"/>
</packages>
</test>
</suite>
目录结构为:
/test-suites/admin_tests.xml
/src/test/java/appOne/testcases/ui/admin/users/users_testcase1.xml
/src/test/java/appOne/testcases/ui/admin/users/users_testcase2.xml
/src/test/java/appOne/testcases/ui/admin/users/users_testcase3.xml
/src/test/java/appOne/testcases/ui/admin/userRoles/userRoles_testcase1.xml
/src/test/java/appOne/testcases/ui/admin/userRoles/userRoles_testcase2.xml
/src/test/java/appOne/testcases/ui/admin/users/userRoles_testcase3.xml
任何帮助将不胜感激,因为我不明白我做错了什么。当我 运行 命令时,我得到 0 个测试 运行.
pom.xml 是:
version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
<artifactId>automation</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.22.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.http-client/google-http-client-gson -->
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-gson</artifactId>
<version>1.41.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.1.1</version>
</dependency>
<!-- Dependency for TestRail APIClient -->
<!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
</properties>
</project>
首先你需要修复你的套件文件。您在 DOCTYPE
中有 https:://
,因此您需要将其修复为 https://
那么你不能只设置任何 属性。你必须告诉 surefire 插件你将使用那个来指定你的套件。将以下部分添加到您的 pom.xml
:
...
<properties>
...
<maven-surefire-plugin.version>3.0.0-M6</maven-surefire-plugin.version>
...
</properties>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suitefile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
最后,由于您来自项目根目录 运行 mvn
,因此您应该指定项目根目录的路径,以便您应该从
mvn test -Dsuitefile=test-suites/admin_tests.xml