如何让webrat遵循重定向

时间:2012-08-13 03:30:29

标签: ruby tdd cucumber bdd webrat

我的方案中有以下内容:

And I click the link Log out
Then I should see the login page

单击Log out链接会将用户发送到/ log_out,然后重定向回登录页面。 Webrat失败了,因为它正在寻找"登录"但是log_out页面是空的(它只是一个会破坏会话并重定向到/的codeigniter函数)

让webrat意识到需要在重定向结束时阅读页面的最佳方法是什么?

1 个答案:

答案 0 :(得分:0)

一种简单但效率低下的方法是在执行重定向所需的大致时间内添加一个睡眠。

And I click the link Log out
And I wait for 5 seconds
Then I should see the login page

步骤定义

When /^I wait for (\d+) seconds$/ do |time|
  sleep time.to_i
end

然而,当遇到网络延迟时,这种解决方案非常脆弱,您的等待可能太长或太短。更好的方法是睡觉,直到你要找的内容出现。

And I click the link Log out
Then within 30 seconds, I should see the login page

步骤定义

Then /^within (\d+) seconds, I should see the login page$/ do |time|
  sleep time.to_i until page.has_text? "Login"
  page.should have_content "Login"
end

如果您发现自己正在使用等待其他步骤,则可以概括逗号后面的其余步骤。

相关问题