Watir: ignore invalid Browser certificates - ruby

I'm trying to tell Google Chrome to ignore invalid Browser certificates with the command line switch from official documentation [1]:
Watir::Browser.new :chrome, switches: ['--ignore-certificate-errors']
But I get the error:
ArgumentError: {:switches=>["--ignore-certificate-errors"]} are
unrecognized arguments for Browser constructor from
/var/lib/gems/3.0.0/gems/watir-7.1.0/lib/watir/capabilities.rb:79:in
`process_browser_options'
3.0.2 (dev)[1] ยป
How can I get rid of the error and tell Chrome to ignore the certificate?
[1] http://watir.com/guides/certificates/

Switches get passed on the args parameter:
Watir::Browser.new(:chrome, options: {
args: ['--ignore-certificate-errors']
})

Related

I get an error when using selenium chromedriver to create a session where I am logged into my account

The code I'm using start the session doesn't seem to be working, but I don't know what is wrong with it.
I can create a session without logging in and do what I want but when I try to the use the recommended method of creating the driver with an Options object and adding a user-data-dir, I run into errors.
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('user-data-dir=C:\Users\user\AppData\Local\Google\Chrome\User Data')
driver = Selenium::WebDriver.for(:chrome, options: options)
driver.get("https://login.tripleseat.com/")
email_field = driver["login"]
email_field.send_keys("clshaps93#gmail.com")
email_field.submit
I want my program to get to the bottom section signed into my account without running into an error.
If I don't have a Chrome window already open, I end up with this error:
1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/response.rb:32:in initialize'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/response.rb:69:inassert_ok': unknown error: cannot determine loading status (Selenium::WebDriver::Error::UnknownError)
from no such execution context
If I do have Chrome window already open, I end up with this error:
1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/response.rb:32:in initialize'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/response.rb:69:inassert_ok': unknown error: Chrome failed to start: crashed (Selenium::WebDriver::Error::UnknownError)
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Other values I have tried to use for user-data-dir just end up being ignored, in that a session starts without logging me in. Is there some code I need to add somewhere to avoid these errors?

Ruby / Capybara - How to use a JQuery command in Capybara

I have the following JQuery script that are working in my Chrome console. However, it is not working when I use it in my Capybara test. What am I doing wrong?
Script that works in my console
$('#skuTabNavigation a[href="#tabImages"]').trigger('click');
Script in my Capybara test. Did not work
script = '$("#skuTabNavigation a[href="#tabImages"]").trigger("click")';
page.execute_script(script)
Terminal MAC error
Failure/Error: page.execute_script(script)
Selenium::WebDriver::Error::UnknownError:
unknown error: Runtime.evaluate threw exception: SyntaxError: missing ) after argument list
(Session info: headless chrome=73.0.3683.75)
(Driver info: chromedriver=2.46.628411 (3324f4c8be9ff2f70a05a30ebc72ffb013e1a71e),platform=Mac OS X 10.12.6 x86_64)
It looks like you need to escape your quotes; you've got 2 sets of double quotes nested inside your capybara script example.
You might try escaping the quotes around tabImages:
script = "$('#skuTabNavigation a[href=\"#tabImages\"]').trigger('click')";

geckodriver not launching firefox

I am using firefox v 48.0.2 and am trying to get my selenium (selenium-server v2.53) remotedriver automated tests to run on firefox, I have geckodriver 0.9.0 installed and when i go through the documentation on the github readme and run this command: (on mac osx 10.11.3)
geckodriver -b /Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin
i get this error message:
thread '< main >' panicked at 'called Result::unwrap() on an Err value: Io(Error { repr: Os { code: 48, message: "Address already in use" } })', ../src/libcore/result.rs:746
note: Run with RUST_BACKTRACE=1 for a backtrace.
ive tried ignoring this step but when i run my tests firefox does not launch, i have ensured that my webdriver capabilities include marrionette: true
WebDriver:
browser: 'firefox'
clear_cookies: false
restart: false
window_size: 414x736
marionette: true
other than that i can not find any documentation to lead me in the correct direction, did i perhaps over look something? any help is greatly appreciated!
I am also using codeception to handle my tests (php)
EDIT
I was able to get this command to work after killing the process that was listening on port 4444:
geckodriver -b /Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin
But even with that running Firefox is still not launching

Open browser with URL in Ruby

I've been using the following to launch the default browser in OS X:
system('open', url)
This has been working fine until upgrading to Yosemite. Now, I frequently get this message when trying to open various URLS:
LSOpenURLsWithRole() failed with error -1712 for the URL http://blah.com
But sometimes that URL will work. I can try it once, and it'll work, another it might not. Very unpredictable.
I've tried all of these:
system("open #{url}")
`open #{url}`
Launchy.open(url, debug: true)
Launchy.open( "#{ url }" ) do |exception|
puts "Attempted to open #{url} and failed because #{exception}"
end
But they all exhibit this same behavior. There are several URLs being opened at once, like this:
urls.each do |url|
system("open #{url}")
end
How can I consistently open a specific URL in my browser on OS X using ruby?
It looks like you are pushing the Browser with too many urls at the same time.
Using sleep seems to work fine.
15.times {|i| `open http://google.com?q=#{i}` }
# LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=5.
# LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=6.
# LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=12.
# LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=14.
# => 15
15.times {|i| sleep(0.2); `open http://google.com?q=#{i}` }
# => 15

