6

I've been using selenium IDE at work. Now we have decided to use Selenium webdriver with Ruby. I'm totally confused about how to set up my Mac, Mac Pro Yosemite 10.10.5.

In my terminal, I ran these commands:

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew doctor
Your system is ready to brew.
$ brew install ruby
  ==> Summary
  /usr/local/Cellar/openssl/1.0.2d_1: 464 files, 18M
==> Installing ruby
==> Downloading https://homebrew.bintray.com/bottles/ruby-2.2.3.yosemite.bottle.100.0%
==> Pouring ruby-2.2.3.yosemite.bottle.tar.gz
    /usr/local/Cellar/ruby/2.2.3: 1080 files, 20M

$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]

$ sudo gem install selenium-webdriver
   Done installing documentation for websocket, ffi, childprocess, rubyzip, multi_json, selenium-webdriver after 25 seconds
6 gems installed

I exported the script recorded from IDE into a Ruby script with: export as ruby/rspec/webdriver. I saved my example script as Exam.rb in documents.

When I run rspec Exam.rb, I get the following error:

/usr/local/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in `load': cannot load such file -- /Users/xxxx/Documents/Exam.rb (LoadError)     
    from /usr/local/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in `block in load_spec_files'        
    from /usr/local/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in `each'        
    from /usr/local/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in `load_spec_files'     
    from /usr/local/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:102:in `setup'       
    from /usr/local/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:88:in `run'      
    from /usr/local/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:73:in `run'      
    from /usr/local/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:41:in `invoke'       
    from /usr/local/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/exe/rspec:4:in `<top (required)>'     
    from /usr/local/bin/rspec:23:in `load'      
    from /usr/local/bin/rspec:23:in `<main>'        

And when I cheked the ruby version:

ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
SoAwesomeMan
  • 2,926
  • 1
  • 17
  • 23
sandy
  • 117
  • 11
  • 1
    did you check this Link? http://stackoverflow.com/questions/18868743/how-to-install-selenium-webdriver-on-mac-os – Sankar Oct 14 '15 at 09:46
  • @SankarRaj Chked. Actually, my prob is diff. I get errors when trying to open a ruby script. So i think i have gone wrong with my set up – sandy Oct 14 '15 at 09:58
  • 2
    could you please include the 'Exam.rb' file? – hamitron Dec 02 '15 at 19:34
  • 1
    also a few things. use rvm for ruby installs instead of the system ruby, and don't sudo install gems, that can be problematic. – hamitron Dec 02 '15 at 19:36

1 Answers1

0

After you have ruby (I recommend RubyVersionManager or rbenv)

You need to install the gem selenium-webdriver

And after that, you need a driver to control the desired browser, in my case I install ChromeDriver, it's just a binary(I added it to my home and edit the environment variable $PATH with the path to the binary) And thats all everything is working, you can run this litlle script to verify it:

require "selenium-webdriver"

driver = Selenium::WebDriver.for :chrome
driver.navigate.to "http://www.google.com"
element = driver.find_element(:name, 'q')
element.send_keys "Hello Selenium WebDriver!"
element.submit
puts driver.title

Consult this book: Selenium WebDriver Recipes in ruby of Zhimin Zhan

G. I. Joe
  • 1,332
  • 14
  • 21