Apparition hangs after "DevTools listening on" - capybara

macos 10.13.6
jruby 9.2.0.0
rspec 3.8.2
capybara 3.28.0
apparition 0.3.0
chrome 76.0.3809.100
Current configuration (tried various options that had no effect:
require 'capybara/apparition'
Capybara.register_driver :apparition do |app|
Capybara::Apparition::Driver.new(app, { headless: true })
end
Capybara.configure do |config|
config.default_max_wait_time = 10
config.ignore_hidden_elements = true
config.default_driver = :apparition
config.javascript_driver = :apparition
end
I'm getting something like this when I attempt to run using apparition:
Capybara starting Puma...
* Version 4.1.0 , codename: Fourth and One
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:50136
DevTools listening on ws://127.0.0.1:50140/devtools/browser/003bf437-48ff-45f9-ac9e-fa0526d904dc
After which it sits there until I force quit out. If headless mode is off, it pops open a browser window, which I can use to visit the Puma listening port but otherwise doesn't actually do anything.
Am I doing something wrong here?
Disclaimer: The reason I tried this in the first place was that chrome/chromedriver updated and borked my selenium chromedriver setup.

UPDATE: This should be fixed in Apparition 0.4.0
——————————————-
Apparition currently isn't working with JRuby - you'll have to swap to MRI to test using Capybara with Apparition.

Related

Webdrivers::NetworkError - Mac64 M1 - ChromeDriver

My Capybara Selenium Webdriver set up is failing when trying to make a connection to ChromeDriver - It appears they released a version without an M1 version to find at the Chromedriver API https://chromedriver.storage.googleapis.com/index.html?path=106.0.5249.61/
Error:
Webdrivers::NetworkError:
Net::HTTPServerException: 404 "Not Found" with https://chromedriver.storage.googleapis.com/106.0.5249.61/chromedriver_mac64_m1.zip
CODE:
Capybara.register_driver :headless_chrome do |app|
options.add_argument("--disable-gpu")
options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument("--window-size=1920,1080")
driver = Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
### Allow file downloads in Google Chrome when headless
### https://bugs.chromium.org/p/chromium/issues/detail?id=696481#c89
bridge = driver.browser.send(:bridge)
path = "/session/:session_id/chromium/send_command"
path[":session_id"] = bridge.session_id
bridge.http.call(:post, path, cmd: "Page.setDownloadBehavior",
params: {
behavior: "allow",
downloadPath: "/tmp/downloads",
})
###
driver
end
When the application calls driver.browser I get the error above and that is because the file it's looking for does not exist.
Can I set a specific version of chrome driver or what system to look for when initializing the driver?
Fix is posted here: https://github.com/titusfortner/webdrivers/pull/239 - This is a known issue in "webdrivers"

Selenium WebDriver Chrome timeout and invalid URL

I am using Selenium Webdriver Chrome initialized in my Rails app as follows
host=XXX
port=XXX
Capybara.register_driver :selenium_chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument("--proxy-server=#{host}:#{port}")
options.add_argument("--headless") # Remove this option to run on Chrome browser
Capybara::Selenium::Driver.new( app,
browser: :chrome,
options: options
)
end
However, it is timing out always when I run a spec giving this error
Net::ReadTimeout upon running the command visit url
URI.parse(current_url) returns #<URI::Generic data:,> which looks incorrect and probably the reason why it is timing out. I looked into the Selenium Webdriver gem and added debugging to see how the request is fetched for this command but for some reason it is not stopping at the pry when the command is get_current_url
Why does current_url look incorrect and why would it not stop for the command get_current_url ?
EDIT: the url is obtained from here and returns the following locally
[6] pry(Selenium::WebDriver::Remote::Bridge)> Remote::OSS::Bridge.new(capabilities, bridge.session_id, **opts).url
=> "data:,"
Adding a pry to the URL method doesn't stop, so wondering how it is obtaining the value.
Ruby: ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a) [x86_64-darwin20]
Selenium-Webdriver: 3.142.7

Rails 6 doesn't output the result of system tests (with rails test:system)

My Rails application doesn't output the result of the system tests (no failures, no assertions, nothing). The funny thing is that I can see chrome doing what it was expected to do (filling fields, etc...), but when the test is finished, no output on the shell, just the following:
francesco.mari#MB68D:DemographicsMapper (inline_mapping_editing *) $ bin/rails test:system
Puma starting in single mode...
* Version 4.3.8 (ruby 2.6.6-p146), codename: Mysterious Traveller
* Min threads: 0, max threads: 4
* Environment: test
* Listening on tcp://127.0.0.1:49330
Use Ctrl-C to stop
francesco.mari#MB68D:DemographicsMapper (inline_mapping_editing *)
Apparently the issue was on the file test_helper.rb. After I added the line parallelize(workers: :number_of_processors) it worked as it should.
class ActiveSupport::TestCase
#...
parallelize(workers: :number_of_processors) # added this line
#...
end

Capybara, Rails, Selenium, Chromedriver + ERR:CONNECTION_REFUSED

I'm setting up Capybara with Selenium Webdriver in my Rails application, and I keep running into the following error:
Helpdesk Ticketing System assigning a ticket should mark ticket as assigned
Failure/Error: visit tickets_path
Selenium::WebDriver::Error::UnknownError:
unknown error: net::ERR_CONNECTION_REFUSED
(Session info: chrome=85.0.4183.102)
My settings are as follows:
Capybara.server = :puma
Capybara.app_host = 'http://intranet.lvh.me'
Capybara.default_driver = :selenium_chrome_headless
In the logs it shows this before the failure, choosing a different port each time it runs:
Capybara starting Puma...
* Version 4.3.6 , codename: Mysterious Traveller
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:56277
Anyone help?
I solved my problem. I was missing:
Capybara.always_include_port = true
I had set route-level URL defaults inside of config/environments/test.rb and that option pulls through to all parts of the application.
When I removed the line shown below, all my tests passed again.
# config/environments/test.rb
Rails.application.routes.default_url_options = {
host: "server.localhost",
port: 3000
}

"No such session" / "chrome not reachable" error when running Chrome in parallel in Jenkins

I am getting the issue with running automation tests on Chrome in Jenkins using parallel_test gem (also use with Capybara, selenium - Ruby language). I'm running it in headless mode with Xvfb. However, most of all test scenarios failed due to 'no such session' or 'chrome not reachable' errors.
This is my run command on test job in Jenkins:
xvfb-run -a --server-args='-screen 0 1680x1050x24' bundle exec parallel_cucumber features/ -n 4 -o '-t ~#ignore -p jenkins_chrome'
This is my register_driver in env.rb:
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app,
browser: :chrome,
desired_capabilities: {
"chromeOptions" => {
"args" => %w{ --start-maximized --disable-impl-side-painting --no-sandbox }
}
})
end
And this is error message:
(Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Linux 4.0.5 x86_64) (Selenium::WebDriver::Error::NoSuchDriverError)
./features/step_definitions/view_a_profile.rb:204:in `/^user has signed in as "([^"]*)"$/'
Someone said the errors are due to xvfb, some said due to Chrome can't run in parallel.
Have anyone experienced this issue? How can I solve this problem?
Chrome with chromedriver and xvfb won't run on any
suse. (probably not related here)
Usually on build servers everything gets executed as root, which
causes this exact error for me with chrome. (for this I am searching for a workaround myself)

Resources