maven没有打开浏览器

时间:2016-04-13 10:49:27

标签: maven selenium testng

我对测试更新鲜。我开发了一个maven selenium项目。它显示构建失败并显示java.lang.NoClassDefFoundError: org/openqa/selenium/interactions/HasInputDevices.

该问题的原因是什么?在这里,我附上了我的代码。

这是我的项目浏览器窗口 enter image description here

SampleTest.java

package com.java.maven;


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class SecondTest {
    WebDriver driver;

@Test
public void test()
{
    System.out.println("hai");
    System.setProperty("webdriver.chrome.driver", "E:/driver/chromedriver.exe");
    driver = new ChromeDriver();
    driver.get("http://stackoverflow.com");

}
}

POM.xml文件 这是我的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>SecondGroupId</groupId>
  <artifactId>SecondArtifactId</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <name>SecondMaven</name>

  <dependencies>

    <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-api</artifactId>
    <version>2.0rc2</version>
    <scope>test</scope>
    </dependency>

     <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
    <version>2.53.0</version>
    <scope>test</scope>
    </dependency>

    <dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>6.8</version>
  <scope>test</scope>
  </dependency>

 <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>2.53.0</version>
     <scope>test</scope>
</dependency>
 <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-remote-driver</artifactId>
    <version>2.53.0</version>
</dependency>
  </dependencies>

   <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.5.1</version>
          <configuration>
            <!-- put your configurations here -->

          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

</project>

控制台 这是我的控制台,它作为我的输出获得。

[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 SecondMaven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ SecondArtifactId ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ SecondArtifactId ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ SecondArtifactId ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ SecondArtifactId ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ SecondArtifactId ---
[INFO] Surefire report directory: E:\MavenRepository\SecondArtifactId\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.java.maven.SecondTest
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@1ee0005
hai
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.227 sec <<< FAILURE!
test(com.java.maven.SecondTest)  Time elapsed: 0.047 sec  <<< FAILURE!
java.lang.NoClassDefFoundError: org/openqa/selenium/interactions/HasInputDevices
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.java.maven.SecondTest.test(SecondTest.java:17)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.interactions.HasInputDevices
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 58 more


Results :

Failed tests:   test(com.java.maven.SecondTest): org/openqa/selenium/interactions/HasInputDevices

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

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.273 s
[INFO] Finished at: 2016-04-18T11:26:34+05:30
[INFO] Final Memory: 10M/138M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project SecondArtifactId: There are test failures.
[ERROR] 
[ERROR] Please refer to E:\MavenRepository\SecondArtifactId\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

1 个答案:

答案 0 :(得分:1)

你得到objectWithID:;好像你错过了依赖的selenium-remote-driver.jar。

NoClassDefFoundError

注意:我添加了'test',因为您从测试中运行代码。阅读有关maven范围here的更多信息。

http://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-remote-driver/2.53.0

https://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/remote/service/DriverService.html