Bad URI(is not URI?) while trying to use Capybara Apparition driver - capybara

it's my first time trying a webdriver different than selenium with capybara.
I've made this very small script below just to see it running but invalid uri error is thrown.
require 'capybara'
require 'capybara/DSL'
require 'capybara/apparition'
include Capybara::DSL
Capybara.javascript_driver = :apparition
Capybara.default_driver = :apparition
visit('https://github.com/twalpole/apparition')
The error thrown is:
> ruby test.rb
Traceback (most recent call last):
15: from test.rb:9:in `<main>'
14: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/capybara-3.34.0/lib/capybara/DSL.rb:58:in `block (2 levels) in <module:DSL>'
13: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/capybara-3.34.0/lib/capybara/session.rb:278:in `visit'
11: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/apparition-0.6.0/lib/capybara/apparition/driver.rb:50:in `browser'
10: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/apparition-0.6.0/lib/capybara/apparition/driver.rb:69:in `client'
9: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/apparition-0.6.0/lib/capybara/apparition/driver/chrome_client.rb:16:in `client'
8: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/apparition-0.6.0/lib/capybara/apparition/driver/chrome_client.rb:16:in `new'
7: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/apparition-0.6.0/lib/capybara/apparition/driver/chrome_client.rb:33:in `initialize'
6: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/apparition-0.6.0/lib/capybara/apparition/driver/chrome_client.rb:33:in `new'
5: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/apparition-0.6.0/lib/capybara/apparition/driver/web_socket_client.rb:10:in `initialize'
4: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/apparition-0.6.0/lib/capybara/apparition/driver/web_socket_client.rb:10:in `new'
3: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/apparition-0.6.0/lib/capybara/apparition/driver/web_socket_client.rb:69:in `initialize'
2: from C:/Ruby26-x64/lib/ruby/2.6.0/uri/common.rb:234:in `parse'
1: from C:/Ruby26-x64/lib/ruby/2.6.0/uri/rfc3986_parser.rb:73:in `parse'
C:/Ruby26-x64/lib/ruby/2.6.0/uri/rfc3986_parser.rb:67:in `split': bad URI(is not URI?): "ws://127.0.0.1:65515/devtools/browser/1c053b9f-60e6-4cef-822f-4d336aac7fad\r" (URI::InvalidURIError)
Am I missing something?
I've these versions installed: capybara (3.34.0), apparition (0.6.0) and chrome (91.0.4472.77) in windows 10 pro 20H2.

I had the same issue while running Apparition driver.
It seems the issue is present while instantiating new TCP Socket done by the Socket Class defined in Apparition/driver/web_socket_client
The URL passed in the initialize of Socket Class seems to have trailing white space .
Workaround
Navigate to the following path Ruby26-x64\lib\ruby\gems\2.6.0\gems\apparition-0.6.0\lib\capybara\apparition\driver
Note:- The location of Ruby26-x64 depends on where you installed ruby on your system for me it was in C drive
Modify the web_socket_client.rb file present in the above path as shown in the below image
Web_Socket_Client Change
This fixed the issue for me

Related

failed to allocate memory (NoMemoryError) when using RAILS_ENV="production" bundle exec rails c

We just upgraded a Rails app to 4.2 to 5.2, everything is working like a charm in development, but when we try to release the app on our production servers, we can't run any rails related commands (assets precompilation, migrate, console, etc.).
Here is the trace:
Traceback (most recent call last):
15: from bin/rails:4:in `<main>'
14: from bin/rails:4:in `require'
13: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<top (required)>'
12: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/command.rb:46:in `invoke'
11: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/command/base.rb:65:in `perform'
10: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
9: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
8: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
7: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/commands/console/console_command.rb:95:in `perform'
6: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/command/actions.rb:15:in `require_application_and_environment!'
5: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/command/actions.rb:28:in `require_environment!'
4: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/railties-5.2.3/lib/rails/application.rb:337:in `require_environment!'
3: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:292:in `require'
2: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
1: from /var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
/var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require': failed to allocate memory (NoMemoryError)
We added puts file; just before the result = super in dependencies.rb:291, and a puts 'ERROR!' in the rescue in dependencies.rb#L260 and here are the last loaded files:
active_support/per_thread_registry
rack/runtime
rack/utils
active_support/cache/strategy/local_cache_middleware
rack/body_proxy
rack/utils
tzinfo/data
ERROR!
active_support/core_ext/time/zones
ERROR!
Traceback (most recent call last):
More information:
There is 52G of memory on the server, and we already tried adding 10G of SWAP.
Running htop is not giving any Memory leak
EDIT:
We tried removing the raise in dependencies.rb#L261 and of course the console loads, here are the logs:
rack/body_proxy
rack/utils
tzinfo/data
ERROR!
active_support/core_ext/time/zones
tzinfo/data/definitions/America/New_York
ERROR!
/var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/tzinfo-1.2.5/lib/tzinfo/ruby_data_source.rb:35: warning: constant ::Data is deprecated
/var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:396: warning: constant ::Data is deprecated
/var/deploy/slaask_kb/web_head/shared/bundle/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/inflector/methods.rb:283: warning: constant ::Data is deprecated
ERROR!
rails/console/app
active_support/all
action_controller
rails/console/helpers
active_record/base
pp
Loading production environment (Rails 5.2.3)
e2mmap
ERROR!
irb(main):001:0>
I was able to reproduce the issue on a development environment (Windows Subsystem for Linux) too.
We finally managed to solve it by upgrading tzinfo from 1.1 to 1.2.5, as suggested here: https://github.com/tzinfo/tzinfo/issues/30

