Problem setting default download directory in Watir after update - ruby

We recently updated our Watir version from 6.8 to 6.19 in anticipation of the 7.0 beta. Since then, our browser configuration that sets the default directory for chrome has stopped working. Our method that sets it is below.
def setup
prefs = {
download: {
prompt_for_download: false,
default_directory: #download_dir
}
}
Watir::Browser.new :chrome, options: { prefs: prefs }
end
#download_dir is set as the dir that I want and I have confirmed that by checking the value with a breakpoint after prefs has been defined.
As far as I can tell, this is how http://watir.com/guides/chrome/ specifies that you should set this up. This method worked fine before the update. I've tried some of the solutions from similar issues on SO with no success.
I receive no errors as far as I can tell, and our testing suite runs fine other than downloading to the chrome default folder instead.
Thanks in advance!

As mentioned in the comments, this is due to a bug in selenium detailed here github.com/SeleniumHQ/selenium/issues/7917.
Using strings in the style of "prompt_for_download" => false fixes the problem.

Related

Ruby Selenium/Watir ".select" does not do anything in Safari (any version)

I'm having a painful time trying to select a value in a select field in Safari. It works fine in Chrome, Firefox and IE.
It finds the object fine, but it doesn't select any value. It also doesn't return any error.
I've also tried this on multiple websites with select fields (same issue):
launch browser
browser = Watir::Browser.new :safari, url: "http://localhost:4444/wd/hub"
Set object (works fine)
elTitle = #browser.element(xpath:'//select[#name="ddTitle"]')
Now things i've tried to select the value:
elTitle.option(:text => "Mrs").select
above returns nil, and nothing actually selected
also tried:
elTitle.options[1].click
above returns nil, and nothing actually selected
also tried:
elTitle.send_keys "Mrs", :tab
(which often results in the listbox options displayed (with the correct value with a tick next to it), but it's on top of the browser and prevents any further code from continuing - but this is another issue altogether)
Ruby: 2.2.6
safari v11.0.3 (High Sierra)
watir gem: 6.10.3
selenium-webdriver: 3.9.0
selenium-standalone-server: 3.9.1
Originally had older versions of these gems, which had the same issue, so updated them, and still have the issue. Had also tried with earlier version of Safari (v10/Sierra), which had the same issue.
I've also been unable to launch Safari Technology Preview (but this is an issue i'll raise separately)
So, in summary, has anyone been able to do ".select" on a select field in Safari?
YOu are doing it wrong, you are calling option method for wrong object.
Try this syntax for select_list always
b.select_list(name: "ddTitle").select "Mrs"
Other syntax is
b.select_list(name: "ddTitle").option(text: "Mrs").select
option method has to be called for Watir::Select object not for Watir::HTMLElement, you are actually calling for Watir::HTMLElement, so it's not working.

Web-extension opening url on addon install works fine on Opera and Chrome but fails on Firefox?

The following web-extension code in my background script background.js works fine on Opera and Chrome triggering appropriate webpage on Install, Update and Uninstall but does nothing in firefox. The same is shown as compatible here - https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/onInstalled
Manifest.json has:
"background" : {
"scripts" : ["includes/background.js"]
},
background.js has :
//CHECK INSTALL, UPDATE, UNINSTALL
chrome.runtime.onInstalled.addListener(function (details) {
if (details.reason == "install") {
chrome.tabs.create({
url : "https://www.example.com/install.html"
});
}
if (details.reason == "update") {
chrome.tabs.create({
url : "https://www.example.com/update.html"
});
}
});
chrome.runtime.setUninstallURL("http://www.example.com/uninstall.html");
You have installed your add-on as a temporary add-on through about:debugging. The documentation states:
This event is not triggered for temporarily installed add-ons.
Thus, the event won't fire. You will need to install your add-on as a normal, non-temporary add-on. There are multiple ways for you to do so. The official way is to install Firefox Developer Edition, or Firefox Nightly and set xpinstall.signatures.required to false in about:config. If you want to do so in the release version of Firefox, you can entirely disable add-on signature checking in Firefox. The process to do so is described in the linked answer (also listed below). You may also the information in the Documentation link below helpful in installing your add-on as a normal add-on.
How can I disable signature checking for Firefox add-ons?
Installing add-ons for development (an archive of Stack Overflow Documentation)

