In the rspec function script, I have:
scenario 'shows things', js: true do page.find('#my_div').trigger(:click)
This is not like the jQuery handler fires the click event of this element. In the debugger, this call returns an empty string "".
If capybara-webkit can simulate mouse events using jQuery handlers that run ajax requests that update dom? If so, any suggestions on this case? I switched from selenium-webdriver because the capybara #trigger method is not supported.
And trying to fire a jQuery event directly throws an error:
page.execute_script "$('#masthead .fclass').trigger('click')"
gives
Capybara::Webkit::InvalidResponseError: Javascript failed to execute
In my gemfile there is
group :test do gem 'capybara' gem "database_cleaner", "~> 0.9.1" gem 'capybara-webkit', git: 'git://github.com/thoughtbot/capybara-webkit.git' gem 'launchy' end
I am using the 'edge' capybara-webkit, as I hit the error with xpath error otherwise (v2.04?).
I was not able to get the javascript error log, although I tried to add stack exceptions to spec / spec_helper.rb:
ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' require 'capybara/rspec' require 'rack/utils' Capybara.app = Rack::ShowExceptions.new(MyApp::Application)
Update: I replaced capybara-webkit with
gem 'poltergeist'
And in spec / spec_helper.rb:
require 'capybara/poltergeist' ... Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new(app, { debug: true }) end Capybara.javascript_driver = :poltergeist Capybara.current_driver = :poltergeist
I get these console error messages from the page ("# my_id"). trigger ('click'):
... {"name"=>"click", "args"=>[3, 2]} poltergeist [1366370900594] state default -> mouse_event poltergeist [1366370900596] state mouse_event -> loading Not allowed to load local resource: file:///home/me/rails/my_app/public/assets_test/application.css ... Not allowed to load local resource: file:///home/me/rails/my_app/public/assets_test/application.js
I tried chmod poltergeist permissions, but the same result.
And trying to run page.execute_script (% Q ($ ("my_id"). Trigger ('click'))) gives an error like jQuery undefined:
ReferenceError: Can't find variable: $ at phantomjs: