Kri*_* MP 7 ruby bdd ruby-on-rails capybara
所以我正在使用水豚编写验收测试。该方案是将我们的时事通讯系统连接到外部邮件服务。
我们将被重定向到我们的外部服务页面以请求访问外部邮件服务。成功后我们将被重定向回我们的系统页面。
When "I grant authorization" do
fill_in "username", :with => "myapp"
fill_in "password", :with => "secret"
click_button "Allow Access"
end
Then "I should see 'Connection Established'" do
page.should have_content "Connection Established"
end
And "I should see that I'm connected to Sample External Service" do
page.should have_content "Connection Established: Sample External Service"
page.should have_content "Deactivate Sample External Service syncing"
end
Run Code Online (Sandbox Code Playgroud)
但是如果我sleep在page.should have_content "Connection Established". 规范将失败。据我所知,使用 sleep 不是最佳做法,因为它会使我们的测试运行缓慢。
如何让它等到它被重定向回我们的系统
Tho*_*ole 10
有 3 种方法可以调整 Capybaras 方法等待其期望为真/元素存在的最长时间
Capybara.default_max_wait_time = <seconds> - 这是全局设置,应该为绝大多数方法调用设置得足够高
Capybara.using_wait_time(<seconds>) do ... end- 这会default_max_wait_time在块内暂时更改,然后在完成后将其恢复为原始设置。当您有许多方法要使用新的等待时间调用时,或者您需要调用一个将等待时间设置为不同值的辅助方法时,这很有意义。
:wait选项 - 所有 Capybara 查找器和期望方法都接受一个:wait选项,该选项将更改该方法调用的最长等待时间。当您遇到需要比正常情况更多等待的特定情况时,可以使用此方法
# This will wait up to 10 seconds for the content to exist in the page
page.should have_content "Connection Established: Sample External Service", wait: 10
Run Code Online (Sandbox Code Playgroud)
注意:将来发布问题时,如果您提供完整的确切错误消息作为问题的一部分通常会有所帮助。
Uni*_*key -1
对于特殊情况,您可以使用Capybara.using_wait_time(seconds)临时更改 的值:Capybara.default_max_wait_time
Capybara.using_wait_time(10) do
page.should have_content "Connection Established"
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4412 次 |
| 最近记录: |