Sam*_*Sam 6 ajax watir-webdriver
我正在编写一个自动测试程序,它将测试一些有时加载某些AJAX调用的Web程序.例如,用户将点击"查询",这将导致HTML"加载"叠加,持续时间为15到90秒.搜索完成后,它将使用结果更新同一页面上的表.
所以显然我可以单独增加等待时间,如下:
browser.td(:id => 'someId').when_present.some_action #=> will wait 30 seconds
browser.td(:id => 'someId').when_present(90).some_action #=> will wait *90* seconds
Run Code Online (Sandbox Code Playgroud)
但有没有办法修改(在我的情况下增加)时间,所以Watir-Webdriver 总是等待90秒,.when_present如下所示:
browser.some_default = 90
browser.td(:id => 'someId').when_present.some_action #=> will wait *90* seconds
Run Code Online (Sandbox Code Playgroud)
更新:这个猴子补丁已合并到watir-webdriver中,因此在watir-webdriver v0.6.5中将不再需要.您可以使用以下方式设置超时:
Watir.default_timeout = 90
Run Code Online (Sandbox Code Playgroud)
在等待的方法是类似这样定义的:
def when_present(timeout = 30)
message = "waiting for #{selector_string} to become present"
if block_given?
Watir::Wait.until(timeout, message) { present? }
yield self
else
WhenPresentDecorator.new(self, timeout, message)
end
end
Run Code Online (Sandbox Code Playgroud)
如您所见,默认超时30秒是硬编码的.因此,没有简单的方法可以随处改变它.
但是,你可以修改等待方法以使用默认时间并将其设置为你想要的.以下猴子补丁将默认超时设置为90秒.
require 'watir-webdriver'
module Watir
# Can be changed within a script with Watir.default_wait_time = 30
@default_wait_time = 90
class << self
attr_accessor :default_wait_time
end
module Wait
class << self
alias old_until until
def until(timeout = Watir.default_wait_time, message = nil, &block)
old_until(timeout, message, &block)
end
alias old_while while
def while(timeout = Watir.default_wait_time, message = nil, &block)
old_while(timeout, message, &block)
end
end # self
end # Wait
module EventuallyPresent
alias old_when_present when_present
def when_present(timeout = Watir.default_wait_time, &block)
old_when_present(timeout, &block)
end
alias old_wait_until_present wait_until_present
def wait_until_present(timeout = Watir.default_wait_time)
old_wait_until_present(timeout)
end
alias old_wait_while_present wait_while_present
def wait_while_present(timeout = Watir.default_wait_time)
old_wait_while_present(timeout)
end
end # EventuallyPresent
end # Watir
Run Code Online (Sandbox Code Playgroud)
加载watir webdriver代码后包含补丁.
| 归档时间: |
|
| 查看次数: |
2747 次 |
| 最近记录: |