我正在使用 Capybara 编写规范来测试我网站上搜索栏的功能。按照此页面上有关如何在 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
感谢您的帮助!