是否有可能在全球范围内增加Watir-webdriver的when_ present的等待时间? [英] Is it possible to globally increase Watir-Webdriver when_present wait time?

查看:166
本文介绍了是否有可能在全球范围内增加Watir-webdriver的when_ present的等待时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个自动化的测试计划,将测试有时加载缓慢某些AJAX调用一些web程序。例如,用户将点击查询,这将导致HTML装载覆盖任何地方从15秒到90秒。当搜索完成时,便用结果在同一页上更新表

I am writing an automated testing program which will test some web programs that are sometimes slow to load certain AJAX calls. For instance the user will click 'Query' which will result in a HTML 'loading' overlay for anywhere from 15 to 90 seconds. When the search completes, it will then update a table on the same page with the results.

所以,很显然,我可以增加单独的等待时间,像这样:

So obviously I can increase the waiting time individually like so:

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

但是,有没有办法修改(在我的情况增加)的时间,所以Watir-webdriver的总是的上等待90秒 .when_ present 像这样:

But is there a way to modify (in my case increase) the time so Watir-Webdriver always waits 90 seconds on .when_present like so:

browser.some_default = 90
browser.td(:id => 'someId').when_present.some_action #=> will wait *90* seconds

警告的几句话:客户端超时不会影响 when_ present 也将隐含等待

推荐答案

更新的:这只猴子补丁已经合并到watir-webdriver的,因此将不再需要在watir-webdriver的v0.6.5 。您可以使用,设置超时时间:

Update: This monkey patch has been merged into watir-webdriver and so will no longer be needed in watir-webdriver v0.6.5. You will be able to set the timeout using:

Watir.default_timeout = 90


借助等待定义类似的方法:


The wait methods are defined similar to:

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

正如你所看到的,在30秒的默认超时是硬codeD。因此,有没有简单的方法来到处改变它。

As you can see, the default timeout of 30 seconds is hard-coded. Therefore, there is no easy way to change it everywhere.

不过,你可以猴子修补等方法来使用默认的时间,将其设置为你想要的。下面的猴子补丁将设置默认的超时时间为90秒。

However, you could monkey patch the wait methods to use a default time and set it to what you want. The following monkey patch will set the default timeout to 90 seconds.

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

包含补丁加载watir webdriver的code后。

Include the patch after the watir webdriver code is loaded.

这篇关于是否有可能在全球范围内增加Watir-webdriver的when_ present的等待时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