Docker + Rspec + Capybara - arguments[0] is undefined - selenium

I'm trying to get my specs working headlessly in docker - They run fine locally on my mac but when I run them inside the docker container I get this error (repeated multiple times)
Selenium::WebDriver::Error::JavascriptError:
arguments[0] is undefined
# [remote server] https://foobar.com/ line 68 > Function:1:1:in `anonymous'
# [remote server] https://foobar.com/:68:20:in `handleEvaluateEvent'
# ./spec/features/foo_spec.rb:15:in `block (2 levels) in <top (required)>
Xvfb is running: Xvfb :99.0 -screen 0 1366x768x16
I've also tried doing a xvfb-run rspec and got the same errors.
spec_helper.rb:
Capybara.default_driver = :selenium
Capybara.javascript_driver = :selenium
What's going on that this can't run inside docker?

The reason for this error is this:
>> webdriver.execute_script("return typeof arguments[0]", "foo")
=> "undefined"
Apparently this is a bug with Firefox 35 and webdriver. There is an issue open for it - https://code.google.com/p/selenium/issues/detail?id=8390.

Related

I want to test with Selenium, but I get an error Webdrivers :: BrowserNotFound

I currently write tests using Rails5, Rspec, Selenium, and webdrivers gems.
However, I get the error Webdrivers :: BrowserNotFound and I can't run it.
I think this is due to Selenium not finding a ChromeDriver.
However, this problem should have been solved by a webdrivers gem, but it doesn't seem to work as expected.
Details will be written below.
Error Log
1.1) Failure/Error: visit hoges_index_path
Webdrivers::BrowserNotFound:
Failed to find Chrome binary.
# /usr/local/bundle/gems/webdrivers-4.1.2/lib/webdrivers/chrome_finder.rb:21:in `location'
# /usr/local/bundle/gems/webdrivers-4.1.2/lib/webdrivers/chrome_finder.rb:10:in `version'
# /usr/local/bundle/gems/webdrivers-4.1.2/lib/webdrivers/chromedriver.rb:46:in `browser_version'
# /usr/local/bundle/gems/webdrivers-4.1.2/lib/webdrivers/chromedriver.rb:106:in `release_version'
# /usr/local/bundle/gems/webdrivers-4.1.2/lib/webdrivers/chromedriver.rb:32:in `latest_version'
# /usr/local/bundle/gems/webdrivers-4.1.2/lib/webdrivers/common.rb:136:in `correct_binary?'
# /usr/local/bundle/gems/webdrivers-4.1.2/lib/webdrivers/common.rb:92:in `update'
# /usr/local/bundle/gems/webdrivers-4.1.2/lib/webdrivers/chromedriver.rb:119:in `block in <top (required)>'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/service.rb:133:in `binary_path'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/service.rb:94:in `initialize'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/service.rb:41:in `new'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/service.rb:41:in `chrome'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/driver.rb:299:in `service_url'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/chrome/driver.rb:40:in `initialize'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/driver.rb:46:in `new'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/driver.rb:46:in `for'
# /usr/local/bundle/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver.rb:88:in `for'
# /usr/local/bundle/gems/capybara-3.28.0/lib/capybara/selenium/driver.rb:49:in `browser'
# /usr/local/bundle/gems/capybara-3.28.0/lib/capybara/selenium/driver.rb:68:in `visit'
# /usr/local/bundle/gems/capybara-3.28.0/lib/capybara/session.rb:276:in `visit'
# /usr/local/bundle/gems/capybara-3.28.0/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
# ./spec/views/hoge/index_spec.rb:28:in `block (2 levels) in <top (required)>'
TestCode
RSpec.feature 'HogeIndex', type: :system do
before(:each) do
visit hoges_index_path
end
scenario 'hoge' do
expect(all('.hoge').count).to eq 1
end
end
rails_helper.rb
RSpec.configure do |config|
~~~
Capybara.register_driver :selenium_chrome_headless do |app|
browser_options = ::Selenium::WebDriver::Chrome::Options.new
browser_options.args << '--headless'
browser_options.args << '--no-sandbox'
browser_options.args << '--disable-gpu'
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end
config.before(:each) do |example|
if example.metadata[:type] == :system
driven_by :selenium_chrome_headless, screen_size: [700, 700]
end
end
~~~~
end
I also turned on Webdrivers Debug logging.
Here is the log at that time.
2019-10-19 02:12:03 DEBUG Webdrivers Checking current version
2019-10-19 02:12:03 DEBUG Webdrivers /root/.webdrivers/chromedriver is not already downloaded
2019-10-19 02:12:04 DEBUG Webdrivers Checking current version
2019-10-19 02:12:04 DEBUG Webdrivers /root/.webdrivers/chromedriver is not already downloaded
F2019-10-19 02:12:10 DEBUG Webdrivers Checking current version
2019-10-19 02:12:10 DEBUG Webdrivers /root/.webdrivers/chromedriver is not already downloaded
2019-10-19 02:12:11 DEBUG Webdrivers Checking current version
2019-10-19 02:12:11 DEBUG Webdrivers /root/.webdrivers/chromedriver is not already downloaded
F2019-10-19 02:12:17 DEBUG Webdrivers Checking current version
2019-10-19 02:12:17 DEBUG Webdrivers /root/.webdrivers/chromedriver is not already downloaded
2019-10-19 02:12:18 DEBUG Webdrivers Checking current version
2019-10-19 02:12:18 DEBUG Webdrivers /root/.webdrivers/chromedriver is not already downloaded
F2019-10-19 02:12:25 DEBUG Webdrivers Checking current version
2019-10-19 02:12:25 DEBUG Webdrivers /root/.webdrivers/chromedriver is not already downloaded
2019-10-19 02:12:26 DEBUG Webdrivers Checking current version
2019-10-19 02:12:26 DEBUG Webdrivers /root/.webdrivers/chromedriver is not already downloaded
F
I will wait for your reply.
It is solved.
It was because Google Chrome was not installed.
I'm sorry.

