Jeff W
Jeff W

Reputation: 568

selenium-webdriver (LoadError) when using with rspec

I have looked at all the other post for questions like this an none of them seem to help, so i am thinking that maybe my case is a bit different? My problem is that i am trying to use selenium webdriver with rspec to start building automated tests for my site. I setup phantomjs and I am trying to run the following example code:

require "selenium-webdriver"
require 'rspec/expectations'

include RSpec::Matchers

def setup
  @driver = Selenium::WebDriver.for :remote, url: 'http:/localhost:8001'
end

def teardown
  @driver.quit
end

def run
  setup
  yield
  teardown
end

run do
  @driver.get 'http://the-internet.herokuapp.com'
  expect(@driver.title).to eql 'The Internet'
end

the code runs without any issues when i just do ruby phatomjs_spec.rb. but when i try to run it with rspec phantomjs_spec.rb i get the following error:

ja:beta jw$ rspec ./spec/selenium/phantom_spec.rb
/Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require': cannot load such file -- selenium-webdriver (LoadError)
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `block in require'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:214:in `load_dependency'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
    from /Applications/XAMPP/xamppfiles/htdocs/rl/web/beta/spec/spec_helper.rb:5:in `<top (required)>'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1181:in `require'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1181:in `block in requires='
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1181:in `each'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1181:in `requires='
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-3.2.2/lib/rspec/core/configuration_options.rb:110:in `block in process_options_into'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-3.2.2/lib/rspec/core/configuration_options.rb:109:in `each'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-3.2.2/lib/rspec/core/configuration_options.rb:109:in `process_options_into'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-3.2.2/lib/rspec/core/configuration_options.rb:22:in `configure'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:96:in `setup'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:85:in `run'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:70:in `run'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:38:in `invoke'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-3.2.2/exe/rspec:4:in `<top (required)>'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/bin/rspec:19:in `load'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/bin/rspec:19:in `<main>'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `eval'
    from /Users/jw/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `<main>'

here is the source of the example i was working on: http://elementalselenium.com/tips/46-headless-ghostdriver

I have tried using 1.3.1, 2.0 and the latest version of rspec without any success. Any ideas? Thanks in advance for your help!

Upvotes: 0

Views: 394

Answers (1)

Jeff W
Jeff W

Reputation: 568

I found the issue. The issue was that selenium-webdriver wasn't listed in the gemfile. I had installed it locally, that is why it was working with ruby but not rspec. Here is where i found the answer:https://github.com/louismullie/treat/issues/87

Upvotes: 1

Related Questions