我正在尝试测试 jquery UI 自动完成功能,我已经使用 selenium 驱动程序通过了测试。我想切换到 poltergiest 进行一些 headless 测试,但现在我的测试失败了。
由于某种我尚未弄清楚的原因,它似乎没有选择自动完成选项
步骤
When /^select contract$/ do
VCR.use_cassette("contract") do
selector =
'.ui-menu-item a:contains("John Smith (123456)")'
within("div#review") do
fill_in("contract", with: "john")
end
sleep 2
page.execute_script "$('#{selector}').trigger(\"mouseenter\").click();"
within("div#myPerformaceReview") do
find_field("contract").value.should ==
"John Smith (123456)"
end
end
end
测试通过使用 Selenium 驱动程序,而没有对步骤进行任何更改。
关于如何调试这个的任何建议?
版本
请您参考如下方法:
我设法弄清楚了,似乎 capybara -poltergeist 驱动程序不会触发 jquery-ui 用于显示下拉列表的任何事件。
我在这里找到了答案:https://github.com/thoughtbot/capybara-webkit/issues/50
我在 features/support 中创建了一个表单助手
module FormHelper
def fill_in_autocomplete(selector, value)
page.execute_script %Q{$('#{selector}').val('#{value}').keydown()}
end
def choose_autocomplete(text)
find('ul.ui-autocomplete').should have_content(text)
page.execute_script("$('.ui-menu-item:contains(\"#{text}\")').find('a').trigger('mouseenter').click()")
end
end
World(FormHelper)
然后我使用这些方法填写表格并选择所需的选项。