2009-06-08 173 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