2011-10-27 23:34:14 +01:00
|
|
|
# Poltergeist - A PhantomJS driver for Capybara #
|
|
|
|
|
2014-04-04 14:47:52 -06:00
|
|
|
[](http://travis-ci.org/teampoltergeist/poltergeist)
|
2012-01-13 15:28:13 +00:00
|
|
|
|
2011-10-27 23:34:14 +01:00
|
|
|
Poltergeist is a driver for [Capybara](https://github.com/jnicklas/capybara). It allows you to
|
|
|
|
run your Capybara tests on a headless [WebKit](http://webkit.org) browser,
|
2015-03-05 10:52:35 +01:00
|
|
|
provided by [PhantomJS](http://phantomjs.org/).
|
2011-10-27 23:34:14 +01:00
|
|
|
|
2014-05-01 12:02:42 -04:00
|
|
|
**If you're viewing this at https://github.com/teampoltergeist/poltergeist,
|
2013-01-28 13:44:03 +00:00
|
|
|
you're reading the documentation for the master branch.
|
|
|
|
[View documentation for the latest release
|
2016-02-09 16:39:59 -05:00
|
|
|
(1.9.0).](https://github.com/teampoltergeist/poltergeist/tree/v1.9.0)**
|
2013-01-28 13:44:03 +00:00
|
|
|
|
2013-02-25 19:22:27 +00:00
|
|
|
## Getting help ##
|
|
|
|
|
|
|
|
Questions should be posted [on Stack
|
|
|
|
Overflow, using the 'poltergeist' tag](http://stackoverflow.com/questions/tagged/poltergeist).
|
|
|
|
|
|
|
|
Bug reports should be posted [on
|
2014-05-01 12:02:42 -04:00
|
|
|
GitHub](https://github.com/teampoltergeist/poltergeist/issues) (and be sure
|
2013-02-25 19:22:27 +00:00
|
|
|
to read the bug reporting guidance below).
|
|
|
|
|
2011-10-27 23:34:14 +01:00
|
|
|
## Installation ##
|
|
|
|
|
2015-12-01 18:24:40 -03:00
|
|
|
Add this line to your Gemfile and run `bundle install`:
|
|
|
|
|
|
|
|
``` ruby
|
|
|
|
gem 'poltergeist'
|
|
|
|
```
|
|
|
|
|
|
|
|
In your test setup add:
|
2011-10-27 23:34:14 +01:00
|
|
|
|
2012-02-18 12:03:37 +00:00
|
|
|
``` ruby
|
|
|
|
require 'capybara/poltergeist'
|
|
|
|
Capybara.javascript_driver = :poltergeist
|
|
|
|
```
|
|
|
|
|
2012-07-02 23:41:23 +01:00
|
|
|
If you were previously using the `:rack_test` driver, be aware that
|
|
|
|
your app will now run in a separate thread and this can have
|
|
|
|
consequences for transactional tests. [See the Capybara README for more
|
|
|
|
detail](https://github.com/jnicklas/capybara/blob/master/README.md#transactions-and-database-setup).
|
|
|
|
|
2012-01-03 20:04:37 +00:00
|
|
|
## Installing PhantomJS ##
|
|
|
|
|
2012-12-04 15:11:27 +01:00
|
|
|
You need at least PhantomJS 1.8.1. There are *no other external
|
2012-10-07 17:21:51 +01:00
|
|
|
dependencies* (you don't need Qt, or a running X server, etc.)
|
2012-06-22 00:53:49 +02:00
|
|
|
|
2012-04-09 21:47:38 +01:00
|
|
|
### Mac ###
|
2012-01-13 15:40:42 +00:00
|
|
|
|
2012-07-24 23:05:50 +01:00
|
|
|
* *Homebrew*: `brew install phantomjs`
|
2013-01-01 16:43:28 +05:30
|
|
|
* *MacPorts*: `sudo port install phantomjs`
|
2015-07-06 09:04:29 +02:00
|
|
|
* *Manual install*: [Download this](https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-macosx.zip)
|
2012-01-13 15:40:42 +00:00
|
|
|
|
2012-04-09 21:47:38 +01:00
|
|
|
### Linux ###
|
2012-01-03 20:04:37 +00:00
|
|
|
|
2015-07-06 09:04:29 +02:00
|
|
|
* Download the [32 bit](https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-i686.tar.bz2)
|
|
|
|
or [64 bit](https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2)
|
2012-04-09 21:47:38 +01:00
|
|
|
binary.
|
2012-10-07 17:05:07 +01:00
|
|
|
* Extract the tarball and copy `bin/phantomjs` into your `PATH`
|
2012-01-03 20:04:37 +00:00
|
|
|
|
2013-02-01 11:28:40 -06:00
|
|
|
### Windows ###
|
2015-07-06 09:04:29 +02:00
|
|
|
* Download the [precompiled binary](https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-windows.zip)
|
2013-10-03 19:38:34 +04:00
|
|
|
for Windows
|
2013-02-01 11:28:40 -06:00
|
|
|
|
2012-04-09 21:47:38 +01:00
|
|
|
### Manual compilation ###
|
2012-01-03 20:04:37 +00:00
|
|
|
|
2012-04-09 21:47:38 +01:00
|
|
|
Do this as a last resort if the binaries don't work for you. It will
|
|
|
|
take quite a long time as it has to build WebKit.
|
|
|
|
|
2015-07-06 09:04:29 +02:00
|
|
|
* Download [the source tarball](https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-source.zip)
|
2012-04-09 21:47:38 +01:00
|
|
|
* Extract and cd in
|
|
|
|
* `./build.sh`
|
2012-01-13 15:40:42 +00:00
|
|
|
|
2012-10-07 17:05:07 +01:00
|
|
|
(See also the [PhantomJS building
|
|
|
|
guide](http://phantomjs.org/build.html).)
|
2012-03-20 17:54:27 +00:00
|
|
|
|
2012-10-07 17:05:07 +01:00
|
|
|
## Compatibility ##
|
2012-03-20 17:54:27 +00:00
|
|
|
|
2013-02-01 11:28:40 -06:00
|
|
|
Poltergeist runs on MRI 1.9, JRuby 1.9 and Rubinius 1.9. Poltergeist
|
|
|
|
and PhantomJS are currently supported on Mac OS X, Linux, and Windows
|
|
|
|
platforms.
|
2012-03-20 17:54:27 +00:00
|
|
|
|
2013-01-26 13:15:13 +00:00
|
|
|
Ruby 1.8 is no longer supported. The last release to support Ruby 1.8
|
|
|
|
was 1.0.2, so you should use that if you still need Ruby 1.8 support.
|
2012-03-20 17:54:27 +00:00
|
|
|
|
2012-01-13 15:40:42 +00:00
|
|
|
## Running on a CI ##
|
|
|
|
|
2012-04-09 21:47:38 +01:00
|
|
|
There are no special steps to take. You don't need Xvfb or any running X
|
|
|
|
server at all.
|
2012-01-03 20:04:37 +00:00
|
|
|
|
2015-12-01 18:24:40 -03:00
|
|
|
[Travis CI](https://travis-ci.org/) and [Codeship](https://codeship.com/) has PhantomJS pre-installed.
|
2012-10-07 17:05:07 +01:00
|
|
|
|
2012-04-15 21:03:16 +02:00
|
|
|
Depending on your tests, one thing that you may need is some fonts. If
|
|
|
|
you're getting errors on a CI that don't occur during development then
|
|
|
|
try taking some screenshots - it may well be missing fonts throwing
|
|
|
|
things off kilter. Your distro will have various font packages available
|
|
|
|
to install.
|
2012-01-03 20:04:37 +00:00
|
|
|
|
2011-10-27 23:34:14 +01:00
|
|
|
## What's supported? ##
|
|
|
|
|
2012-10-07 12:40:11 +01:00
|
|
|
Poltergeist supports all the mandatory features for a Capybara driver,
|
|
|
|
and the following optional features:
|
|
|
|
|
|
|
|
* `page.evaluate_script` and `page.execute_script`
|
|
|
|
* `page.within_frame`
|
|
|
|
* `page.status_code`
|
|
|
|
* `page.response_headers`
|
2013-02-28 02:35:00 +09:00
|
|
|
* `page.save_screenshot`
|
2013-10-10 15:37:28 +04:00
|
|
|
* `page.driver.render_base64(format, options)`
|
|
|
|
* `page.driver.scroll_to(left, top)`
|
|
|
|
* `page.driver.basic_authorize(user, password)`
|
2013-12-01 21:41:41 +04:00
|
|
|
* `element.native.send_keys(*keys)`
|
2016-03-11 18:05:42 +03:00
|
|
|
* `page.driver.set_proxy(ip, port, type, user, password)`
|
2014-09-03 18:59:40 +04:00
|
|
|
* window API
|
2012-10-07 12:40:11 +01:00
|
|
|
* cookie handling
|
|
|
|
* drag-and-drop
|
2011-10-27 23:34:14 +01:00
|
|
|
|
2011-10-31 22:23:52 +00:00
|
|
|
There are some additional features:
|
|
|
|
|
2013-02-28 02:35:00 +09:00
|
|
|
### Taking screenshots with some extensions ###
|
2011-10-31 22:23:52 +00:00
|
|
|
|
|
|
|
You can grab screenshots of the page at any point by calling
|
2013-02-28 02:35:00 +09:00
|
|
|
`save_screenshot('/path/to/file.png')` (this works the same way as the PhantomJS
|
2011-10-27 23:34:14 +01:00
|
|
|
render feature, so you can specify other extensions like `.pdf`, `.gif`, etc.)
|
2013-10-11 19:10:48 +04:00
|
|
|
Just in case you render pdf it's might be worth to set `driver.paper_size=` with
|
|
|
|
settings provided by PhantomJS in [here](https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#wiki-webpage-paperSize)
|
2011-10-27 23:34:14 +01:00
|
|
|
|
2013-10-11 19:10:48 +04:00
|
|
|
By default, only the viewport will be rendered (the part of the page that is in
|
|
|
|
view). To render the entire page, use `save_screenshot('/path/to/file.png',
|
|
|
|
:full => true)`.
|
2011-10-31 23:04:02 +00:00
|
|
|
|
2013-08-31 16:29:17 +04:00
|
|
|
You also have an ability to render selected element. Pass option `selector` with
|
|
|
|
any valid element selector to make a screenshot bounded by that element
|
|
|
|
`save_screenshot('/path/to/file.png', :selector => '#id')`.
|
|
|
|
|
2013-08-25 20:49:32 -07:00
|
|
|
If you need for some reasons base64 encoded screenshot you can simply call
|
|
|
|
`render_base64` that will return you encoded image. Additional options are the
|
|
|
|
same as for `save_screenshot` except the first argument which is format (:png by
|
|
|
|
default, acceptable :png, :gif, :jpeg).
|
|
|
|
|
2012-10-08 13:57:31 -07:00
|
|
|
### Clicking precise coordinates ###
|
|
|
|
|
|
|
|
Sometimes its desirable to click a very specific area of the screen. You can accomplish this with
|
|
|
|
`page.driver.click(x, y)`, where x and y are the screen coordinates.
|
|
|
|
|
2012-04-09 21:47:38 +01:00
|
|
|
### Remote debugging (experimental) ###
|
|
|
|
|
|
|
|
If you use the `:inspector => true` option (see below), remote debugging
|
|
|
|
will be enabled.
|
|
|
|
|
|
|
|
When this option is enabled, you can insert `page.driver.debug` into
|
|
|
|
your tests to pause the test and launch a browser which gives you the
|
|
|
|
WebKit inspector to view your test run with.
|
|
|
|
|
2013-03-23 15:01:59 +01:00
|
|
|
You can register this debugger driver with a different name and set it
|
|
|
|
as the current javascript driver. By example, in your helper file:
|
2013-03-22 21:16:48 +01:00
|
|
|
|
|
|
|
```ruby
|
|
|
|
Capybara.register_driver :poltergeist_debug do |app|
|
|
|
|
Capybara::Poltergeist::Driver.new(app, :inspector => true)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Capybara.javascript_driver = :poltergeist
|
|
|
|
Capybara.javascript_driver = :poltergeist_debug
|
|
|
|
```
|
|
|
|
|
2012-04-15 21:03:16 +02:00
|
|
|
[Read more
|
|
|
|
here](http://jonathanleighton.com/articles/2012/poltergeist-0-6-0/)
|
|
|
|
|
2013-07-17 15:53:51 +04:00
|
|
|
### Manipulating request headers ###
|
2012-07-03 00:32:23 +02:00
|
|
|
|
2013-07-17 15:53:51 +04:00
|
|
|
You can manipulate HTTP request headers with these methods:
|
2012-07-03 00:32:23 +02:00
|
|
|
|
|
|
|
``` ruby
|
2013-07-17 15:53:51 +04:00
|
|
|
page.driver.headers # => {}
|
2012-10-06 22:56:51 +01:00
|
|
|
page.driver.headers = { "User-Agent" => "Poltergeist" }
|
2013-07-17 15:53:51 +04:00
|
|
|
page.driver.add_headers("Referer" => "https://example.com")
|
|
|
|
page.driver.headers # => { "User-Agent" => "Poltergeist", "Referer" => "https://example.com" }
|
2012-07-03 00:32:23 +02:00
|
|
|
```
|
2012-07-03 00:01:48 +01:00
|
|
|
|
2013-07-17 15:53:51 +04:00
|
|
|
Notice that `headers=` will overwrite already set headers. You should use
|
2013-07-25 14:13:07 +04:00
|
|
|
`add_headers` if you want to add a few more. These headers will apply to all
|
2013-07-17 15:53:51 +04:00
|
|
|
subsequent HTTP requests (including requests for assets, AJAX, etc). They will
|
2013-07-25 14:13:07 +04:00
|
|
|
be automatically cleared at the end of the test. You have ability to set headers
|
|
|
|
only for the initial request:
|
|
|
|
|
|
|
|
``` ruby
|
|
|
|
page.driver.headers = { "User-Agent" => "Poltergeist" }
|
|
|
|
page.driver.add_header("Referer", "http://example.com", permanent: false)
|
|
|
|
page.driver.headers # => { "User-Agent" => "Poltergeist", "Referer" => "http://example.com" }
|
|
|
|
visit(login_path)
|
|
|
|
page.driver.headers # => { "User-Agent" => "Poltergeist" }
|
|
|
|
```
|
|
|
|
|
|
|
|
This way your temporary headers will be sent only for the initial request, all
|
|
|
|
subsequent request will only contain your permanent headers.
|
2012-07-03 00:32:23 +02:00
|
|
|
|
2012-07-03 00:01:48 +01:00
|
|
|
### Inspecting network traffic ###
|
|
|
|
|
|
|
|
You can inspect the network traffic (i.e. what resources have been
|
|
|
|
loaded) on the current page by calling `page.driver.network_traffic`.
|
|
|
|
This returns an array of request objects. A request object has a
|
|
|
|
`response_parts` method containing data about the response chunks.
|
2013-10-10 14:00:28 +11:00
|
|
|
Please note that network traffic is not cleared when you visit new page.
|
|
|
|
You can manually clear the network traffic by calling `page.driver.clear_network_traffic`
|
|
|
|
or `page.driver.reset`
|
2012-07-03 00:01:48 +01:00
|
|
|
|
2012-10-06 22:56:51 +01:00
|
|
|
### Manipulating cookies ###
|
|
|
|
|
|
|
|
The following methods are used to inspect and manipulate cookies:
|
|
|
|
|
|
|
|
* `page.driver.cookies` - a hash of cookies accessible to the current
|
|
|
|
page. The keys are cookie names. The values are `Cookie` objects, with
|
|
|
|
the following methods: `name`, `value`, `domain`, `path`, `secure?`,
|
|
|
|
`httponly?`, `expires`.
|
|
|
|
* `page.driver.set_cookie(name, value, options = {})` - set a cookie.
|
|
|
|
The options hash can take the following keys: `:domain`, `:path`,
|
|
|
|
`:secure`, `:httponly`, `:expires`. `:expires` should be a `Time`
|
|
|
|
object.
|
|
|
|
* `page.driver.remove_cookie(name)` - remove a cookie
|
2014-11-27 09:20:56 +03:00
|
|
|
* `page.driver.clear_cookies` - clear all cookies
|
2012-10-06 22:56:51 +01:00
|
|
|
|
2013-12-01 21:41:41 +04:00
|
|
|
### Sending keys ###
|
|
|
|
|
|
|
|
There's an ability to send arbitrary keys to the element:
|
|
|
|
|
|
|
|
``` ruby
|
|
|
|
element = find('input#id')
|
|
|
|
element.native.send_key('String')
|
|
|
|
```
|
|
|
|
|
|
|
|
or even more complicated:
|
|
|
|
|
|
|
|
``` ruby
|
|
|
|
element.native.send_keys('H', 'elo', :Left, 'l') # => 'Hello'
|
|
|
|
element.native.send_key(:Enter) # triggers Enter key
|
|
|
|
```
|
|
|
|
Since it's implemented natively in PhantomJS this will exactly imitate user
|
|
|
|
behavior.
|
|
|
|
See more about [sendEvent](http://phantomjs.org/api/webpage/method/send-event.html) and
|
|
|
|
[PhantomJS keys](https://github.com/ariya/phantomjs/commit/cab2635e66d74b7e665c44400b8b20a8f225153a)
|
2013-06-25 14:21:52 -07:00
|
|
|
|
2011-10-27 23:34:14 +01:00
|
|
|
## Customization ##
|
|
|
|
|
2015-05-23 19:06:09 -04:00
|
|
|
You can customize the way that Capybara sets up Poltergeist via the following code in your
|
2011-10-27 23:34:14 +01:00
|
|
|
test setup:
|
|
|
|
|
2012-02-18 12:03:37 +00:00
|
|
|
``` ruby
|
|
|
|
Capybara.register_driver :poltergeist do |app|
|
|
|
|
Capybara::Poltergeist::Driver.new(app, options)
|
|
|
|
end
|
|
|
|
```
|
2011-10-27 23:34:14 +01:00
|
|
|
|
|
|
|
`options` is a hash of options. The following options are supported:
|
|
|
|
|
2012-02-18 12:03:37 +00:00
|
|
|
* `:phantomjs` (String) - A custom path to the phantomjs executable
|
2013-01-31 21:45:10 +00:00
|
|
|
* `:debug` (Boolean) - When true, debug output is logged to `STDERR`.
|
|
|
|
Some debug info from the PhantomJS portion of Poltergeist is also
|
|
|
|
output, but this goes to `STDOUT` due to technical limitations.
|
2012-02-18 12:03:37 +00:00
|
|
|
* `:logger` (Object responding to `puts`) - When present, debug output is written to this object
|
2013-01-27 10:03:05 +00:00
|
|
|
* `:phantomjs_logger` (`IO` object) - Where the `STDOUT` from PhantomJS is written to. This is
|
2013-07-20 16:35:33 +04:00
|
|
|
where your `console.log` statements will show up. Default: `STDOUT`
|
2012-02-18 12:03:37 +00:00
|
|
|
* `:timeout` (Numeric) - The number of seconds we'll wait for a response
|
2012-12-08 20:58:18 +00:00
|
|
|
when communicating with PhantomJS. Default is 30.
|
2012-04-09 21:47:38 +01:00
|
|
|
* `:inspector` (Boolean, String) - See 'Remote Debugging', above.
|
2016-02-17 20:17:44 +09:00
|
|
|
* `:js_errors` (Boolean) - When false, JavaScript errors do not get re-raised in Ruby.
|
2012-06-04 15:38:55 +02:00
|
|
|
* `:window_size` (Array) - The dimensions of the browser window in which to test, expressed
|
|
|
|
as a 2-element array, e.g. [1024, 768]. Default: [1024, 768]
|
2014-11-13 11:26:33 -05:00
|
|
|
* `:phantomjs_options` (Array) - Additional [command line options](http://phantomjs.org/api/command-line.html)
|
2012-07-11 20:31:29 +01:00
|
|
|
to be passed to PhantomJS, e.g. `['--load-images=no', '--ignore-ssl-errors=yes']`
|
2012-11-01 12:32:40 +00:00
|
|
|
* `:extensions` (Array) - An array of JS files to be preloaded into
|
|
|
|
the phantomjs browser. Useful for faking unsupported APIs.
|
2012-10-06 16:57:46 +01:00
|
|
|
* `:port` (Fixnum) - The port which should be used to communicate
|
2014-04-12 17:02:58 -04:00
|
|
|
with the PhantomJS process. Defaults to a random open port.
|
2011-10-27 23:34:14 +01:00
|
|
|
|
2016-04-10 15:19:21 +10:00
|
|
|
### URL Blacklisting & Whitelisting ###
|
2015-02-12 14:34:47 -05:00
|
|
|
|
2016-04-10 15:19:21 +10:00
|
|
|
Poltergeist supports URL blacklisting, which allows you
|
|
|
|
to prevent scripts from running on designated domains:
|
2015-02-12 14:34:47 -05:00
|
|
|
|
|
|
|
```ruby
|
|
|
|
page.driver.browser.url_blacklist = ['http://www.example.com']
|
|
|
|
```
|
|
|
|
|
2016-04-10 15:19:21 +10:00
|
|
|
and also URL whitelisting, which allows scripts to only run
|
|
|
|
on designated domains:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
page.driver.browser.url_whitelist = ['http://www.example.com']
|
|
|
|
```
|
|
|
|
|
|
|
|
If you are experiencing slower run times, consider creating a
|
|
|
|
URL whitelist of domains that are essential or a blacklist of
|
|
|
|
domains that are not essential, such as ad networks or analytics,
|
|
|
|
to your testing environment.
|
|
|
|
|
2015-02-12 14:34:47 -05:00
|
|
|
Make sure you set it before each running test, because this setting's cleaned
|
|
|
|
up when capybara does reset.
|
|
|
|
|
2012-10-07 17:05:07 +01:00
|
|
|
## Troubleshooting ##
|
|
|
|
|
|
|
|
Unfortunately, the nature of full-stack testing is that things can and
|
|
|
|
do go wrong from time to time. This section aims to highlight a number
|
|
|
|
of common problems and provide ideas about how you can work around them.
|
|
|
|
|
|
|
|
### DeadClient errors ###
|
|
|
|
|
|
|
|
Sometimes PhantomJS crashes during a test. There are basically two kinds
|
|
|
|
of crashes: those that can be reproduced every time, and those that
|
|
|
|
occur sporadically and are not easily reproduced.
|
|
|
|
|
|
|
|
If your crash happens every time, you should read the [PhantomJS crash
|
|
|
|
reporting
|
2014-05-20 14:09:23 +04:00
|
|
|
guide](http://phantomjs.org/crash-reporting.html) and file
|
2012-10-07 17:05:07 +01:00
|
|
|
a bug against PhantomJS. Feel free to also file a bug against
|
|
|
|
Poltergeist in case there are workarounds that can be implemented within
|
|
|
|
Poltergeist. Also, if lots of Poltergeist users are experiencing the
|
2012-10-07 17:45:23 +01:00
|
|
|
same crash then fixing it will move up the priority list.
|
2012-10-07 17:05:07 +01:00
|
|
|
|
|
|
|
If your crash is sporadic, there is less that can be done. Often these
|
|
|
|
issues are very complicated and difficult to track down. It may be that
|
|
|
|
the crash has already been fixed in a newer version of WebKit that will
|
|
|
|
eventually find its way into PhantomJS. It's still worth reporting your
|
2012-10-07 17:45:23 +01:00
|
|
|
bug against PhantomJS, but it's probably not worth filing a bug against
|
2012-10-07 17:05:07 +01:00
|
|
|
Poltergeist as there's not much we can do.
|
|
|
|
|
2012-10-07 17:45:23 +01:00
|
|
|
If you experience sporadic crashes a lot, it may be worth configuring
|
2012-10-07 17:05:07 +01:00
|
|
|
your CI to automatically re-run failing tests before reporting a failed
|
|
|
|
build.
|
|
|
|
|
2013-03-03 15:18:05 +00:00
|
|
|
### MouseEventFailed errors ###
|
2012-10-07 17:05:07 +01:00
|
|
|
|
|
|
|
When Poltergeist clicks on an element, rather than generating a DOM
|
|
|
|
click event, it actually generates a "proper" click. This is much closer
|
|
|
|
to what happens when a real user clicks on the page - but it means that
|
|
|
|
Poltergeist must scroll the page to where the element is, and work out
|
2012-10-07 17:45:23 +01:00
|
|
|
the correct co-ordinates to click. If the element is covered up by
|
2012-10-07 17:05:07 +01:00
|
|
|
another element, the click will fail (this is a good thing - because
|
|
|
|
your user won't be able to click a covered up element either).
|
|
|
|
|
|
|
|
Sometimes there can be issues with this behavior. If you have problems,
|
|
|
|
it's worth taking screenshots of the page and trying to work out what's
|
|
|
|
going on. If your click is failing, but you're not getting a
|
2013-03-03 15:18:05 +00:00
|
|
|
`MouseEventFailed` error, then you can turn on the `:debug` option and look
|
2012-10-07 17:05:07 +01:00
|
|
|
in the output to see what co-ordinates Poltergeist is using for the
|
|
|
|
click. You can then cross-reference this with a screenshot to see if
|
|
|
|
something is obviously wrong.
|
|
|
|
|
2012-10-07 17:45:23 +01:00
|
|
|
If you can't figure out what's going on and just want to work around the
|
|
|
|
problem so you can get on with life, consider using a DOM click
|
|
|
|
event. For example, if this code is failing:
|
2012-10-07 17:05:07 +01:00
|
|
|
|
|
|
|
``` ruby
|
|
|
|
click_button "Save"
|
|
|
|
```
|
2011-10-27 23:34:14 +01:00
|
|
|
|
2012-10-07 17:05:07 +01:00
|
|
|
Then try:
|
2011-10-27 23:34:14 +01:00
|
|
|
|
2012-10-07 17:05:07 +01:00
|
|
|
``` ruby
|
|
|
|
find_button("Save").trigger('click')
|
|
|
|
```
|
2012-01-03 20:04:37 +00:00
|
|
|
|
2012-10-07 17:05:07 +01:00
|
|
|
### Timing problems ###
|
|
|
|
|
|
|
|
Sometimes tests pass and fail sporadically. This is often because there
|
|
|
|
is some problem synchronising events properly. It's often
|
|
|
|
straightforward to verify this by adding `sleep` statements into your
|
|
|
|
test to allow sufficient time for the page to settle.
|
|
|
|
|
|
|
|
If you have these types of problems, read through the [Capybara
|
2012-10-07 17:45:23 +01:00
|
|
|
documentation on asynchronous
|
2016-02-17 20:17:44 +09:00
|
|
|
JavaScript](https://github.com/jnicklas/capybara#asynchronous-javascript-ajax-and-friends)
|
2012-10-07 17:05:07 +01:00
|
|
|
which explains the tools that Capybara provides for dealing with this.
|
|
|
|
|
2013-07-26 11:29:28 +04:00
|
|
|
### Memory leak ###
|
|
|
|
|
|
|
|
If you run a few capybara sessions manually please make sure you've called
|
|
|
|
`session.driver.quit` when you don't need session anymore. Forgetting about this
|
|
|
|
causes memory leakage and your system's resources can be exhausted earlier than
|
|
|
|
you may expect.
|
|
|
|
|
2012-10-07 17:05:07 +01:00
|
|
|
### General troubleshooting hints ###
|
|
|
|
|
|
|
|
* Configure Poltergeist with `:debug` turned on so you can see its
|
|
|
|
communication with PhantomJS.
|
|
|
|
* Take screenshots to figure out what the state of your page is when the
|
|
|
|
problem occurs.
|
2012-10-07 22:02:59 +01:00
|
|
|
* Use the remote web inspector in case it provides any useful insight
|
2012-10-07 17:05:07 +01:00
|
|
|
* Consider downloading the Poltergeist source and using `console.log`
|
|
|
|
debugging to figure out what's going on inside PhantomJS. (This will
|
|
|
|
require an understanding of the Poltergeist source code and PhantomJS,
|
|
|
|
so it's only for the committed!)
|
|
|
|
|
|
|
|
### Filing a bug ###
|
|
|
|
|
|
|
|
If you can provide specific steps to reproduce your problem, or have
|
|
|
|
specific information that might help other help you track down the
|
|
|
|
problem, then please file a bug on Github.
|
|
|
|
|
2012-10-07 17:45:23 +01:00
|
|
|
Include as much information as possible. For example:
|
2012-10-07 17:05:07 +01:00
|
|
|
|
|
|
|
* Specific steps to reproduce where possible (failing tests are even
|
|
|
|
better)
|
2012-10-07 17:45:23 +01:00
|
|
|
* The output obtained from running Poltergeist with `:debug` turned on
|
|
|
|
* Screenshots
|
2016-02-17 20:17:44 +09:00
|
|
|
* Stack traces if there are any Ruby on JavaScript exceptions generated
|
2012-10-07 17:45:23 +01:00
|
|
|
* The Poltergeist and PhantomJS version numbers used
|
|
|
|
* The operating system name and version used
|
2012-10-07 17:05:07 +01:00
|
|
|
|
2012-01-11 22:16:35 +00:00
|
|
|
## Changes ##
|
|
|
|
|
2013-08-14 00:55:21 +04:00
|
|
|
Version history and a list of next-release features and fixes can be found in
|
|
|
|
the [changelog](CHANGELOG.md).
|
2012-01-11 22:16:35 +00:00
|
|
|
|
2011-10-27 23:34:14 +01:00
|
|
|
## License ##
|
|
|
|
|
2015-04-02 20:24:45 +13:00
|
|
|
Copyright (c) 2011-2015 Jonathan Leighton
|
2011-10-27 23:34:14 +01:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
a copy of this software and associated documentation files (the
|
|
|
|
"Software"), to deal in the Software without restriction, including
|
|
|
|
without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be
|
|
|
|
included in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|