3

feksを書いてテキストフィールドを埋めるwatirテストを作成しようとしています

「lon」とドロップダウンがトリガーされるまで待ってから、リストの最初の要素をクリックします。

「lon」と書くと、「London, England, Storbritannia」、London、Kentucky、USA などの多くのオプションがトリガーされます。事前にt​​hnx。

これは私のコードが今までどのように見えるかですが、それはうまくいきません。

def test_scriptflight_autocomplete @site.navigate_to(:travel, :flight) from_field = @site.ie.text_field(:id, "locOriginName") to_field = @site.ie.text_field(:id, 'locDestinationName') from_field.set('オスロ')

# need to fire a key press event after setting the text since the js is handling
# trigger the autocomplete (requires a 'keydown')
from_field.fire_event('onkeydown')   

# wait until the autocomplete gets populated with the AJAX call
@site.ie.wait_until{@site.ie.div(:id, 'onlinesearch').lis.length > 0}
puts @site.ie.div(:id, 'locOriginName ').lis.length
puts @site.ie.div(:id, 'locOriginName').li(:index, 5).text

# find the li you want to select in the autocomplete list and click it
@site.ie.div(:id, 'from-field').li(:text, 'Oslo, Oslo, Norge').click

終わり

4

1 に答える 1

2

私と職場の同僚 (Magnar) は、私が探していた答えを見つけるのに役立つこのブログを見つけました。

http://blog.saush.com/2008/05/using-rspec-and-watir-for-functional-testing-in-web-applications/

class Watir::IE  
    def fire_keydown_on(element_id, key)  
        ie.Document.parentWindow.execScript("key = document.createEventObject(); key.keyCode = #{key}")  
        ie.Document.parentWindow.execScript("document.getElementById('#{element_id}').fireEvent('onkeydown', key)")  
    end  
end

ブログから:

要素 ID とキーを受け取る IE クラス用の新しいメソッド 'fire_keydown_on' を追加しました。このメソッドは、Javascript を呼び出してイベント オブジェクトを作成し (ちなみに、これは IE でのみ機能します)、キー コードをキャリッジ リターン キー (Enter キー) である '13' に設定します。Javascript を呼び出して (要素 ID を使用して) HTML 要素を取得し、作成したばかりのイベント オブジェクトを渡しながら、その上で「onkeydown」イベントを発生させます。

于 2009-03-03T14:55:02.497 に答える