Firefox addon SDK, open an url automatically after Firefox startup?

With Firefox addon SDK, how to open specific url automatically after Firefox startup (for the purpose of testing page)
I've tried tabs.open(url) in this doc:
var tabs = require("sdk/tabs");
tabs.open("http://www.example.com");
And this one and a lot of Stackoverflow page ..., but none of them works at all...(It is still just a blank tab after $ cfx run)
I think you want to do this:
const tabs = require('sdk/tabs');
exports.main = function (options, callbacks) {
if (options.loadReason === 'startup') {
tabs.open('https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening_for_load_and_unload');
}
};
The documentation for this is located here:
https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening_for_load_and_unload
#canuckistani is actually right: if you're not seeing it, it's probably because your options.loadReason is something else. If you've got the plugin installed already, for example, you would get loadReason upgrade instead when you try to install the plugin again. See that url #canuckistani gave for more info.

Updating Firefox addon jsm module code without browser restart

I am developing a Firefox addon that is loaded from a directory instead of an xpi, Firefox extension proxy file. The extension is based on jsm modules.
Is there a way to update those modules to reflect the code changes. The only way to do it now is to close and restart the browser but that its not a sane way to develop anything.
Tried to:
Components.utils.unload('resource://myextension/mymodule.jsm');
Components.utils.import('resource://myextension/mymodule.jsm');
but changes are not made.
Got the answer from Victor Porof. In order to make this work you need to clear first the cache:
var obs = Cc["#mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
obs.notifyObservers(null, "startupcache-invalidate", null);
Hope this helps anyone

Ruby Watir - getting NoMethodError: undefined method 'start' on a newly installed PC

I'm new to Ruby so this might be a really dumb question. But we have this code working on an existing Ruby install PC.
def usr_OpenURL(strURL, strBrowserType)
if strBrowserType == "IE"
# Open Browser at the specified URL and Maximise
browser = Watir::Browser.start(strURL)
browser.waitForIE
browser.bring_to_front
browser.maximize
sleep($nSleepTime)
elsif strBrowserType == "Chrome"
browser = Watir::Browser.new :chrome
browser.goto strURL
sleep($nSleepTime)
else
puts "No Known Browser is Declared"
end
return browser
end
However installing the same version of Ruby on my pc and running the code is returning the error:
undefined method 'start' for Watir::Browser:Class (NoMethodError).
So I used irb to play around with it a bit.
If I do:
require "Watir"
browser = Watir::Browser.start("http://www.google.com")
I get the error, but if I do:
require "Watir"
browser = Watir::Browser.new
browser = Watir::Browser.start("http://www.google.com")
then its ok. It opens a new browser window at that url as expected.
Comparing the PCs I can see different versions of the watir, and watir-webdriver gems are installed - so not sure if something changed between versions.
The person who wrote this ruby code is no longer here - so I can't ask them why they're not doing a .new and Goto for IE.
Any ideas would be appreciated :) Thanks!
Update:
I found this in watir-classic 3.2.0 gem. Thinking maybe that is the culprit.
Watir::Browser is now a class instead of a module - beware if you're monkey-patching.
This is a problem in watir 4.0. I've opened up an issue for that https://github.com/watir/watir/issues/5 - hopefully i will fix it soon :)
The error is likely occurring because the new PC is using Watir 4.0.0, where as the previous PC was using a Watir 3.x version. The recently released Watir 4.0.0 has logic for directing usage between the watir-classic gem and the watir-webdriver gem.
I believe that the gem is not determined until you do Browser.new. After that, the gem is loaded and if it is the watir-classic gem you will have the methods such as Browser.start and Browser.attach (as these do not exist in watir-webdriver).
A possible solution, if you are only using IE is to directly require the needed gem. So do:
require 'watir-classic'
instead of
require 'watir'
As far as I know Browser#start is just a shortcut for Browser#new and Browser#goto. I do not know what is causing the error, but it should be perfectly safe to replace
browser = Watir::Browser.start(strURL)
with
browser = Watir::Browser.new :ie
browser.goto strURL

Resources