本文介绍了使用 Selenium 时出现加载错误:没有要加载的此类文件——规范的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我刚开始学习在 Rails 3 上使用 Selenium,我从 Selenium IDE 开始并生成了 RSpec 格式的脚本

Basically I just started to learn use Selenium on Rails 3, I started with the Selenium IDE and generated the script in RSpec format

在我运行这个脚本之前,我已经为 selenium-clientSeleniumselenium-railsselenium-webdriver 安装了 gems

Before I run this script I have installed gems for selenium-client, Selenium, selenium-rails and selenium-webdriver

但是当我使用 rspec 命令运行这个脚本时,我得到了

But as I using rspec command to run this script, I got

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 无法找到spec"文件夹,尚未有人回答.

I have tried to search for answer, the only case I found that is close to mine is Selenium Can't Find 'spec' Folder, which no one has answered it yet.

有人可以帮助我吗,提前致谢.

Can someone help me please, thanks in advance.

推荐答案

首先我发现 Cucumber + Webrat +Selenium 指南,非常有用

First I found Cucumber + Webrat + Selenium guide which is really useful

其次,我删除了

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

并添加

require 'spec_helper'

其中 spec_helper 包含在 spec 文件夹中

Where spec_helper is the contained in the spec folder

我还删除了 append_after

基本上现在测试用例可以运行了,这不是最好的解决方案,但这是我目前所做的.

Basically now the test cases runnable, this is not the best solution, but it is what I did do so far.

PS:需要从 http://seleniumhq.org/download/ 和使用 java -jar selenium-server-standalone-2.0b2.jar

P.S: need to download the Selenium server from http://seleniumhq.org/download/ and run the server with 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

这篇关于使用 Selenium 时出现加载错误:没有要加载的此类文件——规范的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 08:26