2009-06-08 210 views
4

我的硒測試喜歡隨機失敗。作爲一個例子,我有這種情況下黃瓜+硒隨機失敗

Scenario: I should be able to edit a user 
    Given I created a user with the login "[email protected]" 
    And I am viewing the user with login "[email protected]" 
    Then I should see "Edit this user" 
    When I click "Edit this user" 
    Then I should be editing the user with login "[email protected]" 
    When I press "Update" 
    Then I should be viewing the user with login "[email protected]" 
    And I should see "User was successfully updated." 

這和其他人一起使用基本的webrat:rails模式工作正常。在硒,線

Then I should be editing the user with login "[email protected]" 

Then I should be viewing the user with login "[email protected]" 

失敗隨機的,因爲有時第一失敗,其他時間秒失敗。手動使用網站會產生正確的操作,就像我說的,webrat/rails模式工作正常。

的Rails 2.2.2 黃瓜0.3.7 硒1.1.14(固定FF3工作)

一些額外的信息:

Scenario: I should be able to edit a user       # features/admin_priviledges.feature:26 
    Given I created a user with the login "[email protected]"  # features/step_definitions/global_steps.rb:18 
    And I am viewing the user with login "[email protected]"   # features/step_definitions/global_steps.rb:60 
    Then I should see "Edit this user"        # features/step_definitions/webrat_steps.rb:93 
    When I click "Edit this user"         # features/step_definitions/webrat_steps.rb:18 
    Then I should be editing the user with login "[email protected]" # features/step_definitions/global_steps.rb:66 
    expected: "https://stackoverflow.com/users/8/edit", 
     got: "https://stackoverflow.com/users/8" (using ==) 
    Diff: 
    @@ -1,2 +1,2 @@ 
    -/users/8/edit 
    +/users/8 
    (Spec::Expectations::ExpectationNotMetError) 
    features/admin_priviledges.feature:31:in `Then I should be editing the user with login "[email protected]"' 
    When I press "Update"           # features/step_definitions/webrat_steps.rb:14 
    Then I should be viewing the user with login "[email protected]" # features/step_definitions/global_steps.rb:66 
    And I should see "User was successfully updated." 

Then /^I should be (editing|viewing) the (\w+) with (\w+) "([^\"]*)"$/ do |action,model,field,value| 
    func = make_func(action,model) 
    m = find_model_by_field_and_value(model,field,value) 
    URI.parse(current_url).path.should == eval("#{func}(m)") 
end 

這些都是相關步驟。新聞「更新」之一是一個標準的網頁瀏覽步驟(click_button)

回答

7

改變從

When /^I press "([^\"]*)"$/ do |button| 
    click_button(button) 
end 

一個webrat步驟

When /^I press "([^\"]*)"$/ do |button| 
    click_button(button) 
    selenium.wait_for_page_to_load 
end 

它的工作原理。告訴硒等待修復!

2

你看過請求的時間嗎?我的直覺說硒正在移動得太快。

你可以發佈你的黃瓜步驟和每個失敗的錯誤消息和日誌詳細信息?

+0

增加了一些更多信息。我可以從Webrat.configure塊中設置硒的速度嗎? – 2009-06-08 20:05:59