【问题标题】:Not able to run test.xml file through maven and command line in java selenium无法通过 java selenium 中的 maven 和命令行运行 test.xml 文件
【发布时间】:2017-06-16 13:02:50
【问题描述】:

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

下面是我的项目结构。

这是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,这就是输出。它只占用 PurchaseCredits 类。

命令 - mvn clean test

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

在 mvn -Ptest clean test 之后,这是 Maven 的截图 enter image description here

【问题讨论】:

    标签: java maven testng pom.xml


    【解决方案1】:

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

    mvn -Ptest clean test
    

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

    【讨论】:

    • 非常感谢您的帮助.. 但现在我收到错误,test.xml 不是有效文件.. 你能帮忙解决一下吗
    • xml 失败是什么意思? IntelliJ 和/或 Maven?如果仅使用 IntelliJ,请尝试使用更新的版本,因为您的可能嵌入了太旧的 testng 版本。
    • 我使用 Intellij 作为 Maven 框架的工具。在 pom.xml 我提到了 org.testngtestng6.10test 但是仍然错误保持不变。 “分叉进程中出现错误 [ERROR] org.apache.maven.surefire.testset.TestSetFailedException: Suite file D:\repos\mobikontestapp\src\test\java\test.xml 不是有效文件"
    • 你能分享mvn -e -Ptest clean test的输出吗?
    • maven 正在您的文件不存在的默认文件夹中寻找套件。只需将test.xml 替换为${project.basedir}\test.xml。仅供参考,套件的常用文件夹是src/test/resources
    猜你喜欢
    • 2015-07-12
    • 1970-01-01
    • 2018-04-26
    • 2014-03-22
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    • 2017-09-25
    相关资源
    最近更新 更多