无法通过Java Selenium中的Maven和命令行运行test.xml文件 [英] Not able to run test.xml file through maven and command line in java selenium

查看:76
本文介绍了无法通过Java Selenium中的Maven和命令行运行test.xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Maven和命令行运行test.xml文件.我的test.xml有4个课程,但不幸的是,"mvn test"命令只能选择一个课程.

I want to run test.xml file through maven and command line. My test.xml has 4 classes but unfortunately 'mvn test' command only picks one class.

下面是我的项目结构.

Below is my project structure.

这是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类.

So now if I run maven from the command line this is the output.It is taking only PurchaseCredits class.

命令-mvn clean test

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

If I run from IntelliJ directly it is running properly, so the only issue I am facing is I am not able to run a proper test.xml file from maven

在mvn -Ptest干净测试之后,这是Maven的屏幕截图 在此处输入图片描述

after mvn -Ptest clean test, this is the screenshot for Maven enter image description here

推荐答案

您必须激活配置文件才能激活相应的surefire配置:

You must activate the profile which activates the appropriate surefire configuration:

mvn -Ptest clean test

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

By default, surefire only run Test* and *Test classes. That explains why only PurchaseCreditsTest is taken in your case.

这篇关于无法通过Java Selenium中的Maven和命令行运行test.xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