且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Maven运行我的Selenium测试?

更新时间:2023-09-17 21:30:52

好的,我终于明白了,这实际上是一个特定于Maven的问题,而不是Eclipse或Selenium。

OK, I finally figured it out after realising that this is actually a Maven-specific question rather than Eclipse or Selenium.

Maven可以通过使用exec-maven-plugin来运行它编译的代码,并将以下内容添加到pom.xml中:

Maven can be made to run the code it compiles by using the exec-maven-plugin and adding the following to the pom.xml:

    <build>
     <plugins>
      <plugin>
       <groupId>org.codehaus.mojo</groupId>
       <artifactId>exec-maven-plugin</artifactId>
       <version>1.1.1</version>
       <executions>
        <execution>
         <phase>test</phase>
         <goals>
          <goal>java</goal>
         </goals>
         <configuration>
          <mainClass>Selenium2Example</mainClass>
          <arguments>
           <argument>arg0</argument>
           <argument>arg1</argument>
          </arguments>
         </configuration>
        </execution>
       </executions>
      </plugin>
     </plugins>
    </build>

可以从代码段收集参数,可以通过在pom中列出参数来传递参数。 XML。另外,请确保在 mainClass 元素中使用正确的包名。

As you can probably gather from the snippet, arguments can be passed in by listing them in the pom.xml. Also, be sure to use the proper package name in the mainClass element.

然后您可以运行 mvn编译后跟 mvn test 编译并运行代码。

You can then run mvn compile followed by mvn test to compile and run your code.

信用证必须转到 http: //www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/ 列出了几种方法。

Credit has to go to http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/ for listing several ways to do this.