我试图通过编写feks来创建watir测试来填充文本字段
“Lon”并等待下拉被触发,然后单击列表中的第一个元素。
写作“Lon”应该触发许多选项,如“伦敦,英国,SturbistaNi”,伦敦,肯塔基,美国等。
和沃特在一起有可能吗??
提前通知。
这就是我的代码现在的样子,
但它不起作用,我想知道我错过了什么。
定义测试脚本飞行自动完成
@站点。导航到(:travel,:flight)
from_field=@site.ie.text_字段(:id,“locoriginname”)
to_field=@site.ie.text_字段(: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
结束
最佳答案
我和一位同事(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
来自博客:
我们刚刚为ie类添加了一个新方法fire_keydown_on,它接受元素id和键。这个方法调用javascript来创建一个事件对象(顺便说一句,这只在ie中有效),并将键代码设置为'13',这是回车键(enter键)。它调用javascript获取html元素(使用元素id)并对其触发“onkeydown”事件,同时传递刚创建的事件对象。