简体   繁体   中英

watir-webdriver & proxy credentials

I'm trying to use watir-webdriver/ruby within a corporate environment but am encountering issues with the need for entering proxy credentials in order to access the system under test.

I've read various snippets from other forums, including Alister Scott's helpful tips on setting proxies in general and saving them to profiles. That, however still doesn't get me past the actual need to enter proxy credentials.

Two tacks I can think of include

Option 1: Somehow save the credentials in the same manner as the proxy itself. Eg

profile = Selenium::WebDriver::Firefox::Profile.new
profile.proxy = Selenium::WebDriver::Proxy.new :http => 'myproxy.com:8080', :ssl =>     'myproxy.com:8080'
# COMMAND FOR PROXY CREDENTIALS?
b = Watir::Browser.new :firefox, :profile => profile

Option 2: Use my default profile which has the proxy credentials saved but still requires some webdriver code to click on the 'OK' button (and possibly more with the 'I Understand the Risks' dialog, etc. after)

b = Watir::Browser.new :firefox, :profile => 'default'

I'm not allowed to post images yet as a newbie but dialog text says

The proxy [BLAH] is requesting a username and password. The site says [BLAH] User Name: Password: [OK] [Cancel]

Any suggestions gladly welcomed.

UPDATE I managed to get something to work which was using the default profile and tweaking a firefox setting called 'signon.autologin.proxy' - set this to true (tap in about:config in the browser, filter on 'prox' and it should appear to the bottom)

Would still prefer a watir-webdriver based solution though ;-)

If you need one particular proxy server for a system under test and another for general usage, I would suggest that you look at using a PAC file for that. Link to Automatically Configuring Browsers for Proxy .

Example Script:

function FindProxyForURL(url, host)
{
if (shExpMatch(url, "http://principia.mo.techpaths.com*")) {
return "DIRECT";
}
if (isInNet(myIpAddress(), "192.168.1.0", "255.255.255.0"))
return "PROXY 192.168.1.1:8080";
else
return "DIRECT";
}

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM