商用の自動テストツールを使用しつつ
無料の自動テストツールSeleniumについて学習している初心者です。
2016年初版と古いと思いつつ、技術評論社のSelenium実践入門を見ながら
環境を構築していきましたが、Maven+installでビルド後、コマンドプロンプトでの
実行でエラーが発生し行き詰っております。
対応方法わかりましたら、ご教授いただきたいです。
Windows10
Java1.8.0
Maven3.8.1
selenium-*-driver-3.141.59.jar
EclipseIDEVersion: 2021-03 (4.19.0)
FireFox 89.0.2 (64 ビット)
実行とエラーは以下のとおりです。---------------------------------------------------------------------------------
C:\WINDOWS\system32>java -classpath "C:\eclipse\libs\*.jar;C:\Users\user\selenium-java\workdir\webtest\target\webtest-0.0.1-SNAPSHOT.jar" webtest.SampleScript
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
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)
... 7 more
--------------------------------------------------------------------------------------------------------------------------------------
ビルド時のメッセージがこちら
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/eclipse/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/C:/eclipse/configuration/org.eclipse.osgi/8/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/eclipse/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/C:/eclipse/configuration/org.eclipse.osgi/8/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
[WARNING]
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: 'blocked' (position: START_TAG seen ...</url>\r\n <blocked>... @171:16) @ C:\apache-maven-3.8.1\conf\settings.xml, line 171, column 16
[WARNING]
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< maven.test:legalwebtest >-----------------------
[INFO] Building legalwebtest 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ legalwebtest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ legalwebtest ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ legalwebtest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ legalwebtest ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ legalwebtest ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ legalwebtest ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ legalwebtest ---
[INFO] Installing C:\Users\user\selenium-java\workdir\legalwebtest\target\legalwebtest-0.0.1-SNAPSHOT.jar to C:\apache-maven-3.8.1\repository\maven\test\legalwebtest\0.0.1-SNAPSHOT\legalwebtest-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\Users\user\selenium-java\workdir\legalwebtest\pom.xml to C:\apache-maven-3.8.1\repository\maven\test\legalwebtest\0.0.1-SNAPSHOT\legalwebtest-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.015 s
[INFO] Finished at: 2021-06-23T23:08:12+09:00
[INFO] ------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------
コードはこちら
/**
*
*/
package webtest;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
/**
* @author user
*
*/
public class SampleScript {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
WebDriver driver = new FirefoxDriver();
driver.findElement(By.id("guestname")).sendKeys("サンプルユーザ");
driver.findElement(By.id("goto_next")).click();
driver.quit();
//System.out.println("Hello Maven World!");
}
}
--------------------------------------------------------------------------------------------------------------
WebDriverを使用しているものをコメントあうとして、
System.out.printlnだけでビルド、実行は問題なくできました。
以上、よろしくお願い申し上げます。