2012-06-22 20 views
9

ruby​​ selenium webdriverを使っていくつかの基本的な自動テストを実行しようとしました。同じコードは私の家のコンピュータではうまく動作しますが、認証を必要としないプロキシの背後にある私の仕事用コンピュータでは失敗します。ruby​​ selenium webdriverを使ってブラウザに接続できません

ドライバ=セレン:: WebDriver.for:Firefoxの、:プロファイル=> 'デフォルト'

私が手にエラーがある:

C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.24.0/lib/selenium/webdriver/remote/http/common.rb:66:in `create_response': unexpected response, code= 
403, content-type="text/html" (Selenium::WebDriver::Error::WebDriverError) 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> 
<TITLE>ERROR: The requested URL could not be retrieved</TITLE> 
<STYLE type="text/css"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}PRE{font-family:sans-serif}--></STYLE> 
</HEAD><BODY> 
<H1>ERROR</H1> 
<H2>The requested URL could not be retrieved</H2> 
<HR noshade size="1px"> 
<P> 
While trying to retrieve the URL: 
<A HREF="http://127.0.0.1:7055/hub/session">http://127.0.0.1:7055/hub/session</A> 
<P> 
The following error was encountered: 
<UL> 
<LI> 
<STRONG> 
Access Denied. 
</STRONG> 
<P> 
Access control configuration prevents your request from 
being allowed at this time. Please contact your service provider if 
you feel this is incorrect. 
</UL> 

ブラウザは、ドライバ変数を結果として正しいプロファイルを開きますが、ありません。私は運がないとプロファイル上のプロキシを手動で設定しようとしました。

アイデア?

答えて

16

環境内にHTTP_PROXY(またはhttp_proxy)が設定されている可能性があります。 selenium-webdriver(2.25)の次のリリースでは、NO_PROXY/no_proxy(NO_PROXY = 127.0.0.1に設定することもできます)を守ります。あなたが外の世界と通信するFirefox用に設定されたプロキシが必要な場合は

ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil 
driver = Selenium::WebDriver.for :firefox 

は、あなたがこのような何かを試みることができる:

proxy = Selenium::WebDriver::Proxy.new(:http => ENV['HTTP_PROXY'] || ENV['http_proxy']) 
ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil 
driver = Selenium::WebDriver.for :firefox, :proxy => proxy 
それまでは、ブラウザを起動する前にRubyの環境からプロキシを削除することができます
+0

私はNO_PROXY = 127.0.0.1は、問題を解決した設定、セレンwebdriverを2.26.0を使用しています。 –

+0

うわー、これは実際に私のために働いた。 –

3

プロキシの背後にあるselenium-webdriverの使用には、ブラウザに固有のものがあります。つまり、webdriverによって作成されたブラウザインスタンスにプロキシ設定を渡す方法を見つける必要があります。

以下はFirefoxで動作するコードです。

#Firefox keeps proxy settings in profile. 
profile = Selenium::WebDriver::Firefox::Profile.new 
profile.proxy = Selenium::WebDriver::Proxy.new(:http => "192.168.1.1:3128") 
driver = Selenium::WebDriver.for :firefox, :profile => profile 

driver.navigate.to "http://google.com" 
puts driver.title 
driver.quit 
-1
require 'rubygems' 
require 'selenium-webdriver' 
ENV['NO_PROXY']="127.0.0.1" 
driver = Selenium::WebDriver.for :firefox 
driver.get "http://google.com" 
+4

ようこそStackOverflowへ!たぶん、あなたの答えを説明するテキストを追加することができますか? – franssu

関連する問題