如何使用maven从命令行运行硒测试? [英] How do I run a selenium test using maven from the command line?

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

问题描述

我目前使用Eclipse作为我的Java IDE,我使用Maven。我点击运行按钮,它可以运行我写的Selenium Java测试。



然后我继续在我的本地机器上安装Maven。



进入我的pom.xml文件所在的目录。
我运行命令:mvn test



我收到以下结果:

  [INFO]扫描项目... 
[INFO]
[INFO]使用构建器org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBu $ b $线程数为1
[INFO]
[INFO] ---------------------------- --------------------------------------------
[信息] Building SeleniumWebDriver 0.0.1-SNAPSHOT
[INFO] ----------------------------------- -------------------------------------
[INFO]
[INFO ] --- maven-resources-plugin:2.6:resources(default-resources)@ SeleniumWebDriver ---
[WARNING]使用平台编码(Cp1252实际)来复制过滤的资源,即build是platfo
rm依赖
[INFO]复制0资源
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile(default-compile)@ SeleniumWebDriver ---
[INFO]没有编译 - 所有类都是最新的
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources(default-testResources)@ SeleniumWebDriver - -
[警告]使用平台编码(Cp1252实际)来复制过滤的资源,即build是platfo
rm依赖!
[INFO]复制0资源
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile(default-testCompile)@ SeleniumWebDriver ---
[INFO]没有什么可以编译 - 所有类都是最新的
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test(default-test)@ SeleniumWebDriver ---
[INFO] ---------------------------------------- --------------------------------
[INFO] BUILD SUCCESS
[INFO] - -------------------------------------------------- --------------------
[INFO]总时间:1.139 s
[INFO]完成于:2014-03-17T14:12: 27-05:00
[INFO] Final Memory:12M / 99M
[INFO] ------------------------- -----------------------------------------------

我不明白为什么Firefox浏览器不启动,并且测试运行。在Eclipse IDE中运行相同的测试时,Firefox webBrowser确实启动。



似乎编译正常,但是由于某些原因,没有测试或启动浏览器它有编译后的.class文件。



这是我的pom.xml文件的一个副本:

 < project xmlns =http://maven.apache.org/POM/4.0.0xmlns:xsi =http://www.w3.org/2001/XMLSchema-实例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> SeleniumWebDriver< / groupId>
< artifactId> SeleniumWebDriver< / artifactId>
< version> 0.0.1-SNAPSHOT< / version>
<依赖关系>
<依赖关系>
< groupId> org.seleniumhq.selenium< / groupId>
< artifactId> selenium-java< / artifactId>
< version> 2.40.0< / version>
< / dependency>
<依赖关系>
< groupId> org.seleniumhq.selenium< / groupId>
< artifactId> selenium-firefox-driver< / artifactId>
< version> 2.40.0< / version>
< / dependency>
<依赖关系>
< groupId> org.seleniumhq.selenium< / groupId>
< artifactId> selenium-server< / artifactId>
< version> 2.40.0< / version>
< / dependency>
<依赖关系>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< version> 4.11< / version>
< / dependency>
< / dependencies>
< / project>


解决方案

这是一个较旧的线程,但仍然希望提供为那些被困在这个的人的输入。您必须确保您正在创建的类文件名称以Test字符串结尾。
例如AppTest,TempTest都是有效的类文件名,但AppCheck,TempTest1是无效的名称; maven将不会检测到这些文件执行。


I currently use Eclipse as my Java IDE and I use Maven. I click the run button and it is able to run a Selenium Java test I wrote.

I then proceeded to install Maven on my local machine.

After going to the directory where my pom.xml file is located. I run the command: mvn test

I receive the following results:

[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBu
ilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building SeleniumWebDriver 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ SeleniumWebDriver ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platfo
rm dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ SeleniumWebDriver ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ SeleniumWebDriver ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platfo
rm dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ SeleniumWebDriver ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ SeleniumWebDriver ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.139 s
[INFO] Finished at: 2014-03-17T14:12:27-05:00
[INFO] Final Memory: 12M/99M
[INFO] ------------------------------------------------------------------------

I do not understand why the Firefox webbrowser does not start, and a test is ran. When running the same test in the Eclipse IDE the Firefox webBrowser does start.

It seems to compile fine, but it is for some reason not testing or kicking off the browser when it has the .class files after compilation.

here is a copy of my pom.xml file:

<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>SeleniumWebDriver</groupId>
  <artifactId>SeleniumWebDriver</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.40.0</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-firefox-driver</artifactId>
        <version>2.40.0</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>2.40.0</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
    </dependency>
  </dependencies>
</project>

解决方案

This is a older thread, but still want to provide input for those who are stuck up at this. You have to make sure that the class file names you are creating are ending with "Test" string. e.g. AppTest, TempTest are all valid class file names, but AppCheck, TempTest1 are invalid name; maven will not detect these files for execution.

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

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