我已经查看了所有其他帖子,因为这些问题似乎都没有帮助,所以我想也许我的情况有点不同?我的问题是我正在尝试使用selenium webdriver与rspec开始为我的网站构建自动化测试。我设置了phantomjs,我正在尝试运行以下示例代码:
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
当我执行ruby phatomjs_spec.rb时,代码运行没有任何问题。但是当我尝试使用rspec phantomjs_spec.rb运行它时,我收到以下错误:
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>'
这是我正在处理的示例的来源:http://elementalselenium.com/tips/46-headless-ghostdriver
我尝试过使用1.3.1,2.0和最新版本的rspec但没有成功。有任何想法吗?在此先感谢您的帮助!
答案 0 :(得分:1)
我发现了这个问题。问题是selenium-webdriver没有列在gemfile中。我在本地安装了它,这就是为什么它使用ruby而不是rspec。这是我找到答案的地方:https://github.com/louismullie/treat/issues/87