How to configure Safari webdriver to use .pac file - ruby

I am working on automation repo with Ruby and Watir framework. I found a ways to set the pac file for chrome and firefox webfrivers.
Examples:
chrome: args << "--proxy-pac-url=#{pac_file_path}"
firefox: profile['network.proxy.autoconfig_url'] = pac_file_path
My question is how can I set it for Safari webdriver ?
Thanks !

Theoretically you should be using a proxy configuration in your capabilities. There was a bug with Selenium Options and Proxy until Selenium 4 beta 4, which was just released.
I encourage everyone to upgrade to Watir 7 and Selenium 4 even though they are still technically in beta, they are more reliable than the latest release of 6.x and 3.x.
With Watir 7.0.0.beta4 and Selenium 4.0.0.beta4 you should be able to do this:
proxy = Selenium::WebDriver::Proxy.new(type: :pac,
proxy_autoconfig_url: pac_file_path)
Watir::Browser.new :safari, options: { proxy: proxy }
Once I merge this PR and release Watir 7.0.0.beta5, then this will work:
Watir::Browser.new :safari, proxy: {type: :pac,
proxy_autoconfig_url: pac_file_path}

Related

Setting browser settings in Watir

Because of some bugs when using Watir in Chrome 103, I've downloaded Chrome Beta 104 and set it as the default browser. Watir still keeps using 103 though.
I've also tried setting the browser version in the parameters but didn't help.
prefs = {
intl: {accept_languages: 'en-GB'},
browserVersion: '104.0.5112.48' # also tried 'browser_version' and didn't work either
}
b = Watir::Browser.new :chrome, options: {prefs: prefs}
How do I make it use Chrome 104?
Yes, Chrome does not properly deal with browserVersion:
https://bugs.chromium.org/p/chromedriver/issues/detail?id=3849
You need to pass in:
binary: '/path/to/beta'
https://chromedriver.chromium.org/capabilities#h.p_ID_106

Unsupported command-line flag: --ignore-certificate-errors (in Ruby)

Using Ruby 2.0.0 p481 in RubyMine and chromedriver 2.10
When Chrome starts it displays a message in a yellow popup bar: "You are using an unsupported command-line flag: --ignore-certificate-errors. Stability and security will suffer." This simple example reproduces the problem.
require "selenium-webdriver"
driver = Selenium::WebDriver.for :chrome
driver.navigate.to login_url
This question has been answered for Java and Python. I have looked everywhere for a Ruby analog. Does anyone have a suggestion or know how to translate the Python answer (Unsupported command-line flag: --ignore-certificate-errors) to Ruby? Thank you!
The Ruby selenium-webdriver API doesn't expose a separate Chrome options object like Java/Python but you can set the options via "Capabilities".
The Capabilities web page provides a Ruby example and the table of recognized capabilities that you can inject. Plugging those together with excludeSwitches:
caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"excludeSwitches" => [ "--ignore-certificate-errors" ]})
driver = Selenium::WebDriver.for :chrome, desired_capabilities: caps
Take a look at Watir too, it's a front end for WebDriver.
Their examples show how you can send a :switches array which is passed straight through to the web driver so you can do the same. That makes adding other switches a bit easier rather than going through capabilities.
There is a chromedriver issue on the topic as well. There are posts detailing that you can add a --test-type argument to work around the certificate issue and ruby code examples like above.
I adjusted:
driver = Selenium::WebDriver.for :chrome
to read:
driver = Selenium::WebDriver.for :chrome, :switches => %w[--test-type]
...and the script ran successfully without the yellow flag. Clearly, other command-line switches could be added.
Thank you to Nguyen Vu Hoang and mtm.
I donot know ruby, however my approach is set mode "test-type" to ChromeDriver capabilities
Here's my sample code in Java
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type", "start-maximized",
"no-default-browser-check");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
With Capybara:
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome, switches: ['--test-type'])
end
This error caused my rspec tests to fail. I think it was causing Chrome to slow down so the above fixes did remove the error messages but did not resolve my problem of my tests failing.
If you are using chromedriver-helper then this should fix the problem. Run this from the command line
chromedriver-update
This is described more in chromedriver-helper, "This might be necessary on platforms on which Chrome auto-updates, which has been known to introduce incompatibilities with older versions of chromedrive"
Once I ran this I was able to remove the fixes described elsewhere and Chrome ran with out warnings.

How to bypass website's security certificate in IE using Ruby/Selenium WebDriver