Selenium::WebDriver::Error::UnknownError: newSession

I am running my rspec test with selenium webdriver. The setup looks the following way:
require 'capybara/dsl'
Capybara.app = Rack::File.new File.expand_path('../fixtures', __FILE__)
require 'selenium-webdriver'
Capybara.register_driver :firefox do |app|
options = ::Selenium::WebDriver::Firefox::Options.new
options.args << '--headless' if travis?
Capybara::Selenium::Driver.new(app, browser: :firefox, options: options)
end
Capybara.default_driver = :firefox
When I run rspec the tests fail with
Failure/Error: visit '/select2-v3/index.html'
Selenium::WebDriver::Error::UnknownError:
newSession
# WebDriverError#chrome://marionette/content/error.js:178:5
# UnknownCommandError#chrome://marionette/content/error.js:472:5
# despatch#chrome://marionette/content/server.js:290:13
# execute#chrome://marionette/content/server.js:271:11
# onPacket/<#chrome://marionette/content/server.js:246:15
# onPacket#chrome://marionette/content/server.js:245:8
# _onJSONObjectReady/<#chrome://marionette/content/transport.js:490:9
# ./spec/select2_spec.rb:6:in `block (2 levels) in <top (required)>'
Googling around didn't give me any results.
Do you have any ideas how to fix it?
Update: I am using firefox v63.0
You need to upgrade to the latest version of geckodriver (v0.23.0) to work with Firefox 63.
I did
brew install geckodriver then tried brew link geckodriver then an error message says the target file directory already exist. So I removed the target file directory using
rm '/usr/local/bin/geckodriver' before linking again using brew link geckodriver

Running into issues installing gitlab-shell

