Getting an error with Ruby/Selenium - ruby

I am trying to use Selenium with Ruby. I am new to Ruby, I set it up using this blog http://testnerdy.blogspot.ca/2009/10/installing-ruby-and-selenium-on-windows.html
and the Ruby script I used is from here - http://testnerdy.blogspot.ca/2009/10/running-selenium-tests-written-in-ruby.html
When I ran the script, I get this error
SeleniumRubyWindowsTest.rb:1:in `require': no such file to load -- selenium/client (LoadError)
from SeleniumRubyWindowsTest.rb:1
Any ideas on what I may be doing wrong?

Have you installed the selenium gem? If so, depending on your version of ruby you may need to do a
require 'rubygems'
as the first line of the script to pull in all the gem dependencies, which selenium could be one.

Related

cannot load such file -- capybara (LoadError)

I'm trying to run a ruby file that uses capybara and selenium.
When I run cucumber, I get the error :
cannot load such file -- capybara (LoadError)
I saw in another answer that, in order to solve this problem, I had to install poltergeist, but when I run - gem install poltergeist
, I get the error ERROR: While executing gem ... (ArgumentError)
wrong number of arguments (given 1, expected 0)
Any help will be appreciated
You need to include/install the capybara gem, not poltergeist.
I recommend running cucumber with params -v -b , so that you can see where it's failed with verbose & backtrace log.
cucumber -v -b <your_cucumber_features/tag>
The message
cannot load such file -- capybara (LoadError)
was prompted when you've defined to use capybara in your ruby file but your machine hasn't been installed that gem. So need installing capybara via
gem install capybara
However, gem will be installed to specific RVM, so that if you have any error, then try to see which Ruby version that you install onto your system. I suggest install rbenv so that you can manage it better.

Can't load Nokogiri gem when running a .rb file from a text editor, but it works fine in the Ruby command shell

I use Scintilla Text Editor and Sublime Text 2.
Whenever I use them to run a Ruby script containing:
require 'nokogiri'
...I get this error:
C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- nokogiri (LoadError)
from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/Users/MY_RUBY_SCRIPT.rb:3:in `<main>'
I'm using Ruby 1.9.3 and I made sure to require rubygems, but I still got the error.
However, when I run the script from the Command Prompt With Ruby, the script works fine.
Does anyone know why the script fails in text editors, but not in the Command Prompt?
Maybe your editor runs a different version of Ruby. You can check by running
puts RUBY_VERSION
Turns out I had both Ruby 1.9.2 and 1.9.3 installed, which caused the conflict in SciTE, which was trying to find the gem in Ruby 1.9.2 instead of 1.9.3. I uninstalled 1.9.2 and the script worked fine. If I do need 1.9.2 in the future, I suppose I'll have to learn RVM.

cannot load such file -- ntlm/http (LoadError) - ruby

I'm using ntlm-http gem to verify Windows authentication. This works fine when I run in my test Ruby code, but when I implement it using Cucumber it complains of:
cannot load such file -- ntlm/http (LoadError)
Can any one help me with this please?
Try the following:
require 'net/ntlm_http'
Worked for me!

WEBrick CGI handler pointing to wrong gem location

I am trying to execute my CGI program from WEBrick CGIhandler and kept failing with 'loaderror' of gem libraries. Is someone seen following behavior before? How could I get my CGI scripts to search valid gem location?
[Situaltion]
When I ran CGI scripts that requires 'mysql2' library via Webrick server, I got a following error:
ERROR CGIHandler: /home/charles/code/svr/lib/cgitest.rb:
/home/charles/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mysql2/version (LoadError)
Comment this particular 'require' out from cgitest.rb makes this script work so looks just failed to load this library. Added "puts Gem.path" to the script indicates CGIHandler is looking to following directories to find gem;
["/home/charles/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1", "/.gem/ruby/1.9.1"]
while actual GEM:HOME and GEM:PATH are following;
["/home/charles/.rvm/gems/ruby-1.9.3-p194", "/home/charles/.rvm/gems/ruby-1.9.3-p194#global"]
I think I am missing something very simple but could not figure them out. Really appreciate if someone lead me to the right direction. Any input would be highly welcome.
[Environment]
Using RVM to install Ruby 1.9.3 to Ubuntu Server 12.4 with bunch of gems including "mysql2" library. And the script can load 'mysql2' when I run from local.
$which ruby
/home/charles/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
$irb
1.9.3-p194 :001 > Gem.path
=> ["/home/charles/.rvm/gems/ruby-1.9.3-p194", "/home/charles/.rvm/gems/ruby-1.9.3-
p194#global"]
1.9.3-p194 :002 > require 'mysql2'
=> true
You need to use wrapper instead of bin/ruby:
/home/charles/.rvm/wrappers/ruby-1.9.3-p194/ruby
This will ensure you load proper environment when starting ruby.

OSX Ruby Gems Add to ruby path?

I am just starting to learn ruby. It seems that the default gems install path is not part of Ruby. Is this normal behavior? How can I set the default ruby path? Example:
[11:53:33]wuntee:/Library/Ruby/Gems/1.8/gems/packetfu-1.0.0/examples$ sudo ruby arphood.rb
Fetching the oui.txt from IEEE, it'll be a second. Avoid this with arphood.rb <filename>.
arphood.rb:30:in `require': no such file to load -- packetfu (LoadError)
from arphood.rb:30:in `arp_everyone'
from arphood.rb:51
As you can see packetfu is installed in /Library/Ruby/Gems/1.8/gems/, but ruby cant find it...
that's because you're not in the directory where packetfu.rb file lies and there's no require 'rubygems' to add the gems paths in your script

Resources