Seleniumを覚える エラー対応(Couldn't proxy to http://xxxxxxx/ because host not found)
2015/04/19
前回やっとこさSeleniumを動かせたので、ケースをカスタマイズする方法を確認しようとしたらエラーに遭遇したら
やってみる
www.google.com/を操作しようとしたら、一発でエラー。
1 2 3 4 |
17:03:20.078 INFO - Couldn't proxy to http://goshiuvtch/ because host not found 17:03:20.109 INFO - Couldn't proxy to http://hsssrubbak/ because host not found 17:03:20.125 INFO - Couldn't proxy to http://warvkdkskr/ because host not found 17:03:39.656 INFO - Got result: Timed out after 30000ms on session 9217e1c060ef4cc699833ab9ea1f4c1c |
下記URLと同じ現象だなこれ。
一回寝て、考え直して、調べ直したらうまくいきました。
要はSeleniumServerからのプロキシ指定がうまくいっていなかった。(社内環境なのでプロキシ指定が必須なのです。)
じゃあどうすればSeleniumサーバーからのプロキシ設定ができるのかというと
1 |
java -Dhttp.proxyHost=プロキシホスト名 -Dhttp.proxyPort=プロキシポート番号 -jar selenium-server-standalone-2.22.0.jar |
というように「-Dhttp.proxyHost」「-Dhttp.proxyPort」のオプションを追加してあげればよい。
でもそうすると(サーバーをコマンドプロンプトで起動しJUnitで実行すると)javaプログラム内で下記のようにサーバーを起動していたものとサーバー起動が重複してしまい、エラーになります。
例の「Failed to start: SocketListener0@0.0.0.0:4444」です。
なのでTestBase.javaのサーバー起動部分とサーバー停止部分をコメントアウトしてしまいました。(★を付けている行が今回コメントアウトした行です。)
TestBase.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
protected void setUp() throws Exception { // プロパティファイル読み込み try { prop.load(this.getClass().getResourceAsStream( "testconfig.properties")); } catch (IOException e) { e.printStackTrace(); } // テスト対象のサーバURL&ブラウザ設定をプロパティから読み込む testUrl = prop.getProperty("SeleniumTest.URL"); testBrowser = prop.getProperty("SeleniumTest.Browser"); // SeleniumServerを起動する。 //★seleniumServer = new SeleniumServer(); //★seleniumServer.start(); // seleniumインスタンス起動。プロパティから読み込んだ設定を使用 selenium = new DefaultSelenium("localhost", 4444, testBrowser, testUrl); selenium.start(); } protected void tearDown() throws Exception { // Seleniumインスタンスを停止。 selenium.stop(); // SeleniumServerを停止する。 //★seleniumServer.stop(); } |
関連記事
-
-
どうしてもSelenium-IDEが使いたい そのためには古いFireFoxが欲しい!!
(2015/03/11補足) 最近のfirefoxは無理くり入れられる。下記から …
-
-
【Selenium】【ruby】Casperjsでどうも取得できないページがあるので…Selenium-webdriver!!
casperでダメなサイトがあったので…webdriverを試してみ …
-
-
Selenium Web Driver使い方 (java)
ここが凄い丁寧で分かりやすい。 http://d.hatena.ne.jp/su …
-
-
Seleniumを覚える Selenium-RCの実行
Slenium公式のドキュメントを見ていたら分からなくなったので、別サイトを参考 …