質問編集履歴

2

解決策のまとめ

2016/08/31 08:34

投稿

takuan_no_hito
takuan_no_hito

スコア27

test CHANGED
File without changes
test CHANGED
@@ -107,3 +107,153 @@
107
107
  .classpath
108
108
 
109
109
  .project
110
+
111
+
112
+
113
+
114
+
115
+ ###解決策
116
+
117
+ 後に私の様な方が出たときのために一応この質問に伴い学んだことを付記しておきます。
118
+
119
+
120
+
121
+ まず、エラーの見方。
122
+
123
+ コマンドプロンプトから*.jarを実行すると、エラーコードが見られる。(常識なんでしょうか)
124
+
125
+ ```
126
+
127
+ >java -jar *.jar
128
+
129
+ Error (略)
130
+
131
+ ```
132
+
133
+
134
+
135
+ 2つ目に*.exeファイルは.jarの外部に置く。今回はchromedriver.exeでした。.java内でのソースコードは以下のようにして、実際にC:/chromedriverのフォルダー内にchromedriver.exeを置きました。
136
+
137
+ ```java
138
+
139
+ System.setProperty("webdriver.chrome.driver", "C:/chromedriver/chromedriver.exe");
140
+
141
+ ```
142
+
143
+
144
+
145
+ 3つ目は、¥Main-ClassをMANIFEST.MF内で設定するということ。「jar にメイン・マニフェスト属性がありません」というエラーが出たときはこの設定がなされていない可能性があるらしいです。
146
+
147
+
148
+
149
+ 最後は、JUnitテストでは、*.jarファイルにエクスポートしたときに起動しないこと。eclipseにて「右クリック→実行→JUnitテスト」で実行している場合、*.jarファイルにエクスポートしたときにエラーになります。
150
+
151
+
152
+
153
+ 参考までに、JUnitテストで実行する場合のソースコード(上)と、Javaアプリケーションで実行する場合のソースコード(下)を記しておきます。尚、このソースコードは素人が頑張って作ったものですので、参考程度にしておいて下さい。
154
+
155
+ ```java
156
+
157
+ //JUnitバージョン
158
+
159
+
160
+
161
+ import org.junit.Assert;
162
+
163
+ import org.junit.BeforeClass;
164
+
165
+ import org.junit.Test;
166
+
167
+ import org.openqa.selenium.By;
168
+
169
+ import org.openqa.selenium.Keys;
170
+
171
+ import org.openqa.selenium.WebDriver;
172
+
173
+ import org.openqa.selenium.WebElement;
174
+
175
+ import org.openqa.selenium.chrome.ChromeDriver;
176
+
177
+ public class WebTest {
178
+
179
+
180
+
181
+ @BeforeClass
182
+
183
+ public static void Setup() {
184
+
185
+ System.setProperty("webdriver.chrome.driver", "C:/chromedriver/chromedriver.exe");
186
+
187
+ }
188
+
189
+
190
+
191
+ @Test
192
+
193
+ public void main() {
194
+
195
+ WebDriver driver = new ChromeDriver();
196
+
197
+ driver.get("https://www.google.co.jp/");
198
+
199
+ driver.quit();
200
+
201
+ }
202
+
203
+ ```
204
+
205
+
206
+
207
+ ```java
208
+
209
+ //Javaアプリケーションバージョン
210
+
211
+ import org.junit.Assert;
212
+
213
+ import org.openqa.selenium.By;
214
+
215
+ import org.openqa.selenium.Keys;
216
+
217
+ import org.openqa.selenium.WebDriver;
218
+
219
+ import org.openqa.selenium.WebElement;
220
+
221
+ import org.openqa.selenium.chrome.ChromeDriver;
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+ public class WebTest {
230
+
231
+
232
+
233
+ public static void main(String[] args){
234
+
235
+ (new WebTest5()).run();}
236
+
237
+
238
+
239
+ public static void Setup() {
240
+
241
+ System.setProperty("webdriver.chrome.driver", "C:/chromedriver/chromedriver.exe");
242
+
243
+ }
244
+
245
+
246
+
247
+ public void run() {
248
+
249
+ Setup();
250
+
251
+ WebDriver driver = new ChromeDriver();
252
+
253
+ driver.get("https://www.google.co.jp/");
254
+
255
+ driver.quit();
256
+
257
+ }
258
+
259
+ ```

1

改善

2016/08/31 08:34

投稿

takuan_no_hito
takuan_no_hito

スコア27

test CHANGED
File without changes
test CHANGED
@@ -10,67 +10,51 @@
10
10
 
11
11
 
12
12
 
