【问题标题】:Should I use Selenium or Jasmine in order to test view files with RSpec?我应该使用 Selenium 还是 Jasmine 来使用 RSpec 测试视图文件?
【发布时间】:2012-04-02 01:07:12
【问题描述】:

我将 Ruby on Rails 3.2.2、cucumber-rails-1.3.0、rspec-rails-2.8.1 和 capybara-1.1.2 与 Selenium 驱动程序一起使用。在收到我的previous question 的答案后,我有一个疑问:我应该使用 Selenium ruby​​-gem 还是 Jasmine ruby​​-gem 来使用 RSpec 测试视图文件?如果是这样,因为我我已经在使用 Selenium 来测试 JavaScript 以使用 Cucumber 查看文件,为什么(使用 RSpec 进行测试时)我应该使用 Jasmine 而不是 Selenium?也就是说,为什么要使用两个目的相同的ruby-gem,制作相同的东西?

一般而言,您如何建议使用 RSpec 测试视图文件? ...但是,这是使用 RSpec 测试视图文件的“正确方法”还是应该使用 Cucumber 测试这些文件?

【问题讨论】:

    标签: ruby-on-rails ruby selenium rspec jasmine


    【解决方案1】:

    我更喜欢使用 selenium 服务器,firefox 中的 selenium IDE 来记录和 rspec 的 selenium 客户端。

    selenium_helper.rb

    ENV["RAILS_ENV"] ||= 'test'
    require File.expand_path(File.join(File.dirname(__FILE__),'../..','config','environment'))
    require 'spec/autorun'
    require 'spec/rails'
    require 'factory_girl'
    require 'rspec/instafail'
    require "selenium/client"
    
    Spec::Runner.configure do |config|
    end
    

    rspec_tester_file_spec.rb

      require "selenium/selenium_helper"
        require "selenium/modules/loginator"
    
        describe "tester" do
          attr_reader :selenium_driver
          alias :page :selenium_driver
    
          before(:all) do
            @verification_errors = []
            @selenium_driver = Selenium::Client::Driver.new \
              :host => "localhost",
              :port => 4444,
              :browser => "*firefox",
              :url => "http://localhost:3000",
              :timeout_in_second => 60
          end
    
          before(:each) do
            @selenium_driver.start_new_browser_session
          end
    
          append_after(:each) do
            @selenium_driver.close_current_browser_session
          end
    
          it "login and then try to search for stuff" do
            @login.run_login(page)
            page.click "link=CSR"
            page.wait_for_page_to_load "30000"
            page.type "id=isq_Name", "john smith"
            page.click "css=input[type=\"submit\"]"
            page.wait_for_page_to_load "30000"
            page.is_text_present("Update")
            page.is_text_present("Date")
            page.is_text_present("PIN")      
            page.is_text_present("Name")
          end
    

    【讨论】:

    • 我还想补充一点,我确实使用 jasmine,但仅用于 javascript 测试,从不用于基于视图的测试。此外,如果我有一个可以用 jasmine 测试的 javascript 函数,那么我会,但不是在它改变 UI 元素时。我用 selenium 检查的 UI 元素。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多