在我的场景中有以下几点:
And I click the link Log out
Then I should see the login page单击Log out链接将用户发送到/log_out,然后重定向回登录页面。Webrat失败了,因为它正在寻找“登录”,但log_out页面是空的(它只是一个codeigniter函数,它破坏会话并重定向到/)
让webrat意识到它需要在重定向结束时读取页面的最好方法是什么?
发布于 2012-08-14 14:39:11
一种简单但低效的方法是,仅为执行重定向所需的大致时间添加睡眠。
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如果您发现自己在使用等待其他步骤,则逗号后面的其余步骤可以推广。
https://stackoverflow.com/questions/11927868
复制相似问题