I am trying to automate some IE browser tests using Ruby/Selenium WebDriver.
When I run the following code, it opens a new IE browser with the url but it always tells that 'There is a problem with this website's security certificate.'
Is there any way to set the IE profile/capabilities using Ruby similar to the ones used in Java?
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :ie
driver.get "https://xxxxxxxxxxxxxxxxxx.com"
There's no way to set it by any capabilities, even if you were using Java. If you have found any approaches to achieve it in Java, please post it and see if it can be translated into Ruby.
But you can always simulate the clicking to bypass it.
# Tested under Windows 7, IE 10, Ruby 2.0.0
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :ie
driver.get "https://xxxxxxxxxxxxxxxxxx.com"
driver.get("javascript:document.getElementById('overridelink').click()");

Ruby gem watir changing Firefox proxy settings without being asked to

For whatever reason, watir changes my Firefox browser settings without my instruction to do this.
If I open Firefox manually (at the office), it normally is set to 'No Proxy' and works just fine.
However, if watir launches a new FF instance, it is set to 'Manual Proxy', and a a browser error states that it's trying to use a proxy server which is refusing connection.
We have no proxy server at work.
How do I get watir to launch a Firefox window with No Proxy? I've searched the web and have not found a single example of this.
(BTW, the FF settings from a watir-launched session are independent of normal FF settings; in other words, manually changing FF settings doesn't correct the problem).
Based on the information here, there are 5 different proxy configurations for Firefox:
0
Direct connection, no proxy. (Default in Windows and Mac previous to 1.9.2.4 /Firefox 3.6.4)
[edit]
1
Manual proxy configuration.
[edit]
2
Proxy auto-configuration (PAC).
[edit]
4
Auto-detect proxy settings.
[edit]
5
Use system proxy settings. (Default in Linux; default for all platforms, starting in 1.9.2.4 /Firefox 3.6.4)
It looks like "0" is the one you need. We set that as described on the Watir-Webdriver help page for Firefox:
profile = Selenium::WebDriver::Firefox::Profile.new
profile["network.proxy.type"] = 0
browser = Watir::Browser.new :firefox, :profile => profile
All of the profile["lorem ipsum"] type options are listed in the about:config menu URL in Firefox, and are accessed/changed in a similar fashion.

Selenium Webdriver and Firefox 18

My Selenium tests use onMouseOver features like
List<WebElement> menuitems = getDriver().findElements(By.tagName("li"));
Actions builder = new Actions(getDriver());
WebElement menu = menuitems.get(2);
getDriver().manage().timeouts().implicitlyWait(Constants.IMPLICITY_WAIT, TimeUnit.SECONDS);
builder.moveToElement(menu).build().perform();
I'm using Firefox driver. Since Firefox updated itself to version 18, my tests stopped working. I know this has to do with native events support - but does not version 18 support native events, or am i able to enable them? If not, is there any replacing implementation to my code?
I'm using selenium java 2.28.0.
For Firefox 18 support we need use selenium webdriver api 2.28.0,jar.
Selenium Java 2.27 mentions that native support for FF17 has been added. However, there has been no mention of support for FF18 in the change logs for 2.28. So its webdriver not supporting native events and not FF18 not supporting native events. You can try downgrading to FF 17 and probably turn off automatic updates for some time.
Rolling back to FF17 is a temporary work around until WebDriver version supports FF18
FF17 Extended Support Release packages -- http://www.mozilla.org/en-US/firefox/organizations/all.html
Note: If you are Mac user, you can simply rename your current FF from 'FireFox' to 'FireFox18' in your applications folder. Install the package from the above URL, which should create a new application called 'FireFox' that will be used by WebDriver.
My hover-over broke with v28. I now use the following hoverOver method with an optional javascript workaround and it seems to work okay.
public void HoverOver(IWebElement elem, bool javascriptWorkaround = true)
{
if (javascriptWorkaround)
{
String code = "var fireOnThis = arguments[0];"
+ "var evObj = document.createEvent('MouseEvents');"
+ "evObj.initEvent( 'mouseover', true, true );"
+ "fireOnThis.dispatchEvent(evObj);";
((IJavaScriptExecutor)driver).ExecuteScript(code, elem);
}
else
{
Actions builder = new Actions(driver);
builder.MoveToElement(elem).Build().Perform();
}
}
I was facing the same issue with Firefox 20. Then I re-installed latest Selenium server (.jar files).
http://selenium.googlecode.com/files/selenium-server-standalone-2.32.0.jar
Hope this works!

Resources