Problem with port when launching ruby/rails app on windows10/ubuntu

I have two different projects - one that I made for practicing purpose and one that is a real project.
I'm using RVM to set version and they both run on 2.6.0 & rails 5.2.3
My practice project launches fine on localhost:3000. However I can't see anywhere or anyhow that it's being used while running the app (checking in resource manager/netstat)
However when I'm trying to launch the second app I'm getting "listen: Address already in use - listen(2) and rails shuts down.
I've tried restarting the terminal/my computer just to make sure nothing is running on port 3000 and I can't for the life of me understand why it's not working.
Has anyone experienced something similar? I've obviously tried looking at similar questions here however most answers are related to terminating whatever is running on 3000 at the moment, but I can't confirm that anything is.
UPDATED:
Ok so when I launch the app that complains about port being in use I get the following:
/usr/share/rvm/rubies/ruby-2.6.0/bin/ruby: warning: shebang line ending with \r may cause problems
After that it tries to start, it says it's listening on tcp://127.0.0.1:3000 which is fine and dandy, but then it stops and here's the trace:
Traceback (most recent call last):
19: from bin/rails:4:in `<main>'
18: from bin/rails:4:in `require'
17: from /home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<top (required)>'
16: from /home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/railties-5.2.3/lib/rails/command.rb:46:in `invoke'
15: from /home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/railties-5.2.3/lib/rails/command/base.rb:65:in `perform'
14: from /home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
13: from /home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
12: from /home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
11: from /home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:142:in `perform'
10: from /home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:142:in `tap'
9: from /home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:147:in `block in perform'
8: from /home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/railties-5.2.3/lib/rails/commands/server/server_command.rb:53:in `start'
7: from /home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/rack-2.0.7/lib/rack/server.rb:297:in `start'
6: from /home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/puma-4.3.0/lib/rack/handler/puma.rb:73:in `run'
5: from /home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/puma-4.3.0/lib/puma/launcher.rb:172:in `run'
4: from /home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/puma-4.3.0/lib/puma/cluster.rb:463:in `run'
3: from /home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/puma-4.3.0/lib/puma/runner.rb:82:in `start_control'
2: from /usr/share/rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/forwardable.rb:230:in `add_unix_listener'
1: from /home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/puma-4.3.0/lib/puma/binder.rb:328:in `add_unix_listener'
/home/sorgmantel/.rvm/gems/ruby-2.6.0/gems/puma-4.3.0/lib/puma/binder.rb:328:in `listen': Address already in use - listen(2) (Errno::EADDRINUSE)
Breadcrumb Mongo query succeeded meta_data collection:Array has been dropped for having an invalid data type
Is it possible that it has to do with file origins? My project runs fine because it's written in windows but I can't run the other one that was written on MAC, with the different line endings and all. I've heard Ruby can be sensitive when you run it on windows machines.
So apparantly this was caused by
activate_control_app
in my puma.rb file. When I commented it out the app launched fine.

Unable to resolve dependency: user requested 'fileutils (= 1.0.2)' (Gem::UnsatisfiableDependencyError)

