Capybara Selenium Firefox untrusted issuer screen - ruby

Is there a way to bypass the untrusted issuer screen that appears on Firefox? I'm struggling to follow with geckodriver etc. It's changed a lot since the last time I needed Firefox in Selenium.
My env file has the following:
Capybara.default_driver = :selenium
Capybara.register_driver :selenium do |app|
opts = Selenium::WebDriver::Firefox::Options.new
opts.add_argument('acceptInsecureCerts')
Capybara::Selenium::Driver.new(app, browser: :firefox, options: opts)
end
Capybara.default_driver = :selenium
I'm using Firefox 54
selenium webdriver 3.4.3
geckodriver 0.17
I think I'm using options wrong but I can't find the right solution.

You need to specify accept_insecure_certs in the desired capabilities. The following should do it for you
Capybara.register_driver :selenium do |app|
caps = Selenium::WebDriver::Remote::Capabilities.new(accept_insecure_certs: true)
Capybara::Selenium::Driver.new(
app,
browser: :firefox,
desired_capabilities: caps
)
end

Related

Trying to install extension from Chrome store through Capybara

Trying to install Chrome extension through capybara test, but unable to achieve in Ruby
https://chrome.google.com/webstore/detail/google-keep-chrome-extens/lpcaedmchfhocbbapmcbpinfpgnhiddi
Capybara.register_driver :chrome do |app|
client = Selenium::WebDriver::Remote::Http::Default.new
extension_path = 'https://chrome.google.com/webstore/detail/sticky-notes-just-popped/plpdjbappofmfbgdmhoaabefbobddchk'
profile = Selenium::WebDriver::Chrome::Profile.new()
profile.add_extension(extension_path)
Capybara::Selenium::Driver.new(app, browser: :chrome, http_client: client, profile: profile)
end
Tried with this but still dnt get success.

Chrome binary not found on Heroku with Selenium for Ruby on Rails

Two weeks ago, I managed to have a working environment on Heroku, combining Capybara, Selenium, Chromedriver and Chrome for web scraping. However, one week ago I must have changed something, which causes the setup to crash due to the Chrome binary not being found.
WARN: Selenium::WebDriver::Error::UnknownError: unknown error: cannot find Chrome binary (Driver info: chromedriver=2.40.565383 (76257d1ab79276b2d53ee976b2c3e3b9f335cde7),platform=Linux 4.4.0-1019-aws x86_64)
I am using the two relevant buildpacks on the Heroku-14 Stack
https://github.com/heroku/heroku-buildpack-xvfb-google-chrome
https://github.com/heroku/heroku-buildpack-chromedriver
Used gems:
gem 'selenium-webdriver','>=3.6.0'
gem 'chromedriver-helper'
I've spent the weekend trying to get this to work by passing various paths directly into the capybara.rb initializer (and compared these by running heroku run bash), but could not get it working.
capybara.rb
require "selenium/webdriver"
chrome_bin = ENV.fetch('GOOGLE_CHROME_SHIM', nil)
chrome_opts = chrome_bin ? { "chromeOptions" => { "binary" => 'app/.apt/usr/bin/google-chrome-stable' } } : {}
puts chrome_opts.to_s
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(chrome_opts)
)
end
Capybara.default_driver = :chrome
Capybara.javascript_driver = :chrome
I have also set the ENV vars in Heroku via the interface but when checking with ENV via heroku run rails c, it seems that the BIN var is loaded from the buildpack, and overrides my configuration.
I set GOOGLE_CHROME_BIN and GOOGLE_CHROME_SHIM to: /app/.apt/usr/bin/google-chrome
I'm no sure what kind of changes I have to make to get it working again. There are quite a few puzzle pieces, which one do I need to fix? Suggestions welcome!
SOLVED:
require "selenium/webdriver"
chrome_bin = ENV.fetch('GOOGLE_CHROME_SHIM', nil)
Capybara.register_driver :chrome do |app|
browser_options = ::Selenium::WebDriver::Chrome::Options.new
browser_options.binary = chrome_bin
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end
Capybara.default_driver = :chrome
Capybara.javascript_driver = :chrome
I'm guessing you upgraded to the latest selenium-webdriver and chromedriver in the last few weeks. chromeOptions is no longer a valid key to pass, you can try changing it to goog:chromeOptions but you really should just be using an instance of the Selenium::WebDriver::Chrome::Options class
Capybara.register_driver :chrome do |app|
options = ::Selenium::WebDriver::Chrome::Options.new
options.binary = ...
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end

Configure the spec_helper file to have the default driver open an incognito window in Chrome

I am stuck trying to figure out how to get my default driver to open Chrome with an incognito window.
Capybara.default_driver = :selenium_chrome is what I currently have for my default driver.
How can I add the option that tells the driver to always open an incognito window?
You need to register your own driver which configures Chrome the way you want
Capybara.register_driver :incognito_chrome do |app|
browser_options = ::Selenium::WebDriver::Chrome::Options.new
browser_options.args << '--incognito'
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end
and then set that as your default driver
Capybara.default_driver = :incognito_chrome

Capybara app_host with colon won't work with Firefox

I'm having a very odd issue with some capybara/selenium tests. For context I'm running ruby-rspec with selenium and capybara. My test work just fine when I run them on Chrome, but for some reason with Firefox, the 2nd URL fails.
spec_helper.rb
BROWSER = :chrome
BROWSER = :firefox
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, browser: BROWSER)
end
Capybara.default_driver = :selenium
# This one works
Capybara.app_host = "https://bar.foo.com/home"
# This one doesn't
Capybara.app_host = "https://foo.bar.com:18661/home"
The error I get:
Selenium::WebDriver::Error::WebDriverError:
WebDriverError#chrome://marionette/content/error.js:172:5
InsecureCertificateError#chrome://marionette/content/error.js:291:5
handleReadyState#chrome://marionette/content/listener.js:274:21
handleEvent#chrome://marionette/content/listener.js:247:9

Capybara - visit() not working with firefox

I'm a noob in cucumber and capybara, so please bear with me.
I'm trying to setup a cucumber project that uses chrome and firefox as the test platform. So far, I have got the test to work on chrome, but not on firefox.
Below is the code snippet:
require 'uri'
require 'net/http'
require 'fileutils'
require 'selenium-webdriver'
require File.dirname(__FILE__) + '/throttle.rb'
#CAPYBARA
require 'capybara/cucumber'
require 'capybara/session'
#require 'capybara-webkit'
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Capybara.register_driver :selenium_firefox do |app|
Capybara::Selenium::Driver.new(app, :browser => :firefox)
end
driver = case ENV['BROWSER']
when 'chrome'
:chrome
when 'firefox'
:selenium_firefox
when 'webkit'
:webkit
when 'ie'
:internet_explorer
else
:chrome
end
Capybara.default_driver = driver
Capybara.javascript_driver = :selenium_firefox
Capybara.run_server = false
Capybara.default_selector = :css
Then, for the test, I just simply did a visit("http://www.google.com").
If I set my browser parameter to chrome, it worked fine. Cucumber openned up chrome and automatically typed in "www.google.com", and the page loaded without a problem.
However, the moment I set it to firefox: $cucumber features/test.feature BROWSER=firefox, it didn't work. It did open up the firefox browser, but nothing was being automatically typed into the URL box.
So, I must be missing something in the setup process that I'm not aware of. I have been looking for solutions on the web (require 'selenium webdriver', put 'selenium webdriver' into my Gemfiles, etc.), but so far none has worked for me.
What am I missing here? How come visit() didn't automatically populate the URL box of firefox, but it did just fine with chrome?
Thank you for your help.

Resources