Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 198 lines (138 sloc) 8.264 kb
76fe32d @jonleighton omg
jonleighton authored
1 # Poltergeist - A PhantomJS driver for Capybara #
2
508cf9d @jonleighton Bump version
jonleighton authored
3 Version: 0.2.0
76fe32d @jonleighton omg
jonleighton authored
4
5 Poltergeist is a driver for [Capybara](https://github.com/jnicklas/capybara). It allows you to
6 run your Capybara tests on a headless [WebKit](http://webkit.org) browser,
7 provided by [PhantomJS](http://www.phantomjs.org/).
8
9 ## Installation ##
10
11 Add `poltergeist` to your Gemfile, and add in your test setup add:
12
13 require 'capybara/poltergeist'
14 Capybara.javascript_driver = :poltergeist
15
16 Currently PhantomJS is not 'truly headless', so to run it on a continuous integration
17 server you will need to use [Xvfb](http://en.wikipedia.org/wiki/Xvfb). You can either use the
18 [headless gem](https://github.com/leonid-shevtsov/headless) for this,
19 or make sure that Xvfb is running and the `DISPLAY` environment variable is set.
20
cf37abe @jonleighton Update the README
jonleighton authored
21 ## Installing PhantomJS ##
22
23 You need PhantomJS 1.4.1+, built against Qt 4.8, on your system.
24
25 ### Mac users ##
26
27 By far the easiest, most reliable thing to do is to [install the
28 pre-built static binary](http://code.google.com/p/phantomjs/downloads/detail?name=phantomjs-1.4.1-macosx-static-x86.zip&can=2&q=).
29 Try this first.
30
31 ### Linux users, or if the pre-built Mac binary doesn't work ###
32
33 You need to build PhantomJS manually. Unfortunately, this not
34 currently straightforward, for two reasons:
35
36 1. Using Poltergeist with PhantomJS built against Qt 4.7 causes
37 segfaults in WebKit's Javascript engine. Fortunately, this problem
38 doesn't occur under the recently released Qt 4.8. But if you don't
39 have Qt 4.8 on your system (check with `qmake --version`), you'll
40 need to build it.
41
42 2. A change in the version of WebKit bundled with Qt 4.8 means that in order
43 to be able to attach files to file `<input>` elements, we must apply
44 a patch to the Qt source tree that PhantomJS is built against.
45
46 So, you basically have two options:
47
48 1. **If you have Qt 4.8 on your system, and don't need to use file
49 inputs**, [follow the standard PhantomJS build instructions](http://code.google.com/p/phantomjs/wiki/BuildInstructions).
50
6c6e059 @joliss Fix PhantomJS build instructions for Linux
joliss authored
51 2. **Otherwise**, [download the PhantomJS tarball](http://code.google.com/p/phantomjs/downloads/detail?name=phantomjs-1.4.1-source.tar.gz&can=2&q=)
52 and run either `deploy/build-linux.sh --qt-4.8` or `cd deploy; ./build-mac.sh`.
cf37abe @jonleighton Update the README
jonleighton authored
53 The script will
54 download Qt, apply some patches, build it, and then build PhantomJS
55 against the patched build of Qt. It takes quite a while, around 30
56 minutes on a modern computer with two hyperthreaded cores. Afterwards,
57 you should copy the `bin/phantomjs` binary into your `PATH`.
58
59 PhantomJS 1.5 plans to bundle a stripped-down version of Qt, which will
60 reduce the build time a bit (although most of the time is spent building
61 WebKit) and make it easier to apply patches. When it is possible to make
62 static builds for Linux, those may be provided too, so most users will
63 avoid having to build it themselves.
64
76fe32d @jonleighton omg
jonleighton authored
65 ## What's supported? ##
66
67 Poltergeist supports basically everything that is supported by the stock Selenium driver,
68 including Javascript, drag-and-drop, etc.
69
b18225d @jonleighton Add a resize command to allow users to resize the browser window
jonleighton authored
70 There are some additional features:
71
72 ### Taking screenshots ###
73
74 You can grab screenshots of the page at any point by calling
76fe32d @jonleighton omg
jonleighton authored
75 `page.driver.render('/path/to/file.png')` (this works the same way as the PhantomJS
76 render feature, so you can specify other extensions like `.pdf`, `.gif`, etc.)
77
fb497cb @jonleighton Add support for choosing between rendering the whole page or just par…
jonleighton authored
78 By default, only the viewport will be rendered (the part of the page that is in view). To render
79 the entire page, use `page.driver.render('/path/to/file.png', :full => true)`.
80
b18225d @jonleighton Add a resize command to allow users to resize the browser window
jonleighton authored
81 ### Resizing the window ###
82
83 Sometimes the window size is important to how things are rendered. Poltergeist sets the window
84 size to 1024x768 by default, but you can set this yourself with `page.driver.resize(width, height)`.
85
76fe32d @jonleighton omg
jonleighton authored
86 ## Customization ##
87
88 You can customize the way that Capybara sets up Poltegeist via the following code in your
89 test setup:
90
91 Capybara.register_driver :poltergeist do |app|
92 Capybara::Poltergeist::Driver.new(app, options)
93 end
94
95 `options` is a hash of options. The following options are supported:
96
97 * `:phantomjs` (String) - A custom path to the phantomjs executable
98 * `:debug` (Boolean) - When true, debug output is logged to `STDERR`
99 * `:logger` (Object responding to `puts`) - When present, debug output is written to this object
34af795 @jonleighton Stop using EventMachine for WebSocket server.
jonleighton authored
100 * `:timeout` (Numeric) - The number of seconds we'll wait for a response
101 when communicating with PhantomJS. `nil` means wait forever. Default
102 is 10.
76fe32d @jonleighton omg
jonleighton authored
103
104 ## Bugs ##
105
106 Please file bug reports on Github and include example code to reproduce the problem wherever
cf37abe @jonleighton Update the README
jonleighton authored
107 possible. (Tests are even better.) Please also provide the output with
108 `:debug` turned on, and screenshots if you think it's relevant.
76fe32d @jonleighton omg
jonleighton authored
109
110 ## Why not use [capybara-webkit](https://github.com/thoughtbot/capybara-webkit)? ##
111
112 If capybara-webkit works for you, then by all means carry on using it.
113
114 However, I have had some trouble with it, and Poltergeist basically started
115 as an experiment to see whether a PhantomJS driver was possible. (It turned out it
cf37abe @jonleighton Update the README
jonleighton authored
116 was, but only thanks to some new features since the 1.3 release.)
76fe32d @jonleighton omg
jonleighton authored
117
118 In the long term, I think having a PhantomJS driver makes sense, because that allows
119 PhantomJS to concentrate on being an awesome headless browser, while the capybara driver
120 (Poltergeist) is able to be the minimal amount of glue code necessary to drive the
121 browser.
122
cf37abe @jonleighton Update the README
jonleighton authored
123 I also find it more pleasant to hack in CoffeeScript than C++,
124 particularly as my C++ experience only goes as far as trying to make
125 PhantomJS/Qt/WebKit work with Poltergeist :)
126
127 ## Hacking ##
128
129 Contributions are very welcome and I will happily give commit access to
130 anyone who does a few good pull requests.
131
132 To get setup, run `bundle install`. You can run the full test suite with
133 `rspec spec/` or `rake`.
134
135 I previously set up the repository on [Travis CI](http://travis-ci.org/)
136 but unfortunately given they need a custom-built Qt+PhantomJS in order
137 to pass, it can't be used for now. When static Linux PhantomJS builds
138 are working this can be revisited.
139
140 While PhantomJS is capable of compiling and running CoffeeScript code
141 directly, I prefer to compile the code myself and distribute that (it
142 makes debugging easier). Running `rake autocompile` will watch the
143 `.coffee` files for changes, and compile them into
144 `lib/capybara/client/compiled`.
145
8ab5c03 @jonleighton Fix #8
jonleighton authored
146 ## Changes ##
147
148 ### 0.3 (unreleased) ###
149
150 * There was a bad bug to do with clicking elements in a page where the
151 page is smaller than the window. The incorrect position would be
152 calculated, and so the click would happen in the wrong place. This is
153 fixed. [Issue #8]
154
34af795 @jonleighton Stop using EventMachine for WebSocket server.
jonleighton authored
155 * Poltergeist didn't work in conjunction with the Thin web server,
156 because that server uses Event Machine, and Poltergeist was assuming
157 that it was the only thing in the process using EventMachine.
158
159 To solve this, EventMachine usage has been completely removed, which
160 has the welcome side-effect of being more efficient because we
161 no longer have the overhead of running a mostly-idle event loop.
162
163 [Issue #6]
164
165 * Added the `:timeout` option to configure the timeout when talking to
166 PhantomJS.
167
8ab5c03 @jonleighton Fix #8
jonleighton authored
168 ### 0.2 ###
169
170 * First version considered 'ready', hopefully fewer problems.
171
172 ### 0.1 ###
173
174 * First version, various problems.
175
76fe32d @jonleighton omg
jonleighton authored
176 ## License ##
177
178 Copyright (c) 2011 Jonathan Leighton
179
180 Permission is hereby granted, free of charge, to any person obtaining
181 a copy of this software and associated documentation files (the
182 "Software"), to deal in the Software without restriction, including
183 without limitation the rights to use, copy, modify, merge, publish,
184 distribute, sublicense, and/or sell copies of the Software, and to
185 permit persons to whom the Software is furnished to do so, subject to
186 the following conditions:
187
188 The above copyright notice and this permission notice shall be
189 included in all copies or substantial portions of the Software.
190
191 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
192 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
193 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
194 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
195 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
196 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
197 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.