@javascript黄瓜测试使用selenium驱动程序传递,但在使用poltergiest时失败

Mar*_*ffx 7 autocomplete cucumber capybara phantomjs poltergeist

我正在尝试测试jquery UI自动完成,我已经使用selenium驱动程序传递了测试.我想切换到poltergiest进行一些无头测试,但现在我的测试现在都失败了.

由于某种原因,我似乎没有选择自动完成选项

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
Run Code Online (Sandbox Code Playgroud)

测试通过使用Selenium驱动程序而不对步骤进行任何更改.

关于如何调试这个的任何建议?

  • selenium-webdriver(2.27.2)
  • 恶作剧者(1.0.2)
  • 黄瓜(1.2.1)
  • 黄瓜栏杆(1.0.6)
  • 水豚(1.1.4)
  • 幻影1.8.1

Mar*_*ffx 8

我已经设法搞清楚了,似乎capybara-poltergeist驱动程序不会触发jquery-ui用来显示下拉列表的任何事件.

我在这里找到答案:https://github.com/thoughtbot/capybara-webkit/issues/50

我在功能/支持中创建了一个表单助手

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)
Run Code Online (Sandbox Code Playgroud)

然后我使用这些方法填写表格并选择所需的选项.