I am trying to install Gitlab CE from source and following this installation guide.
When I attempt to install the gitlab-shell using the command provided.
sudo -u git -H bundle exec rake gitlab:shell:install REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production SKIP_STORAGE_VALIDATION=true
I received the following stack trace error.
WARNING: This version of GitLab depends on gitlab-shell 4.1.1, but you're running Unknown. Please update gitlab-shell.
rake aborted!
Gitlab::TaskFailedError: Gitlab::TaskFailedError
/home/git/gitlab/lib/tasks/gitlab/task_helpers.rb:87:in `run_command!'
/home/git/gitlab/lib/tasks/gitlab/task_helpers.rb:164:in `clone_repo'
/home/git/gitlab/lib/tasks/gitlab/task_helpers.rb:157:in `checkout_or_clone_tag'
/home/git/gitlab/lib/tasks/gitlab/shell.rake:16:in `block (3 levels) in <top (required)>'
/usr/local/bin/bundle:22:in `load'
/usr/local/bin/bundle:22:in `<main>'
Tasks: TOP => gitlab:shell:install
What config file should I be modifying to fix my issue? Do I need to modify the Redis URL even though I am using the default configuration? By the way, this install is on an Ubuntu 16.04 server.
This might be caused by using a version of git that is too old.
To debug: append the --trace option to bundle exec to get more info on where this error is coming from and inspect the source.

Selenium WebDriver can't find Firefox when installed with Homebrew cask

Homebrew cask does some app linking magic on Mac OS X. Apparently it's not good enough because Selenium WebDriver looking for the Firefox executable can't find it. The following is an error message from an RSpec test run with Capybara driving Selenium.
What is a good way to hint the location of the Firefox executable?
Failure/Error: Unable to find matching line from backtrace
Selenium::WebDriver::Error::WebDriverError:
Could not find Firefox binary (os=macosx). Make sure Firefox is installed or set the path manually with Selenium::WebDriver::Firefox::Binary.path=
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/binary.rb:127:in `path'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/binary.rb:60:in `execute'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/binary.rb:34:in `start_with'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/launcher.rb:70:in `start_silent_and_wait'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/launcher.rb:35:in `block in launch'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/socket_lock.rb:20:in `locked'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/launcher.rb:32:in `launch'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/firefox/bridge.rb:24:in `initialize'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/common/driver.rb:31:in `new'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/common/driver.rb:31:in `for'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver.rb:67:in `for'
# /Users/mende/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/capybara-2.4.4/lib/capybara/selenium/driver.rb:13:in `browser'
As the error msg says: You have to specify Selenium::WebDriver::Firefox::Binary.path for custom app paths.
# in spec_helper.rb
require 'selenium/webdriver'
Selenium::WebDriver::Firefox::Binary.path =
"/opt/homebrew-cask/Caskroom/Firefox/latest/Firefox.app/Contents/MacOS/firefox"
If you don't want to touch the test framework, you can install firefox to /Applications (default path selenium searches for) to make it work without setting the Binary.path.
brew cask install --appdir="/Applications" firefox
I just added the code for Selenium to look for this directory specifically without needing to set it or change appdir. It will be available in the selenium-webdriver gem 2.49+

Mechanize getting "Errno::ECONNRESET: Connection reset by peer - SSL_connect"