I have deployed a branch to Heroky and now I want to run the migrations or load the schema, either way I get:
Unable to resolve dependency: user requested 'fileutils (= 1.0.2)' (Gem::UnsatisfiableDependencyError)
I have tried restarting heroku (heroku restart) and then running heroku run rake db:schema:load but nothing happens.
I also tried running gem update --default but nothing changed.
I'm running Rails 5.2, Ruby 2.5.3, Heroku Cedar-14 Stack (it is deprecated, could this be causing the problem?)
Any ideas?
Traceback (most recent call last):
20: from /app/vendor/bundle/ruby/2.5.0/bin/rake:23:in `<main>'
19: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems.rb:304:in `activate_bin_path'
18: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems.rb:304:in `synchronize'
17: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems.rb:306:in `block in activate_bin_path'
16: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems.rb:243:in `finish_resolve'
15: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems/request_set.rb:397:in `resolve_current'
14: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems/request_set.rb:385:in `resolve'
13: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems/resolver.rb:188:in `resolve'
12: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems/resolver/molinillo/lib/molinillo/resolver.rb:42:in `resolve'
11: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems/resolver/molinillo/lib/molinillo/resolution.rb:64:in `resolve'
10: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems/resolver/molinillo/lib/molinillo/resolution.rb:106:in `start_resolution'
9: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems/resolver/molinillo/lib/molinillo/resolution.rb:165:in `initial_state'
8: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider.rb:51:in `sort_dependencies'
7: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider.rb:69:in `with_no_such_dependency_error_handling'
6: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems/resolver/molinillo/lib/molinillo/delegates/specification_provider.rb:52:in `block in sort_dependencies'
5: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems/resolver.rb:277:in `sort_dependencies'
4: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems/resolver.rb:277:in `with_index'
3: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems/resolver.rb:277:in `sort_by'
2: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems/resolver.rb:277:in `each'
1: from /app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems/resolver.rb:283:in `block in sort_dependencies'
/app/vendor/ruby-2.5.3/lib/ruby/2.5.0/rubygems/resolver.rb:231:in `search_for': Unable to resolve dependency: user requested 'fileutils (= 1.0.2)' (Gem::UnsatisfiableDependencyError)
I had this error after upgrade of bunlder to v1.9.9, and solved it with:
sudo gem install bundler -v 1.17.3
If you have several bundler versions installed, then you can run specific version of bundle this way: bundle _1.17.3_ exec rspec
Though seems like later bundler versions are pretty buggy, having one old bundler may work the best, at least this is what I have on my Ubuntu.
if running on a deprecated stack, upgrading it should solve the problem

Rails test error " UNIXServer is required (LoadError)" on windows

I am running into an issue when trying to execute "rails test" on windows.
Issue:
17: from test/controllers/users_controller_test.rb:1:in `<main>'
16: from C:/Ruby25-x64/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
15: from C:/Ruby25-x64/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
14: from C:/Users/ES0074223/RubyOnRails/firefly/test/test_helper.rb:5:in `<top (required)>'
13: from C:/Users/ES0074223/RubyOnRails/firefly/test/test_helper.rb:6:in `<class:TestCase>'
12: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-6.0.0.beta1/lib/active_support/test_case.rb:82:in `parallelize'
11: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-6.0.0.beta1/lib/active_support/test_case.rb:82:in `new'
10: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-6.0.0.beta1/lib/active_support/testing/parallelization.rb:54:in `initialize'
9: from C:/Ruby25-x64/lib/ruby/2.5.0/drb/drb.rb:1710:in `start_service'
8: from C:/Ruby25-x64/lib/ruby/2.5.0/drb/drb.rb:1710:in `new'
7: from C:/Ruby25-x64/lib/ruby/2.5.0/drb/drb.rb:1404:in `initialize'
6: from C:/Ruby25-x64/lib/ruby/2.5.0/drb/drb.rb:772:in `open_server'
5: from C:/Ruby25-x64/lib/ruby/2.5.0/drb/drb.rb:804:in `auto_load'
4: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-6.0.0.beta1/lib/active_support/dependencies.rb:297:in `require'
3: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-6.0.0.beta1/lib/active_support/dependencies.rb:263:in `load_dependency'
2: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-6.0.0.beta1/lib/active_support/dependencies.rb:297:in `block in require'
1: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-6.0.0.beta1/lib/active_support/dependencies.rb:297:in `require'
C:/Ruby25-x64/lib/ruby/2.5.0/drb/unix.rb:6:in `<top (required)>': UNIXServer is required (LoadError)
Any help is much appreciated.
Might be related to Rails Issue #34410 Windows support for parallelization and instrumenter
Problem still exists today (end of nov 2019)
$ rails test
Traceback (most recent call last):
28: from bin/rails:9:in `<main>'
...
8: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/activesupport-6.0.1/lib/active_support/testing/parallelization.rb:58:in `initialize'
7: from C:/Ruby26-x64/lib/ruby/2.6.0/drb/drb.rb:1715:in `start_service'
6: from C:/Ruby26-x64/lib/ruby/2.6.0/drb/drb.rb:1715:in `new'
5: from C:/Ruby26-x64/lib/ruby/2.6.0/drb/drb.rb:1403:in `initialize'
4: from C:/Ruby26-x64/lib/ruby/2.6.0/drb/drb.rb:772:in `open_server'
3: from C:/Ruby26-x64/lib/ruby/2.6.0/drb/drb.rb:804:in `auto_load'
2: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/zeitwerk-2.2.1/lib/zeitwerk/kernel.rb:23:in `require'
1: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/zeitwerk-2.2.1/lib/zeitwerk/kernel.rb:23:in `require'
C:/Ruby26-x64/lib/ruby/2.6.0/drb/unix.rb:6:in `<top (required)>': UNIXServer is required (LoadError)
The important part of the error messages was from testing/parallelization.rb.
In test/test_helper.rb: add "with threads":
parallelize(workers: :number_of_processors, with: :threads)
But this alone did not solve the problem. I also had
to upgrade sass-rails to version 6 (I had 5 before) in the Gemfile:
gem 'sass-rails', '>= 6'
and do a bundle update.
Why sass-rails is involved is a mystery.
From this article, it looks like this issue comes from the application using Unix sockets, which isn't supported on Windows.
I strongly suggest you run the application in Docker. This will solve your issues, but will -- of course -- not be a native windows experience.

Unitialized constant error in rails console vs. irb using a Mechanize wrapper

First question from a fundamental level - What is the meaning of an un-initialized constant error in Ruby? I come from an objective-c background, if that helps provide some context.
Secondly, I am running a rake task in rails that is throwing the aforementioned error. Specifically, the error occurs when I am using the 'tor-privoxy' gem, which is a Mechanize wrapper allowing automated browsing through a tor proxy.
I am using the following example code provided on github: https://github.com/pirj/tor-privoxy
agent ||= TorPrivoxy::Agent.new '127.0.0.1', '', {8118 => 9050} do |agent|
sleep 10
puts "New IP is #{agent.ip}"
page = agent.get('https://www.example.com/')
end
>> New IP is 72.141.125.115
>> NameError: uninitialized constant Net::HTTP::Persistent::SSLReuse::HTTPResponse
from /Library/Ruby/Gems/1.8/gems/net-http-persistent-2.3.3/lib/net/http/persistent/ssl_reuse.rb:115:in `connect'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:548:in `start'
from /Library/Ruby/Gems/1.8/gems/net-http-persistent-2.3.3/lib/net/http/persistent.rb:405:in `connection_for'
from /Library/Ruby/Gems/1.8/gems/net-http-persistent-2.3.3/lib/net/http/persistent.rb:616:in `request'
from /Library/Ruby/Gems/1.8/gems/mechanize-2.1/lib/mechanize/http/agent.rb:264:in `fetch'
from /Library/Ruby/Gems/1.8/gems/mechanize-2.1/lib/mechanize.rb:319:in `get'
from /Library/Ruby/Gems/1.8/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:16:in `send'
from /Library/Ruby/Gems/1.8/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:16:in `method_missing'
from (irb):4
from /Library/Ruby/Gems/1.8/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:11:in `call'
from /Library/Ruby/Gems/1.8/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:11:in `initialize'
from (irb):1:in `new'
from (irb):1
On the other hand, if I run this same code in irb, it does not throw the unitialized constant error. I have ensured that my gemfile includes 'tor-privoxy' and ran the 'bundle install' command.
if you want to work with ruby on your mac, i recommend that you use a tool like rvm or rbenv to manage your installation of ruby.
the error that you are experiencing seems to be already known. have a look at this github issue: https://github.com/thrillcall/net-http-persistent/commit/9f770b4660f1c9c433c1f3b50ba24dd4f1f71cf8

Resources