2013-11-15 10 views
5

私は、特定のAJAX呼び出しを読み込むのが遅くなるWebプログラムをテストする自動テストプログラムを作成しています。たとえば、ユーザーは「クエリ」をクリックし、15秒から90秒の間にHTMLの「読み込み」オーバーレイが発生します。検索が完了すると、結果と同じページの表が更新されます。Wait-Webdriverを現在の待機時間のときにグローバルに増やすことは可能ですか?

だから、明らかに私が個別にそうように待機時間を増やすことができます:.when_presentにワチール-webdriverを常に待機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 

しかし、(私の場合の増加に)修正する方法がある時間をそのような:警告の

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

いくつかの単語:Client timeout will not affectwhen_presentNor will implicit wait

答えて

9

アップデート:このサルパッチはwatir-webdriverにマージされているため、watir-webdriver v0.6.5では必要ありません。

Watir.default_timeout = 90 

wait methodsがに似て定義されています:あなたが見ることができるように、30秒のデフォルトのタイムアウトがハードコードされて

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 

あなたは使用してタイムアウトを設定することができるようになります。したがって、どこにでも簡単に変更することはできません。

ただし、待機時間の方法を使用してデフォルト時間を使用し、必要な時間に設定することができます。次のMonkeyパッチは、デフォルトのタイムアウトを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 

watir webdriverコードが読み込まれた後にパッチを含めます。

+0

Rubishを新しくして、これまでにはあまり拡張していなかった。これは私のために完全に働くように見え、私が必要としたものでした。ありがとうございました! – Sam

+2

猿のパッチの代わりに、もちろんこの変更を提案するwatir-webdriverにプルリクエストを送ることができます。 – jarib

関連する問題