Does anyone know how to test a Rails app with geolocation?
I have tried with this setup, but it crashes.
spec_helper.rb
Capybara.javascript_driver = :selenium2
Capybara.register_driver :selenium2 do |app|
prefs = {
:geolocation => {
:default_content_setting => true,
}
}
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
$ rspec ./spec/acceptance/create_new_account_spec.rb
Failure/Error: visit login_page
Selenium::WebDriver::Error::UnknownError:
unknown error: session deleted because of page crash
from tab crashed
(Session info: chrome=33.0.1750.152)
(Driver info: chromedriver=2.9.248307,platform=Mac OS X 10.9.2 x86_64)
I'm using this versions:
selenium-webdriver (2.40.0)
Chrome 34.0.1847.76
chromedriver 2.9.248307
Related
I am trying to use WSL2 to rails application and had this error when RSpec is running:
Selenium::WebDriver::Error::WebDriverError:
chrome not reachable
(Session info: headless chrome=77.0.3865.75)
Someone know to fix it?
My capybara.rb:
require "capybara/rails"
require "selenium-webdriver"
Capybara.default_max_wait_time = 10
Capybara.register_driver :chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new(
args: %w[headless no-sandbox]
)
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
Capybara.javascript_driver = :chrome
Capybara.server = :puma, { Silent: true }
I put the path in env variables to reach my chromewebdriver binary, following this article "https://ngauthier.com/2017/09/rails-system-tests-with-headless-chrome-on-windows-bash-wsl.html" and nothing!
I just fix it with the following code
Capybara.register_driver :chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new(args: %w[
headless no-sandbox disable-gpu window-size=1920x1080
])
Capybara::Selenium::Driver.new(app,
browser: :chrome,
desired_capabilities: {
"chromeOptions" => {
w3c: false
}
}
)
end
Please let me know if this is resolve your issue
I'm getting the error above when trying to run Selenium on Heroku, RoR app.
I've added the buildpacks heroku-buildpack-google-chrome and heroku-buildpack-chromedriver
Then added the config variables
GOOGLE_CHROME_SHIM=/app/.apt/opt/google/chrome/chrome
GOOGLE_CHROME_BIN=/app/.apt/opt/google/chrome/chrome
And added this code on the capybara setup:
chrome_bin = ENV.fetch('GOOGLE_CHROME_SHIM', nil)
chrome_opts = chrome_bin ? { "chromeOptions" => { "binary" => chrome_bin } } : {}
Capybara.register_driver :chrome do |app| Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(chrome_opts), ) end
Capybara.javascript_driver = :chrome
As described on the chrome link: https://github.com/heroku/heroku-buildpack-google-chrome
Do I need to set up another variable for the location of the webdriver? If yes, how? and how do I assign it?
Thanks
Was able to get this working on heroku rails app by using the following:
1) added the buildpacks heroku-buildpack-google-chrome and heroku-buildpack-chromedriver
2) set the driver in rails
options = Selenium::WebDriver::Chrome::Options.new
if Rails.env.production?
Selenium::WebDriver::Chrome.path = ENV["GOOGLE_CHROME_SHIM"]
end
options.add_argument("--headless")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")
#driver = Selenium::WebDriver.for :chrome, options: options
No need to set any ENV variables on heroku as GOOGLE_CHROME_SHIM is set automatically by the webdriver build package.
I'm new to mobile testing and I wanted to try Appium with Capybara. I've already configured Appium to run and open Safari but just after opening it goes to 0.0.0.0 page, closes and throws an error:
An unknown server-side error occurred while processing the command.
Original error: Could not navigate to webview! Err: connect
ECONNREFUSED ::1:27753
I'm using:
Appium: 1.7.2
Xcode: 9.3
That's my spec_helper.rb:
require 'bundler'
Bundler.require
require 'capybara/dsl'
require 'appium_capybara'
Capybara.run_server = false
desired_caps_ios = {
deviceName: "iPhone Simulator",
browserName: 'Safari',
platformName: "iOS",
platformVersion: "11.3",
automationName: 'XCUITest'
}
url = "http://localhost:4723/wd/hub"
Capybara.register_driver(:appium) do |app|
appium_lib_options = {
server_url: url
}
all_options = {
appium_lib: appium_lib_options,
caps: desired_caps_ios
}
Appium::Capybara::Driver.new app, all_options
end
Capybara.default_driver = :appium
RSpec.configure do |config|
config.include Capybara::DSL
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.shared_context_metadata_behavior = :apply_to_host_groups
end
And my test is just:
it 'test' do
visit 'https://google.com'
end
Can anyone help me with this?
I've just figure it out! Just the newest version of iOS(11.3) is not yet supported by Appium. I had to download SDKs for iOS 11.2.
what are the advantages/pros/cons of using
Capybara.current_driver = :chrome
versus using
Capybara.current_driver = :selenium_chrome
To give a bit more context, I'm using capybara in a standalone ruby script.
They are just names that can be used to identify specific driver configurations so it all depends on what is registered as :chrome and :selenium_chrome. The latest Capybara (2.15.1) release provides a default registration for :selenium_chrome which is defined as
# Configure selenium-webdriver to use chrome as the browser
Capybara.register_driver :selenium_chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
but that can be redefined in your code. There is no gem, that I know of, that provides a default registration of :chrome so if that's currently valid it would most likely be defined in your code (search for register_driver).
I'm trying to use headless mode of chrome with capybara/selenium in rspec Ruby on Rails and getting a error when try to click on confirm dialog
Capybara.register_driver(:headless_chrome) do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w[headless disable-gpu test-type window-size=1920x1080] }
)
driver = Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: capabilities
)
driver
end
Capybara.server = :puma
Capybara.javascript_driver = :headless_chrome
scenario 'delete movie' do
login_as user
visit edit_public_movie_path(movie)
expect(page).to have_selector('span[ng-click="ctrl.deleteMovie()"]')
find('span[ng-click="ctrl.deleteMovie()"]').click
page.driver.browser.switch_to.alert.accept
wait_for_ajax(wait_after: 1)
expect(page).to have_content('Click here to upload movie (Max: 500 MB)')
end
And got this error
Event movie success delete movie
Failure/Error: page.driver.browser.switch_to.alert.accept
Selenium::WebDriver::Error::NoSuchAlertError:
no alert open
(Session info: headless chrome=59.0.3071.115)
(Driver info: chromedriver=2.29.461585 (0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b),platform=Mac OS X 10.12.5 x86_64)
With common mode it works without errors. Seems the selenium don't support headless mode or need to other approach to do it. Any ideas?
Update(resolved)
So, I spent a lot of time and find working environments.
You need to last build of chromium because preview versions have a bug. You can get it by these scripts linux or Mac
Here is my capybara config
Capybara.register_driver(:headless_chrome) do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: {
args: %w[headless disable-gpu disable-popup-blocking no-sandbox window-size=1920x1920],
binary: "#{Dir.home}/chromium-latest-#{platrofm}/latest/#{chrome_file}"
})
driver = Capybara::Selenium::Driver.new(app,
browser: :chrome,
desired_capabilities: capabilities)
driver
end
Capybara.server = :puma
Capybara.javascript_driver = :headless_chrome
Capybara.default_max_wait_time = 20
Capybara.server_port = 55305
def platform
if /linux/ =~ RUBY_PLATFORM
"linux"
else
"macosx"
end
end
def platform_linux?
platform == "linux"
end
def chrome_file
if platform_linux?
"chrome"
else
"Chromium.app/Contents/MacOS/Chromium"
end
end
And you should use page.driver.browser.switch_to.alert.accept instead of page.accept_alert
Had the same problem. Please use the disable-popup-blocking in chromeOptions.