2016-04-13 12 views
-1

私はテストにもっと慣れています。私はmaven seleniumプロジェクトを開発しました。ビルドの失敗を示し、java.lang.NoClassDefFoundError:org/openqa/selenium/interactions/HasInputDevicesを表示しました。その問題。ここに私のコードを添付しました。mavenはブラウザを開きません

これは私のプロジェクトエクスプローラウィンドウです。
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: [email protected]005 
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 
+2

あなたが書いたコードを追加し、あなたの質問を変更することができます。あなたのコンソール出力を追加してください。 質問中に[ガイドライン](http://stackoverflow.com/help/how-to-ask)に従ってください。 – Paras

+0

pArAs、私のmistake.Now申し訳ありません私のコードを追加し、私の質問をコンソール。 –

+0

「SampleTest」クラスを正確に保存したプロジェクト構造を私に見せてもらえますか。 – Paras

答えて

1

NoClassDefFoundErrorが得られます。依存関係からselenium-remote-driver.jarが欠けているようです。

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

注:テストからコードを実行するため、「テスト」を追加しました。 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

+0

あなたの答えをありがとう。しかし、それは同じエラーが表示されます。 –

+0

次の依存関係を追加した後も同じエラーが表示されますか? ? – OhadR

+0

ええ、私は同じエラーを持っています。エラーを避けるために他の方法がありますか? –

関連する問題