I am trying to run TestNG/Selenium a specific test suite, but I can't get it to run the test. The command I am running is:
mvn test -Dsuitefile=admin_tests.xml
The admin_tests.xml contains:
<?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>
The directory structure is:
/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
Any help would really be appreciated as I don't understand what I am doing wrong. When I run the command I get 0 tests run.
pom.xml is:
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>
CodePudding user response:
First of all you need to fix your suite file. You have https:://
in DOCTYPE
so you need to fix it to https://
Then you cannot just set any property. You have to tell surefire plugin that you are going to use that one to specify your suite. Add the following section to your 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>
Next finally since you are running mvn
from project root you should specify the path from project root so that you should start everything with
mvn test -Dsuitefile=test-suites/admin_tests.xml