用黄瓜测试 JQuery 自动完成 ui [英] Testing JQuery autocomplete ui with cucumber
本文介绍了用黄瓜测试 JQuery 自动完成 ui的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到了这个黄瓜场景:
I got this cucumber sceanario:
When I fill in "End User" with "john"
Then wait
Then wait
When I click "John Doe"
Then show me the page
步骤定义:
Then /^wait$/ do
sleep 2
end
When /^(?:|I )click "([^"]*)"$/ do |selector|
find(":contains('#{selector}')").click
end
它通过但没有选择用户.最终用户"等于显示页面"中的约翰".
It passes but it doesn't select a user."End User" equals "john" in 'show me the page'.
我什至无法让它在 javascript 控制台中工作.下面的代码没有选择任何东西.
I even can't get it to work in a javascript console. The following code does not select anything.
$(":contains('John Doe')").last().trigger('click')
# => [<a class="ui-corner-all" tabindex="-1"...
如何编写自动完成选择的脚本?无论是纯 JavaScript 还是黄瓜.
How can I script a autocomplete select? Be it in pure javascript or in cucumber.
推荐答案
试试看
When /^I type in "([^"]*)" into autocomplete list "([^"]*)" and I choose "([^"]*)"$/ do |typed, input_name,should_select|
page.driver.browser.execute_script %Q{ $('input[data-autocomplete]').trigger("focus") }
fill_in("#{input_name}",:with => typed)
page.driver.browser.execute_script %Q{ $('input[data-autocomplete]').trigger("keydown") }
sleep 1
page.driver.browser.execute_script %Q{ $('.ui-menu-item a:contains("#{should_select}")').trigger("mouseenter").trigger("click"); }
end
这样使用
And I type in "Foo" into autocomplete list "input_id" and I choose "Foobar"
这篇关于用黄瓜测试 JQuery 自动完成 ui的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文