From 3692dcb96ce954a9df883d7c229f4ab31ec02da2 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 25 Feb 2013 13:19:44 -0500 Subject: [PATCH] add poltergeist dom_click support --- README.md | 10 +++++++++- skel/root/features/support/drivers.rb | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ad9d9a6..775f9e7 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ I normally do things: gem 'bintz-integration_testing_setup', :git => 'git://github.com/johnbintz/bintz-integration_testing_setup.git' ``` -`bundle install`, then run `bundle exec bints-integration_testing_setup`. It's best to do this on a pristine +`bundle install`, then run `bundle exec bintz-integration_testing_setup`. It's best to do this on a pristine project, but it may work on one that already has some stuff in it. ## Gem setup @@ -369,6 +369,14 @@ end * Testing using external services, like [Feed Validator](http://feedvalidator.org/): Force the application to start up by `visit`ing a safe page that doesn't do anything, or is wrapped by a VCR call. Then build the URL to give to the remote service using `Capybara.app_host`, like you would with `Rack::Test`. +* Sometimes Poltergeist and PhantomJS don't click the right element. This is due to the WebKit renderer being + silly sometimes. If you're having intermittent problems with a `click` on an element, use `dom_click` instead: + + ``` ruby + find_submit.dom_click + ``` + + This will use a DOM click in drivers that support DOM event firing, and a regular `click` on other browsers (like Selenium). ## Writing less better organized code diff --git a/skel/root/features/support/drivers.rb b/skel/root/features/support/drivers.rb index 8137913..08c6fcc 100644 --- a/skel/root/features/support/drivers.rb +++ b/skel/root/features/support/drivers.rb @@ -9,3 +9,16 @@ require 'persistent_selenium/driver' # you can override the driver with the DRIVER environment variable ENV['DRIVER'] ||= 'persistent_selenium' +# if PhantomJS is having problems clicking something, use dom_click +class Capybara::Node::Element + def dom_click + synchronize do + begin + trigger('click') + rescue NotImplementedError, Capybara::NotSupportedByDriverError + click + end + end + end +end +