简体   繁体   English

无法在Maven项目中运行TestNG Suit

[英]Can not run TestNG suit in Maven project

Here is my pom file for Java Selenium WebDriver Maven project: 这是Java Selenium WebDriver Maven项目的pom文件:

<?xml 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>MyProject</groupId>
    <artifactId>TestAutomation</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/resources/wwwRegression.xml</suiteXmlFile>
                        <suiteXmlFile>src/test/resources/betaRegression.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.10</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.50.1</version>
        </dependency>
    </dependencies>
</project>

What I need to do - run certain test suite from cmd on windows. 我需要做的-在Windows上从cmd运行某些测试套件。 From the project dir I tried to use different variations of commands: 从项目目录中,我尝试使用不同的命令变体:

mvn test -Dsurefire.suiteXmlFile=wwwRegression
mvn test -Dsuite=wwwRegression
mvn surefire:test -DsuiteXmlFile=wwwRegression

But all the time both of the test suites are executing. 但是,所有测试套件始终都在执行。 Does anybody have any ideas how to run one certain test suite ? 是否有人对如何运行某个测试套件有任何想法?

You have to set a property in the pom file to be able to pass through the command prompt. 您必须在pom文件中设置属性才能通过命令提示符。

Modify the pom file like below. 如下修改pom文件。

<properties
    <testngFiles>src/test/resources/wwwRegression.xml,src/test/resources/betaRegression.xml</testngFiles>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>${testngFiles}</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
    </plugins>
</build>

You can run the test by using 您可以使用来运行测试

mvn -U clean install -DtestngFiles=src/test/resources/wwwRegression.xml mvn -U全新安装-DtestngFiles = src / test / resources / wwwRegression.xml

Note: Surefire can take multiple testNG XML files as comma separated values. 注意:Surefire可以将多个testNG XML文件作为逗号分隔的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Maven构建中对Testng进行套装测试之前运行antrun插件 - Run antrun plugin before suit tests of testng in maven build 无法在Maven项目中运行TestNG Test Suite - Can't run TestNG Test Suite in a maven project 我的Maven项目如何在没有TestNG尝试运行JUnit测试的情况下同时运行JUnit和TestNG? - How can my Maven project run both JUnit and TestNG without TestNG trying to run JUnit tests? 无法在 Cucumber-Maven(TestNG)中运行 testng.xml - Can't run testng.xml in Cucumber-Maven(TestNG) 如何在mac中通过命令行运行maven项目的testng脚本 - How to run the testng script of maven project through the command line in mac 如何从命令提示符下运行Maven项目testng.xml - how to run maven project testng.xml from the command prompt Maven项目(Cucumber + TestNG + Selenium-Java)测试无法使用mvn clean install在命令行上运行测试 - Maven Project(Cucumber+TestNG+Selenium-Java] Test Can't Run test on command line with mvn clean install 无法在Tomcat 7中运行maven项目 - can not run maven project in Tomcat 7 How to run maven selenium project in docker (Maven + Selenium + java + TestNg + docker) - How to run maven selenium project in docker (Maven + Selenium + java + TestNg + docker) 想要使用 TestNg 包运行 maven 项目,但在执行项目时出错 - Want to run a maven project with TestNg packages but getting error when executing the project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM