为什么我的简单硒测试没有通过maven运行

时间:2015-09-25 04:00:22

标签: java maven selenium

我无法通过maven测试运行以下简单的硒测试。但是,当我右键单击测试并运行时,Java应用程序工作正常。

我写了一个非常基本的selenium脚本,如下所示:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class sampleTest 
{
    public static void main(String[] args) 
    {
        WebDriver driver=new FirefoxDriver();
        driver.get("http://www.google.com");
        System.out.println(driver.getTitle());
        driver.quit();
    }
}

以下是我的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>MavenHybridFramework</groupId>
  <artifactId>MavenHybridFramework</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties>
  <dependencies>
      <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.47.1</version>
      </dependency>
      <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.1.1</version>
        <scope>test</scope>
      </dependency>
    </dependencies>

    <build>
        <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                <source>1.6</source>
                <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
            </plugin>
        </plugins>
    </pluginManagement>
  </build>
</project>

我只将java配置为JDK,以下是我得到的控制台输出:

[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder  org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building MavenHybridFramework 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenHybridFramework ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ MavenHybridFramework ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MavenHybridFramework ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ MavenHybridFramework ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ MavenHybridFramework ---
[INFO] Surefire report directory: D:\UD\Frameworks\MavenHybridAF\target\surefire-reports
[INFO] Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-testng/2.18.1/surefire-testng-2.18.1.pom
[INFO] Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-testng/2.18.1/surefire-testng-2.18.1.pom (4 KB at 1.9 KB/sec)
[INFO] Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-testng-utils/2.18.1/surefire-testng-utils-2.18.1.pom
[INFO] Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-testng-utils/2.18.1/surefire-testng-utils-2.18.1.pom (3 KB at 3.5 KB/sec)
[INFO] Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-testng-utils/2.18.1/surefire-testng-utils-2.18.1.jar
[INFO] Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-testng/2.18.1/surefire-testng-2.18.1.jar
[INFO] Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-testng/2.18.1/surefire-testng-2.18.1.jar (36 KB at 29.8 KB/sec)
[INFO] Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-testng-utils/2.18.1/surefire-testng-utils-2.18.1.jar (29 KB at 19.8 KB/sec)

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running sampleTest
Configuring TestNG with: TestNGMapConfigurator
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.479 sec - in sampleTest

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.131 s
[INFO] Finished at: 2015-09-25T09:22:11+05:30
[INFO] Final Memory: 8M/20M
[INFO] ------------------------------------------------------------------------

2 个答案:

答案 0 :(得分:0)

我们使用sevenium-maven-plugin和maven-failsafe-plugin。您可以通过在pom.xml

中搜索stest来了解我们如何设置我们的

答案 1 :(得分:0)

要将代码作为Maven Test运行,您需要将代码置于@Test注释之下。对于您的代码:

@Test
public void test()
    {
        WebDriver driver=new FirefoxDriver();
        driver.get("http://www.google.com");
        System.out.println(driver.getTitle());
        driver.quit();
    }