Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara: NotSupportedByDriverError when trying to simulate pressing <ENTER>

I am writing a spec using Capybara to test the functionality of a search bar on my website. After following the instructions on this page on how to simulate pressing the Enter Key in Rspec/Capybara, I get the following error when I run my tests:

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

Am I doing something wrong? Here are the contents of my spec file:

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

I appreciate your assistance!

like image 577
Thalatta Avatar asked Aug 05 '13 23:08

Thalatta


1 Answers

Okay, so I didn't have the capybara-webkit installed and therefore I got the error that I did. Thank you!

like image 60
Thalatta Avatar answered Sep 24 '22 09:09

Thalatta