13
+
14
+
15
+ 追記(16/08/31,10:28)エラーメッセージを付記
16
+
17
+
18
+
19
+ Error: A JNI error has occurred, please check your installation and try again
20
+
21
+ Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/W
22
+
23
+ ebDriver
24
+
25
+ at java.lang.Class.getDeclaredMethods0(Native Method)
26
+
27
+ at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
28
+
29
+ at java.lang.Class.privateGetMethodRecursive(Unknown Source)
30
+
31
+ at java.lang.Class.getMethod0(Unknown Source)
32
+
33
+ at java.lang.Class.getMethod(Unknown Source)
34
+
35
+ at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
36
+
37
+ at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
38
+
39
+ Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
40
+
41
+ at java.net.URLClassLoader.findClass(Unknown Source)
42
+
43
+ at java.lang.ClassLoader.loadClass(Unknown Source)
44
+
45
+ at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
46
+
47
+ at java.lang.ClassLoader.loadClass(Unknown Source)
48
+
49
+ ... 7 more
50
+
51
+
52
+
13
- ###.classpathのソースコード
53
+ ###ソースコード
14
54
 
15
55
  ```
16
56
 
17
- <?xml version="1.0" encoding="UTF-8"?>
18
57
 
19
- <classpath>
20
-
21
- <classpathentry kind="src" path="src/test"/>
22
-
23
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
24
-
25
- <classpathentry kind="lib" path="lib/apache-mime4j-0.6.jar"/>
26
-
27
- <classpathentry kind="lib" path="lib/bsh-2.0b4.jar"/>
28
-
29
- <classpathentry kind="lib" path="lib/cglib-nodep-2.1_3.jar"/>
30
-
31
- <classpathentry kind="lib" path="lib/commons-codec-1.10.jar"/>
32
-
33
- <classpathentry kind="lib" path="lib/commons-exec-1.3.jar"/>
34
-
35
- <classpathentry kind="lib" path="lib/commons-io-2.4.jar"/>
36
-
37
- <classpathentry kind="lib" path="lib/commons-logging-1.2.jar"/>
38
-
39
- <classpathentry kind="lib" path="lib/gson-2.3.1.jar"/>
40
-
41
- <classpathentry kind="lib" path="lib/guava-19.0.jar"/>
42
-
43
- <classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
44
-
45
- <classpathentry kind="lib" path="lib/hamcrest-library-1.3.jar"/>
46
-
47
- <classpathentry kind="lib" path="lib/httpclient-4.5.1.jar"/>
48
-
49
- <classpathentry kind="lib" path="lib/httpcore-4.4.3.jar"/>
50
-
51
- <classpathentry kind="lib" path="lib/httpmime-4.5.jar"/>
52
-
53
- <classpathentry kind="lib" path="lib/jcommander-1.48.jar"/>
54
-
55
- <classpathentry kind="lib" path="lib/jna-4.1.0.jar"/>
56
-
57
- <classpathentry kind="lib" path="lib/jna-platform-4.1.0.jar"/>
58
-
59
- <classpathentry kind="lib" path="lib/junit-4.12.jar"/>
60
-
61
- <classpathentry kind="lib" path="lib/netty-3.5.7.Final.jar"/>
62
-
63
- <classpathentry kind="lib" path="lib/phantomjsdriver-1.2.1.jar"/>
64
-
65
- <classpathentry kind="lib" path="lib/selenium-java-2.53.0-srcs.jar"/>
66
-
67
- <classpathentry kind="lib" path="lib/selenium-java-2.53.0.jar"/>
68
-
69
- <classpathentry kind="lib" path="lib/testng-6.9.9.jar"/>
70
-
71
- <classpathentry kind="output" path="bin"/>
72
-
73
- </classpath>
74
58
 
75
59
 
76
60
 
@@ -81,6 +65,28 @@
81
65
  ###試したこと
82
66
 
83
67
  Seleniumのpathが通っていないのではと考えています。
68
+
69
+
70
+
71
+ 追記(16/08/31,10:28)
72
+
73
+ ご指摘を受けて、ソースコードを以下の様に変更しました。
74
+
75
+
76
+
77
+ ```
78
+
79
+ public static void Setup() {
80
+
81
+ System.setProperty("webdriver.chrome.driver", "C:/Users/..(中略)../chromedriver/chromedriver.exe");
82
+
83
+ }
84
+
85
+ //尚、修正は、 "./driver/chromedriver.exe" → "C:/Users/..(中略)../chromedriver/chromedriver.exe"です。
86
+
87
+ ```
88
+
89
+ C:/Users/..(中略)../chromedriver のファイルには実際にchromedriver.exeが入っていることは確認済みであり、Eclipse内での正常な挙動を確認しています。
84
90
 
85
91
 
86
92