Watir与webdriver,代理,Firefox [英] Watir with webdriver, proxy, Firefox
问题描述
问题:我需要一个代理。
通过google搜索,我发现了一些代码片段,但是我不能把它们放在一起。
这是我现在制作的,请让我知道我缺少什么:
require'watir- webdriver'
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(network.proxy.http,proxy.myplace.com);
profile.setPreference(network.proxy.http_port,8080);
WebDriver driver = new FirefoxDriver(profile);
browser = Watir :: Browser.new:firefox
browser.goto(http://www.google.com/)
我得到这个错误信息:
I: /watir/webdriver/webdrivertest.rb:3:语法错误,意外的tCONSTANT,expec $ b $ ting keyword_do或'{'或'('
FirefoxProfile profile = new FirefoxProfile();
另外,我不知道如何使用名为'driver'的变量
解决方案调用底层的Selenium WebDriver。
我使用这种技术来设置Firefox 3.6的路径,可以同时测试Firefox 4和3.6:
$ b $ pre $Selenium :: WebDriver :: Firefox.path = ENV ['FIREWATIRPATH']
browser = Watir :: Browser.new:firefox
所以要做你想做的事要做:
profile = Selenium :: WebDriver :: Firefox :: Profile.new
proxy = Selenium :: WebDriver :: Proxy.new(:http =&g t;http://proxy.org:8080)
profile.proxy = proxy
#您必须多做一点才能使用特定的配置文件
driver = Selenium :: WebDriver.for:firefox,:profile => profile
browser = Watir :: Browser.new(driver)
看看: Selenium Ruby Bindings 和
你有什么问题与代理线?
您可以尝试这个:
profile = Selenium :: WebDriver :: Firefox :: Profile.new
profile [network.proxy.type] = 1
profile [network.proxy.http] =proxy.myplace .com
profile [network.proxy.http_port] = 8080
是看你的设置是关于:配置和复制它们的代码。
I am able to use watir-webdriver with IE, but I would prefer to use Firefox. Problem: I need a proxy. By googling around, I found some code snippets, but I am not able to put all them together. This is what I produced up to now, please let me know what am I missing:
require 'watir-webdriver'
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.http", "proxy.myplace.com");
profile.setPreference("network.proxy.http_port", 8080);
WebDriver driver = new FirefoxDriver(profile);
browser = Watir::Browser.new :firefox
browser.goto( "http://www.google.com/" )
I get this error message:
I:/watir/webdriver/webdrivertest.rb:3: syntax error, unexpected tCONSTANT, expec
ting keyword_do or '{' or '('
FirefoxProfile profile = new FirefoxProfile();
Also, I don't know how to use the variable called 'driver'
Call the underlying Selenium WebDriver.
I've used this technique to set a path to Firefox 3.6 so I can test with both Firefox 4 and 3.6:
Selenium::WebDriver::Firefox.path = ENV['FIREWATIRPATH']
browser = Watir::Browser.new :firefox
So to do what you're trying to do:
profile = Selenium::WebDriver::Firefox::Profile.new
proxy = Selenium::WebDriver::Proxy.new(:http => "http://proxy.org:8080")
profile.proxy = proxy
# You have to do a little more to use the specific profile
driver = Selenium::WebDriver.for :firefox, :profile => profile
browser = Watir::Browser.new(driver)
Look at: Selenium Ruby Bindings and Webdriver FAQ for more info.
What problem are you having with the Proxy line?
You could try this:
profile = Selenium::WebDriver::Firefox::Profile.new
profile["network.proxy.type"] = 1
profile["network.proxy.http"] = "proxy.myplace.com"
profile["network.proxy.http_port"] = 8080
The idea is to see what your settings are in about:config and duplicating them in code.
这篇关于Watir与webdriver,代理,Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!