在我们使用watir-webdriver的Ruby应用程序web测试应用程序中,我们添加了代码,允许页面上存在但尚未可见的元素长达30秒(由于AJAX,javascript,性能,等等。)。正在测试的例程是:
start_time = Time.now
while !visible? do
@logger.info "!visible is true, looping"
sleep 1
if Time.now - start_time > 30
@logger.debug("error while checking for visible")
raise ElementHiddenError, element_hidden_message
end
end
用于测试的RSpec是:
...
it "raises ElementHiddenError if element is hidden" do
element.should_receive(:visible?).and_return(false)
expect { proxy.set('something') }.to raise_error(ElementHiddenError)
end
....
当我运行此RSpec时,我收到此错误:
1)
'ElementProxy#set raises ElementHiddenError if element is hidden' FAILED
expected ElementHiddenError but nothing was raised
./spec/element_proxy_spec.rb:144:in `(root)'
org/jruby/RubyKernel.java:2043:in `instance_eval'
./spec/spec_helper.rb:68:in `timeout'
org/jruby/RubyArray.java:1614:in `each'
org/jruby/RubyArray.java:1614:in `each'
org/jruby/RubyKernel.java:1052:in `load'
我可以通过评论循环来获得此RSpec:
#start_time = Time.now
while !visible? do
@logger.info "!visible is true, looping"
sleep 1
#if Time.now - start_time > 30
@logger.debug("error while checking for visible")
raise ElementHiddenError, element_hidden_message
#end
end
我不是这段代码的原作者,但似乎在RSpec中发生了时间或睡眠的事情正在影响这个测试。
我很感激有关如何调试此问题的任何想法,因为几乎所有命令集都使用此例程。延迟适用于我们的应用程序,但未通过RSpec。
感谢。