Ruby autofill test (watir)

I am trying to create a watir test that fills the inn text field by writing feks

"lon" and until a drop-down list appears, then click on the first item in the list.

The spelling of "lon" should evoke many variations, such as "London, England, Storbritania", London, Kentucky, USA, etc. How is this possible with this? thnx in advance.

This is what my code looks like so far; these odes do not work, although I wonder where I missed something.

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 (' Oslo')

# 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

end

+3
1

(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

:

"fire_keydown_on" IE-, . Javascript (, , IE) key code "13", ( ). Javascript HTML ( ) onkeydown, .

+2

Source: https://habr.com/ru/post/1704065/


All Articles