无法通过 java selenium 中的 maven 和命令行 运行 test.xml 文件

Not able to run test.xml file through maven and command line in java selenium

我想通过 maven 和命令行 运行 test.xml 文件。我的 test.xml 有 4 个 classes 但不幸的是 'mvn test' 命令只选择了一个 class.

下面是我的项目结构。

这里是 pom.xml

的代码
<groupId>com.mobikon.commontestapp</groupId>
<artifactId>commontestapp</artifactId>
<version>1.0-SNAPSHOT</version>

<repositories>
    <repository>
        <id>central</id>
        <name>bintray</name>
        <url>http://jcenter.bintray.com</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.0</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.10</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.uncommons</groupId>
        <artifactId>reportng</artifactId>
        <version>1.1.2</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
    </dependency>

    <dependency>
        <groupId>commons-configuration</groupId>
        <artifactId>commons-configuration</artifactId>
        <version>1.10</version>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-configuration2</artifactId>
        <version>2.1</version>

    </dependency>

</dependencies>

<profiles>

    <profile>
        <id>test</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.19.1</version>


                    <configuration>
                        <properties>
                            <property>
                                <name>usedefaultlisteners</name>
                                <value>false</value>
                            </property>
                            <property>
                                <name>listener</name>
                                <value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value>
                            </property>
                        </properties>

                        <suiteXmlFiles>
                            <suiteXmlFile>test.xml</suiteXmlFile>
                        </suiteXmlFiles>
                        <!--<workingDirectory>target/</workingDirectory>-->
                    </configuration>

                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

这是 test.xml

的代码
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Mobikon Automation Tests" verbose="1" >

    <test name="mEngage" >
        <classes>
            <class name="mengage.tests.LoginScenarios"></class>
            <class name="mengage.tests.PurchaseCreditsTest"></class>
            <class name="mengage.tests.VerifyTotalCustomers"></class>
            <class name="mengage.tests.VerifyCredits"></class>
        </classes>
    </test>
</suite>

所以现在如果我从命令行 运行 maven 这是 output.It 只获取 PurchaseCredits class。

命令 - mvn clean test

如果我直接从 IntelliJ 运行 运行 正确,所以我面临的唯一问题是我无法 运行 正确 test.xml来自 Maven 的文件

mvn -Ptest clean 测试后,这是 Maven 的屏幕截图 enter image description here

您必须激活配置文件以激活适当的 surefire 配置:

mvn -Ptest clean test

默认情况下,surefire 仅 运行 Test**Test 类。这就解释了为什么在您的情况下只采用 PurchaseCreditsTest