ruby-on-rails – Capybara:尝试模拟按下时的NotSupportedByDriverError

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Capybara:尝试模拟按下时的NotSupportedByDriverError前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用Capybara编写一个规范来测试我网站上搜索栏的功能.按照本 page上有关如何模拟按Rspec / Capybara中的Enter键的说明操作后,运行测试时出现以下错误
Failure/Error: page.driver.execute_script(keypress)
 Capybara::NotSupportedByDriverError:
   Capybara::Driver::Base#execute_script

难道我做错了什么?以下是我的spec文件内容

require 'spec_helper'

describe 'Search' do
  it 'displays no results when non-existent things are looked up'   do

  visit root_path

  page.first(".search-icon-small").click

  fill_in "search",with: "NonExistent"

  #simulate pressing Enter
  keypress ="var e = $.Event('keydown',{ keyCode: 13 }); $('body').trigger(e);"
  page.driver.execute_script(keypress)

  page.should have_content('No Results')
  end

  it 'displays content that exists' do
    #Clients
    client = Client.new
    client.name = 'Gerard Leskovar'
    client.save!

    visit root_path


    page.first(".search-icon-small").click

    fill_in "search",with: "Leskovar"

    keypress ="var e = $.Event('keydown',{ keyCode: 13 }); $('body').trigger(e);"
    page.driver.execute_script(keypress)

    page.should have_content('Gerard Leskovar')

  end
end

感谢您的协助!

解决方法

好的,所以我没有安装capybara-webkit,因此我收到了错误.谢谢!

猜你在找的Ruby相关文章