如何使用Maven运行我的Selenium测试? [英] How can I run my Selenium tests with Maven?

查看:123
本文介绍了如何使用Maven运行我的Selenium测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何运行Selenium WebDriver测试,而不必使用Eclipse或者IntelliJ或任何其他的IDE。我使用纯文本编辑器进行所有的java开发,而不是为了编译和运行测试而不需要安装(并学习)IDE。

I'm trying to figure out how to run Selenium WebDriver tests without having to use Eclipse or IntelliJ or any other IDE. I do all my java development using a plain text editor, and don't want to have to install (and learn) an IDE just for the sake of compiling and running tests.

我已经尝试遵循Selenium文档,但实际上并没有告诉你如何从命令行运行测试。

I've tried following the Selenium documentation, but it stops short of actually telling you how to run the tests from the command line.

我对maven的简短体验量到以下内容:

My brief experience with maven amounts to the following:

    $ mvn compile
    <snip>
    No sources to compile

    $ mvn test
    <snip>
    No tests to run

    $ mvn run
    <snip>
    Invalid task 'run'

我知道的唯一的另一个是 mvn jetty:run 但是似乎不正确,因为我不想运行一个新的网络服务器。

The only other one I know is mvn jetty:run but that doesn't seem right as I'm not wanting to run a new web server.

我怀疑我只需要在我的pom.xml中设置正确的目标等等,但我不知道应该是什么,并且令人惊讶地找不到任何在线的。

I suspect I just need to set the correct targets etc in my pom.xml, but I don't know what they should be, and surprisingly can't find any online.

可以有人帮忙吗?

推荐答案

好的,我终于明白了,这实际上是一个特定于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.

这篇关于如何使用Maven运行我的Selenium测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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