Getting pop-up error "Netscape.cfg/AutoConfig failed" when trying to drive firefox via selenium Grid using Watir-Webdriver

Get Error:
Netscape.cfg/AutoConfig failed. Please contact your system administrator.
Error: defaultPref failed: [Exception... "Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIPrefBranch.setBoolPref]" nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)" location: "JS frame :: prefcalls.js :: defaultPref :: line 58" data: no]
Netscape.cfg/AutoConfig failed. Error: defaultPref failed: [Exception... "Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED)
I have the following setup:
Selenium Grid on CentOs 6.4
Slave Node = CentOs 6.4
Trying to run Firefox remotely via Watir-WebDriver
require "rubygems"
require "test/unit"
#require "selenium"
require "watir-webdriver"
caps = Selenium::WebDriver::Remote::Capabilities.firefox
#caps.version = "24"
caps[:name] = "Firefox 24 , port 5555"
default_profile = Selenium::WebDriver::Firefox::Profile.from_name "default"
default_profile.native_events = true
driver = Selenium::WebDriver.for(:firefox, :profile => default_profile)
#browser = Watir::Browser.new(
:remote,
:url => "http://vm-auto.his.vm:4444/wd/hub",
:desired_capabilities => caps)
#browser.goto "google.com"
#browser.text_field(:name => "q").set "3M"
#browser.button.click
#browser.div(:id => "resultStats").wait_until_present
#browser.screenshot.save ("GoogleSearch_FF24.png")
#browser.close
Firefox version is Mozilla Firefox 24.7.0
there is a reference to this error in https://bugzilla.mozilla.org/show_bug.cgi?id=717438
the resolution being suggested as:
In my case commenting out this pref in mozilla.cfg stops generating this message.
But I do not know origin of this pref.
//stops the request to send performance data from displaying
//pref("toolkit.telemetry.prompted", true);
But, i could not find mozilla.cfg on the filesystem where firefox is installed
That error definitely seems to be related to a problem in the mozilla config file BUT in my case the file was not mozilla.cfg but mozilla-lock.cfg (located at C:\Program Files (x86)\Mozilla Firefox\).
The filename is dictated by the lockset.js file at C:\Program Files (x86)\Mozilla Firefox\defaults\pref\. The line is pref("general.config.filename", "mozilla-lock.cfg")
My issue with the config file was the following lines:
lockpref("security.tls.version.min", "1");
lockpref("security.tls.version.max", "3");
The values should be without quotes:
lockpref("security.tls.version.min", 1);
lockpref("security.tls.version.max", 3);
As addendum, it's entirely possible you don't have a config file at all and the problem exists with a manual configuration in the about:config. Open up the about:config page, and sort by 'status' to look for 'locked', 'user set' or any other non 'default' items.
I had the same issue with Firefox 24 ESR. Mozilla.cfg was in the same directory as the Firefox executable.
In my case this was under "%localappdata%\Microsoft\AppV\Client\Integration[Unique-Code]\Root".
I commented out 'pref("toolkit.telemetry.prompted", true);' and the error message didn't appear anymore.

Resources