java - 如何从命令行使用 maven 运行 selenium 测试?

标签 java eclipse maven selenium

我目前使用 Eclipse 作为我的 Java IDE,我使用 Maven。我单击运行按钮,它能够运行我编写的 Selenium Java 测试。

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

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

我收到以下结果:

[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] ------------------------------------------------------------------------

我不明白为什么 Firefox 网络浏览器没有启动,并运行了一个测试。在 Eclipse IDE 中运行相同的测试时,Firefox webBrowser 会启动。

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

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

<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>

最佳答案

这是一个较旧的线程,但仍然想为那些被困在这个问题上的人提供意见。您必须确保正在创建的类文件名以“Test”字符串结尾。 例如AppTest、TempTest 都是有效的类文件名,而 AppCheck、TempTest1 是无效的名称; maven 不会检测这些文件来执行。

关于java - 如何从命令行使用 maven 运行 selenium 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22462181/

相关文章:

java - android - Google Play 商店上未显示更新按钮

eclipse - 从jar或Eclipse中排除文件

java - 这种依赖给了我一个 jar 的两个版本。我该如何解决?

java - Maven 错误 - java.lang.NoClassDefFoundError : org/slf4j/helpers/MarkerIgnoringBase

java - Jetty 11 不检测 Servlet

java - 查找对象 ArrayList 中每个字段的最小值/最大值的有效方法

java - 双 while 循环读取文本文件

java - 在没有 persistence.xml 或 orm.xml 的情况下使用 IntelliJ 生成 JPA 实体

java - 如何更改 Eclipse SpringSource 插件使用的 Gradle 版本?

java - 如何让 eclipse 插件监听新编译的项目?