2011-06-29 13 views
0

次の統合テストがあります。フォーム上にフォームをロードします。送信ボタンがデータなしで押されると、フォームにエラーボックスが表示されます。フォームはajaxで送信され、エラーが発生したページにフォームを戻す必要があります。NOOBセレンrspecテストが通過しない

これはブラウザで見ることができますが、テストは失敗します。

私は間違っていますか?私は完全なNOOBですので、いくつかのガイダンスが必要です。

は 'spec_helperは、' 私はそれを考え出した "RubyGemsの"

describe "Boards" do 

    describe "board creation failure" 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 => "*chrome", 
     :url => "http://localhost:3000/", 
     :timeout_in_second => 60 
    end 

    before(:each) do 
     @selenium_driver.start_new_browser_session 
    end 

    after(:each) do 
     @selenium_driver.close_current_browser_session 
     @verification_errors.should == [] 
    end 

    it "should show the error explanation div" do 
     page.open "/" 
     page.click "board_submit" 
     page.is_element_present("error_explanation").should be_true #should show error box 
    end 
    end 

答えて

1

を必要と 必要です。

すべてのajax呼び出しが完了するまで待つようにSeleniumに指示するには、次のメソッドを追加する必要がありました。

このメソッドをspec/spec_helper.rbファイルに入れ、ファイルにrequire 'spec_helper'があることを確認しました。あなたは私も私のコードをクリーンアップし、それをよりDRYにするためにspec_helper.rbファイルにselenium_driverのためのセットアップコードを動かす上で見ることができるように

 #needed for selenium ajax testing 
     def wait_for_ajax(timeout=5000) 
      js_condition = 'selenium.browserbot.getUserWindow().jQuery.active == 0' 
      @selenium_driver.wait_for_condition(js_condition, timeout) 
     end 



    #needed for selenium ajax testing 

    def selenium_setup 

     @verification_errors = [] 
     @selenium_driver = Selenium::Client::Driver.new \ 
     :host => "localhost", 
     :port => 4444, 
     :browser => "*firefox", 
     :url => "http://localhost:3000/", 
     :timeout_in_second => 60 
     #return @selenium_driver 
    end 

:ここ

はspec_helper.rb方法であります:ここでは

は私の統合テストファイルです:

require 'spec_helper' 

describe "Board form" do 
    attr_reader :selenium_driver 
    alias :page :selenium_driver 

    before(:all) do 
    selenium_setup 
    @selenium_driver.start_new_browser_session 
    end 

    after(:all) do 
    @selenium_driver.close_current_browser_session 
    @verification_errors.should == [] 
    end 

    describe "create board" do 
     describe "failure" do 
     it "test_ home page form" do 
      page.open "/" 
      ("Happy Birthday Greetings | Home").should == page.get_title 
      page.is_element_present("board_bp_name").should be_true 
      page.is_text_present("Name").should be_true 
      ("Happy Birthday Greetings | Home").should == page.get_title 
      page.click "board_submit" 
      wait_for_ajax 
      page.is_element_present("board_bp_name").should be_true 
      page.is_text_present("Name").should be_true 
      page.is_element_present("board_birthday_1i").should be_true 
      page.is_element_present("board_submit").should be_true 
      page.is_text_present("exact:Oops, looks like 1 error occured: \n Hey whose birthday is it? Please enter a name.").should be_true 
      page.is_element_present("error_explanation").should be_true 
     end 
     end 

     describe "success" do 

     it "should create a new board for a properly filled in form and show the correct flash message" do 
      page.open "/" 
      page.type "board_bp_name", "Test User" 
      page.select "board_birthday_2i", "label=October" 
      page.select "board_birthday_1i", "label=1967" 
      page.select "board_birthday_3i", "label=7" 
      page.click "board_submit" 
      wait_for_ajax 
      page.wait_for_page_to_load("30000") 
      page.get_location().should =~ /boards\/\d/i 
      page.is_element_present("css=div.flash.success").should be_true 
      page.is_text_present("Your friend's board has been created.").should be_true 
      page.is_text_present("Test User").should be_true 
      page.is_text_present("43").should be_true 
      page.is_element_present("greeting_link").should be_true 
      page.is_text_present("Add greeting").should be_true 
     end 
     end 
    end 
    end 
関連する問題