黄瓜 + selenium 随机失败

5
我的Selenium测试经常会随机失败。例如,我有这个场景:
Scenario: I should be able to edit a user
  Given I created a user with the login "test@example.com"
  And I am viewing the user with login "test@example.com"
  Then I should see "Edit this user"
  When I click "Edit this user"
  Then I should be editing the user with login "test@example.com"
  When I press "Update"
  Then I should be viewing the user with login "test@example.com"
  And I should see "User was successfully updated."

这些内容与基本的webrat:rails模式一起使用时都可以正常工作。在selenium中,这一行代码是:
Then I should be editing the user with login "test@example.com"

并且

Then I should be viewing the user with login "test@example.com"

测试有时候会随机失败,有时第一个失败,有时第二个失败。手动操作网站可以正常运行,而且像我说的那样,使用webrat/rails模式也正常工作。

Rails 2.2.2 Cucumber 0.3.7 selenium 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 "test@example.com"        # features/step_definitions/global_steps.rb:18
  And I am viewing the user with login "test@example.com"         # 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 "test@example.com" # features/step_definitions/global_steps.rb:66
    expected: "/users/8/edit",
         got: "/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 "test@example.com"'
  When I press "Update"                                           # features/step_definitions/webrat_steps.rb:14
  Then I should be viewing the user with login "test@example.com" # 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

以下是相关步骤。"更新"按钮是一个标准的webrat步骤(click_button)。
2个回答

8
更改Webrat步骤的方法如下:
When /^I press "([^\"]*)"$/ do |button|
  click_button(button)
end

to

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

它有效了。告诉Selenium等待即可解决!


3

你有没有查看请求的时间?我的直觉告诉我这是因为selenium运行得太快了。

你能否发布你的cucumber步骤以及每个失败的错误消息和日志详细信息?


增加了一些信息。我可以在Webrat.configure块中设置Selenium的速度吗? - Daniel Huckstep
有任何解决方法吗?看起来我遇到了同样的问题。 - Julian Maicher

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接