【问题标题】:Capybara: NotSupportedByDriverError when trying to simulate pressing <ENTER>Capybara:尝试模拟按 <ENTER> 时出现 NotSupportedByDriverError
【发布时间】:2013-08-06 19:32:12
【问题描述】:

我正在使用 Capybara 编写规范来测试我网站上搜索栏的功能。按照page 上关于如何在 Rspec/Capybara 中模拟按下 Enter 键的说明后,我在运行测试时收到以下错误:

 Failure/Error: page.driver.execute_script(keypress)
 Capybara::NotSupportedByDriverError:
   Capybara::Driver::Base#execute_script

我做错了吗?以下是我的规范文件的内容:

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 gem!
  • 如果有人在使用 Poltergeis 作为 Capybara 驱动程序时对此有答案,我将不胜感激 :)
  • 我的 gemfile 中有 gem,我做了 bundle 但它也不起作用
  • 哦,我忘了, js: true
  • 我安装了 js: true 和 capybara-webkit,但在我所有尝试调用 evaluate_script 时仍然看到这一点。这方面还有其他线索吗?我所有的谷歌搜索都把我带到了死胡同,比如这个 SO 页面。

标签: ruby-on-rails rspec capybara


【解决方案1】:

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

【讨论】:

  • capybara-webkit 的开发已暂停。您应该使用 Selenium 或 Apparition 驱动程序。
猜你喜欢
  • 2021-02-11
  • 2019-08-30
  • 2021-01-18
  • 1970-01-01
  • 1970-01-01
  • 2011-06-27
  • 2019-10-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多