Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在IDE中使用run选项运行时,使用TestNG XML的并行执行运行良好,但mvn clean测试失败,并出现与参数相关的错误_Java_Maven_Selenium Webdriver_Automation_Testng - Fatal编程技术网

Java 在IDE中使用run选项运行时,使用TestNG XML的并行执行运行良好,但mvn clean测试失败,并出现与参数相关的错误

Java 在IDE中使用run选项运行时,使用TestNG XML的并行执行运行良好,但mvn clean测试失败,并出现与参数相关的错误,java,maven,selenium-webdriver,automation,testng,Java,Maven,Selenium Webdriver,Automation,Testng,我正在使用两套浏览器尝试并行执行。testng.xml是这样的: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Suite" parallel="tests" thread-count="2"> <test name="Test1" parallel="methods" t

我正在使用两套浏览器尝试并行执行。testng.xml是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests" thread-count="2">
    <test name="Test1" parallel="methods" thread-count="3">
        <parameter name="browser" value="chrome"/>
        <classes>
            <class name="Test01" />
        </classes>
    </test>
    <test name="Test2" parallel="methods" thread-count="3">
        <parameter name="browser" value="firefox"/>
        <classes>
            <class name="Test02" />
        </classes>
    </test>
</suite>
<plugin>
      <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-surefire-plugin</artifactId>
             <version>2.18.1</version>
                <executions>
                  <execution>
                    <configuration>
                        <suiteXmlFiles>
                            <suiteXmlFile>testng.xml</suiteXmlFile>
                        </suiteXmlFiles>
                    </configuration>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
          </executions>
</plugin>

我做错了什么?在几次试图理解错误之后,我感到非常困惑。使用Intellij IDEA中的run按钮,testng xml如何能够正常运行,但mvn clean test因上述错误而失败?我想了解终端运行与IDE运行之间的差异背后的逻辑

使用maven surefire插件并尝试在build标记下添加以下配置:

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.0</version>
    <configuration>
        <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
    </plugin>

要运行testNg.xml,我们可以将xml文件传递到标记
只有当您的项目遵循由maven创建的相同结构时,它才会工作:src/main和src/test

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <skip>false</skip>
                <forkCount>0</forkCount>
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>

org.apache.maven.plugins
maven surefire插件
2.19.1
假的
0
testng.xml
如果您更改了结构,则需要在
标记的文件夹中提及,如我所举的示例src:

<build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <!-- plugin executes the testng tests -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <skip>false</skip>
                    <forkCount>0</forkCount>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
       </plugins>
    </build>

src
org.apache.maven.plugins
maven surefire插件
2.19.1
假的
0
testng.xml

谢谢。这是有道理的。还有一件事我很困惑。套件标记旁边的线程数和测试标记旁边的线程数有什么区别?这是否意味着SUITE标记中的线程数意味着它将在两个线程中并行运行SUITE。测试方法将在3个线程中运行?如果我只有一个测试方法,线程数是4,那该怎么办?这将根据定义工作,但是,在使用selenium时,您还需要同步代码,否则浏览器会出现故障,最好在套件级别使用并行。这很有效。我想知道为什么我必须在-Dsurefire标记中指定xml,而mvn clean测试本身无法工作,即使我在依赖项中有surefire插件?这可能与maven runner的默认配置有关
mvn -Dsurefire.suiteXmlFiles=testng.xml clean test
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <skip>false</skip>
                <forkCount>0</forkCount>
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
<build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <!-- plugin executes the testng tests -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <skip>false</skip>
                    <forkCount>0</forkCount>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
       </plugins>
    </build>