I'm unable to get Mechanize to load a page that used to work -- it's reliably failing with a Errno: ECONNRESET: Connection reset by peer - SSL_connect message. Any suggestions as to what I should try or details I should look at? (Please see "what I've tried" below...)
Update 1
Taking a hint from a related S.O. post, I tried accessing the site directly with Net::HTTP. When I set http.ssl_version = :TLSv1, I get a redirect rather than an error (as it should be). So my question becomes: how can I configure Net::HTTP's underlying ssl_version parameters from within Mechanize?
Thanks...
The symptoms:
$ rails console
>> a = Mechanize.new
=> #<Mechanize:0x007fd26789b8e0 ...>
>> p = a.get("http://sce.com")
# (...after a long pause...)
Errno::ECONNRESET: Connection reset by peer - SSL_connect
from /sandbox/usr/lib/ruby/2.0.0/net/http.rb:918:in `connect'
from /sandbox/usr/lib/ruby/2.0.0/net/http.rb:918:in `block in connect'
from /sandbox/usr/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
from /sandbox/usr/lib/ruby/2.0.0/net/http.rb:918:in `connect'
from /sandbox/usr/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
from /sandbox/usr/lib/ruby/2.0.0/net/http.rb:857:in `start'
from /sandbox/usr/lib/ruby/gems/2.0.0/gems/net-http-persistent-2.9/lib/net/http/persistent.rb:691:in `start'
from /sandbox/usr/lib/ruby/gems/2.0.0/gems/net-http-persistent-2.9/lib/net/http/persistent.rb:631:in `connection_for'
...
from /sandbox/usr/lib/ruby/gems/2.0.0/gems/mechanize-2.7.2/lib/mechanize/http/agent.rb:257:in `fetch'
from /sandbox/usr/lib/ruby/gems/2.0.0/gems/mechanize-2.7.2/lib/mechanize/http/agent.rb:974:in `response_redirect'
from /sandbox/usr/lib/ruby/gems/2.0.0/gems/mechanize-2.7.2/lib/mechanize/http/agent.rb:298:in `fetch'
from /sandbox/usr/lib/ruby/gems/2.0.0/gems/mechanize-2.7.2/lib/mechanize.rb:432:in `get'
from (irb):3
The environment:
$ rake about
About your application's environment
Ruby version 2.0.0 (x86_64-darwin12.4.0)
RubyGems version 2.1.9
Rack version 1.5
Rails version 4.0.0
JavaScript Runtime JavaScriptCore
Active Record version 4.0.0
Action Pack version 4.0.0
Action Mailer version 4.0.0
Active Support version 4.0.0
Middleware ActionDispatch::Static, Rack::Lock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007ffd423c50e0>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::Head, Rack::ConditionalGet, Rack::ETag
Application root /Users/me/MyProject
Environment development
Database adapter postgresql
Database schema version 20131017201057
$ openssl version
OpenSSL 1.0.1e 11 Feb 2013
$ system_profiler -detailLevel mini SPSoftwareDataType
System Software Overview:
System Version: OS X 10.8.5 (12F45)
Kernel Version: Darwin 12.5.0
Time since boot: 8 days 7:40
What I've tried:
I've tried the same URL from a Firefox web browser. It works.
I've explicitly set the Mechanize request_headers to exactly mimic the Firefox browser. No change.
I've updated my ssl/cert.pem file (a second time) as described in this S.O post. No change.
I've tried different sites: www.pge.com and www.sdge.com. Both work. There's something different about the www.sce.com site.
Success with Net::HTTP
Here's an example of Net::HTTP working:
$ irb
>> require 'net/https'
=> true
>> require 'uri'
=> false
>> uri = URI.parse("https://www.sce.com/")
=> #<URI::HTTPS:0x007facab8f6ba0 URL:https://www.sce.com/>
>> http = Net::HTTP.new(uri.host, uri.port)
=> #<Net::HTTP www.sce.com:443 open=false>
>> http.use_ssl = true
=> true
>> http.ssl_version = :TLSv1 # <= this line makes all the difference
=> :TLSv1
>> r = http.start { |agent| p agent.get(uri.path) }
=> #<Net::HTTPFound 302 Found readbody=true>
>> r.to_hash
=> {"content-language"=>["en-US"], "date"=>["Fri, 18 Oct 2013 01:00:07 GMT"], "location"=>["https://www.sce.com/wps/portal/home/!ut/p/b1/04_Sj9CPykssy0xPLMnMz0vMAfGjzOIt3Q1cPbz8DTzdQwKNDTyNAw38gh0djQ0MzIAKIoEKDHAARwNC-sP1o8BK8Jjg55Gfm6pfkBthoOuoqAgAgIrzaA!!/dl4/d5/L2dBISEvZ0FBIS9nQSEh/"], "p3p"=>["CP=\"NON CUR OTPi OUR NOR UNI\""], "server"=>["IBM_HTTP_Server"], "transfer-encoding"=>["chunked"], "x-powered-by"=>["Servlet/3.0"], "set-cookie"=>["PD_STATEFUL_d55ece64-8d9a-11e2-84a1-0050560010d6=%2Fwps; Path=/", "session_www=740796608.47873.0000; path=/"]}
The folks on the Mechanize mailing list kindly provided the answer:
agent = Mechanize.new do |a|
a.ssl_version = :TLSv1
end