Setting browser settings in Watir - ruby

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

Related

How to check if selenium is working on browser on Ruby

I am wondering if I can write the script that is working on the browser and I can see it.
Now, I am working on the project using selenium on Ruby, and they totally work on the headless mode but I want to change it to normal mode( which I can see that is working on the browser)
I have tried a lot but I don't know how to do it.
here is what I have tried.
options = Selenium::WebDriver::Chrome::Options.new
driver = Selenium::WebDriver.for(:chrome, options: options)
driver.get("https://www.google.co.jp/")
and it returns the error like this.
Selenium::WebDriver::Error::UnknownError (unknown error: Chrome failed to start: exited abnormally.)
(unknown error: DevToolsActivePort file doesn't exist) (The
process started from chrome location /usr/bin/google-chrome is no
longer running, so ChromeDriver is assuming that Chrome has crashed.)
and this is the one that work fine but can't open a browser
options = Selenium::WebDriver::Chrome::Options.new
driver = Selenium::WebDriver.for(:remote, url: 'http://chrome:4444/wd/hub', desired_capabilities: :chrome, options: options,)
Probably this is so basic thing on selenium so I feel sorry but any advice will be welcome.

How to configure Safari webdriver to use .pac file

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}

Automate javascript splash downloads in Ruby Watir

In case of a download initiated by Javascript (usually by some Javascript code that submits a form, which may be dynamically added to the page), none of the standard method for forcing a file download in Watir worked for me: I still get the browser file-download confirmation pop-up, which cannot be scripted in Watir. Worse, it looks like even conventional methods that worked when following a convential link to download a file, are now broken in newest browsers, please see this other question:
How to download a file using Watir 6.0
Any suggestion on how to do it?
The documentation for that is here now: http://watir.com/guides/downloads/
prefs = {
download: {
prompt_for_download: false,
default_directory: '/path/to/dir'
}
}
b = Watir::Browser.new :chrome, options: {prefs: prefs}
Best practice, though, is not to use Watir or Selenium to handle downloads. Ideally the creation of and access to the file is handled in a unit or integration test. Watir interacts with browsers, whereas downloads are partially an operating system function. This is to say that it may not be possible to do exactly what you need.
If was having a similar problem and I enable the logger.level it helped me to determine if the prefs were even being set for the "chromeOptions"
Selenium::WebDriver.logger.level = :info
prefs = {
download: {
prompt_for_download: false,
default_directory: "#{FigNewton.download_files}"
}
}
args = ['--ignore-certificate-errors', '--disable-popup-blocking', '--disable-translate', '--disable-infobars']
browser = Watir::Browser.new :chrome, options: {prefs: prefs, args: args }
I'm not saying this will resolve your issue, however just wanted to provide you the information about the logger.level. I find it helpful.

how to set download preferences in watir webdriver for internet explorer....what is the code need to be done

I am using ruby with watir-webdriver.
when downloading a file with chrome,code is there for setting preferences.
What is the procedure for doing the same with internet explorer
i had tried same preference setting that worked for chrome. But it failed in IE.
require 'watir-webdriver'
Watir.default_timeout = 90
prefs = {
:download => {
:prompt_for_download => false,
:default_directory => "#{custom_download_path}"
}
}
$browser = Watir::Browser.new :chrome, :prefs => prefs
IE version :10+
Platform : windows 7..
You should ask yourself what you are really testing here. Beyond 'is the file available and served correctly to a download request', doing file downloads using different browsers starts to be more of a test of the browser itself than your website/server code. This is the sort of test I'd do on a single browser to verify the download link points to the right file, and call it good. For other browsers maybe just verify that the user can see the download link, and that the URL for the download is correct. Or if you really need to examine the file itself, then get the link address, and just download the file with curl or something similar.

How to modify the Firefox profile used by Watir-Webdriver

I'm working on web-application automation using Ruby 1.9.3p484 and Watir-webdriver (0.8.0) with Firefox 41.0 for Ubuntu.
I want the browser to not load any images. To do that, I try to change the 'permissions.default.image' firefox parameter to 2.
I have tried the following code:
profile = Selenium::WebDriver::Firefox::Profile.new
profile['permissions.default.image'] = 2
browser = Watir::Browser.new(:firefox, :profile => profile)
browser.goto url
But, the browser keep loading the images. In the about:config page, the 'permissions.default.image' is still set to 1.
Any ideas on what could be wrong?
I don't know why, but if I use from_name method in Selenium class init, then you code is working perfectly:
profile = Selenium::WebDriver::Firefox::Profile.from_name "default"

Resources