2012-04-02 71 views
1

我正在使用Selenium驱动程序使用Ruby on Rails 3.2.2,cucumber-rails-1.3.0,rspec-rails-2.8.1和capybara-1.1.2。在收到我的previous question的答案后,我怀疑:我应该使用Selenium ruby​​-gem还是Jasmine ruby​​-gem来测试使用RSpec的视图文件?如果是这样,因为我已经在使用Selenium来测试用于查看黄瓜文件的JavaScript,为什么(当用RSpec测试时)应该使用Jasmine而不是Selenium?也就是说,为什么要使用两个具有相同目的的红宝石并制作相同的东西?我应该使用Selenium还是Jasmine来测试使用RSpec的视图文件?

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

回答

2

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

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 
+0

我想也补充一点,我使用的茉莉花但只针对JavaScript的测试,从不为视图基础的测试。此外,如果我有一个可以用茉莉花测试的javascript函数,那么我会,但不是当它改变UI元素时。 UI元素,我检查与硒。 – earlonrails 2012-05-11 21:04:25

相关问题