Java 无法运行testng.xml

Java 无法运行testng.xml,java,maven,selenium,automation,Java,Maven,Selenium,Automation,我正在使用SeleniumWebDriver、eclipse、testng和surefire插件。我无法从pom.xml运行testng.xml文件。当我使用mvn test运行pom.xml时,它直接运行src/test/java/testCases中的文件。请就我的错误提出建议。先谢谢你 我的POM文件: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSch

我正在使用SeleniumWebDriver、eclipse、testng和surefire插件。我无法从pom.xml运行testng.xml文件。当我使用mvn test运行pom.xml时,它直接运行src/test/java/testCases中的文件。请就我的错误提出建议。先谢谢你

我的POM文件:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test.maven</groupId>
    <artifactId>NumberGenerator</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>NumberGenerator</name>
    <!-- <url>http://maven.apache.org</url> -->
    <!-- <dependencies> -->
    <!-- <dependency> -->
    <!-- <groupId>junit</groupId> -->
    <!-- <artifactId>junit</artifactId> -->
    <!-- <version>4.11</version> -->
    <!-- <scope>test</scope> -->
    <!-- </dependency> -->
    <!-- </dependencies> -->

    <!-- <build> -->
    <!-- <plugins> -->
    <!-- <plugin> -->
    <!-- <groupId>org.apache.maven.plugins</groupId> -->
    <!-- <artifactId>maven-compiler-plugin</artifactId> -->
    <!-- <version>2.3.2</version> -->
    <!-- <configuration> -->
    <!-- <source>1.6</source> -->
    <!-- <target>1.6</target> -->
    <!-- </configuration> -->
    <!-- </plugin> -->
    <!-- </plugins> -->
    <!-- </build> -->
    <!-- Source directory configuration -->
    <build>
        <plugins>
            <!-- Following plugin executes the testng tests -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19</version>
                <configuration>
                    <!-- Suite testng xml file to consider for test execution -->
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                        <!-- <suiteXmlFile>suites-test-testng.xml</suiteXmlFile> -->
                    </suiteXmlFiles>
                </configuration>
            </plugin>
            <!-- Compiler plugin configures the java version to be usedfor compiling 
                the code -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <!-- Dependency libraries to include for compilation -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.8</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

在testNG.xml文件中,必须指定完全限定名,而不是类的路径。下面这个指定的更改应该可以做到这一点

<classes>
   <class name="testCases.Automation_Sobet_WBG_YiWanCai"/>
</classes>

如果不使用JUnit,可以将其从POM文件中删除。

在testNG.xml文件中,必须指定完全限定名,而不是类的路径。下面这个指定的更改应该可以做到这一点

<classes>
   <class name="testCases.Automation_Sobet_WBG_YiWanCai"/>
</classes>

如果您不使用JUnit,可以将其从POM文件中删除。

我认为这很好。无论如何,您已经在testng.xml中指定了确切的且只有一个要执行的类。因此,它正在考虑
自动化\u Sobet\u WBG\u YiWanCai
。请尝试在testng.xml中为类指定错误的路径,并查看是否有错误。或者可能是我没有直接在您的问题中找到单词。@mk08我尝试在testng.xml中为类指定错误的路径,但它仍然不起作用。。当我运行它时,似乎什么都没有加载/运行maven是否告诉您,0个测试运行,0个通过,0个失败?或者,当您作为maven test运行时,您可以发布准确的控制台输出。请尝试在testng.xml中使用test类名的相对路径,如
,我认为这样做很好。无论如何,您已经在testng.xml中指定了确切的且只有一个要执行的类。因此,它正在考虑
自动化\u Sobet\u WBG\u YiWanCai
。请尝试在testng.xml中为类指定错误的路径,并查看是否有错误。或者可能是我没有直接在您的问题中找到单词。@mk08我尝试在testng.xml中为类指定错误的路径,但它仍然不起作用。。当我运行它时,似乎什么都没有加载/运行maven是否告诉您,0个测试运行,0个通过,0个失败?或者,当您作为maven test运行时,您可以发布准确的控制台输出。请尝试使用testng.xml中测试类名的相对路径,例如
hi,testng.xml我无法运行,testng.xml我无法运行
<classes>
   <class name="testCases.Automation_Sobet_WBG_YiWanCai"/>
</classes>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19</version>
    <configuration>
    <!-- Suite testng xml file to consider for test execution -->
        <suiteXmlFiles>
            <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
</plugin>