gpt4 book ai didi

ruby-on-rails - cucumber + Selenium 随机失败

转载 作者:数据小太阳 更新时间:2023-10-29 07:25:23 25 4
gpt4 key购买 nike

我的 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.7selenium 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 步骤(点击按钮)

最佳答案

更改 webrat 步骤
When /^I press "([^\"]*)"$/ do |button|
click_button(button)
end

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

它有效。让 selenium 等待修复!

关于ruby-on-rails - cucumber + Selenium 随机失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/966052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com