2011-03-16 57 views
1

基本上,我剛開始學on Rails的3使用Selenium,我開始與硒IDE和生成的RSpec格式LoadError使用Selenium時:沒有這樣的文件來加載 - 規格

劇本之前,我運行此腳本我已經安裝的寶石selenium-clientSeleniumselenium-railsselenium-webdriver

但是,當我使用rspec的命令來運行該腳本,我得到了

C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:58:in `require': no such file to load -- spec (LoadError) 
    from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:58:in `rescue in require' 
    from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require' 
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/selenium-client-1.2.18/lib/selenium/rspec/spec_helper.rb:2:in `<top (required)>' 
    from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' 
    from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' 
    from C:/Users/qsang/Desktop/Code/NextBigThing/spec/Selenium/create_new_user.rb:5:in `<top (required)>' 
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load' 
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `block in load_spec_files' 
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map' 
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files' 
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run' 
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process' 
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run' 
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `block in autorun' 

我試圖尋找答案,唯一的情況是我發現接近我的是Selenium Can't Find 'spec' Folder,這還沒有人回答。

有人可以幫助我,請提前致謝。

回答

1

首先我發現Cucumber + Webrat + Selenium guide這是

其次,我刪除

require "selenium/rspec/spec_helper" 
require "spec/test/unit" 

並補充

require 'spec_helper' 

spec_helper是包含在規範文件夾

我真的很有用也刪除了所有的方法append_after

基本上現在的測試用例可以運行,這不是最好的解決方案,但這是我迄今爲止所做的。

P.S:需要從http://seleniumhq.org/download/下載Selenium服務器和運行服務器java -jar selenium-server-standalone-2.0b2.jar


spec_helper

# This file is copied to spec/ when you run 'rails generate rspec:install' 
ENV["RAILS_ENV"] ||= 'test' 
require File.expand_path("../../config/environment", __FILE__) 
require 'rspec/rails' 

# Requires supporting ruby files with custom matchers and macros, etc, 
# in spec/support/ and its subdirectories. 
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} 

RSpec.configure do |config| 
    # == Mock Framework 
    # 
    # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: 
    # 
    # config.mock_with :mocha 
    # config.mock_with :flexmock 
    # config.mock_with :rr 
    config.mock_with :rspec 

    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 
    config.fixture_path = "#{::Rails.root}/spec/fixtures" 

    # If you're not using ActiveRecord, or you'd prefer not to run each of your 
    # examples within a transaction, remove the following line or assign false 
    # instead of true. 
    config.use_transactional_fixtures = true 
end 
2

我有這個麻煩,以及。但是我試圖運行這個獨立的,而不是在一個rails3項目。然而我嘗試使用ruby 1.9.2

我實際上試圖測試一個我們想要增量轉換爲rails的IIS/ASP網站。第一步是採用我們完美的「Selenese」測試套件,將它們導出爲RSpec並使用ruby等運行它們。我是ruby/rails領域的新手,我覺得這很令人沮喪。我認爲幾個小時的工作已經變成了幾天...

我遵循類似的戰術爲你自己。但是,我只是刪除了所有的寶石,並要求除require "selenium/client"之外的語句。我也將append_after更名爲afterappend_after方法在selenium/rspec/spec_helper文件中定義(我檢查了lib)。

我已經花了幾個小時在網上搜索,我無法找到答案,爲什麼require "selenium/rspec/spec_helper"聲明失敗 - 它似乎spec(我認爲是RSpec中使用什麼被稱爲)缺少一種叫做。

我讓它工作我認爲它缺少一些功能。 spec_helper似乎處理捕獲系統狀態和其他有用的功能。

我有興趣知道你在你的spec_helper文件。你可以發佈嗎?

+0

我已經安裝了Rspec,並通過執行'rails generate rspec:install'在我的項目文件夾下生成了一個spec文件夾。 'spec_helper'文件包含在這個文件中,我把它放在我的答案中http://stackoverflow.com/questions/5330867/loaderror-when-using-selenium-no-such-file-to-load-spec/5341873#5341873 – Souloikj 2011-04-01 15:21:04

+0

感謝spec_helper澄清。 雖然我打算使用黃瓜和RSpec進一步開發此混合(rails/IIS)網站。我決定走低科技並使用測試/單元,因爲Selenium可以轉換爲測試/單元以及RSpec。這很好,因爲現有的Selenium測試不是非常「RSpec樣」開始 - 而是他們更「測試/統一」;-) 這樣我就可以完全獨立運行這些測試,只有ruby或plop他們在rails應用程序結構中由rake運行。 – danv 2011-04-03 20:34:18

4

問題是您的Rspec版本。 Selenium寶石正在尋找Rspec 1.2.8或更高版本,但Rspec在2.0中對其類結構進行了改動,其中激烈。硒是尋找,只是不Rspec的2不復存在文件,類和方法,如果你卸載 Rspec的一則當前版本:

gem install rspec -v 1.3.1 

應該解決您的問題。如果您在自動化系統中使用Rspec來實現其他功能,這可能不是一個可行的選擇。

相關問題