README.md in poltergeist-1.4.1 vs README.md in poltergeist-1.5.0

- old
+ new

@@ -7,11 +7,11 @@ provided by [PhantomJS](http://www.phantomjs.org/). **If you're viewing this at https://github.com/jonleighton/poltergeist, you're reading the documentation for the master branch. [View documentation for the latest release -(1.4.1).](https://github.com/jonleighton/poltergeist/tree/v1.4.1)** +(1.5.0).](https://github.com/jonleighton/poltergeist/tree/v1.5.0)** ## Getting help ## Questions should be posted [on Stack Overflow, using the 'poltergeist' tag](http://stackoverflow.com/questions/tagged/poltergeist). @@ -41,30 +41,29 @@ ### Mac ### * *Homebrew*: `brew install phantomjs` * *MacPorts*: `sudo port install phantomjs` -* *Manual install*: [Download this](http://code.google.com/p/phantomjs/downloads/detail?name=phantomjs-1.8.1-macosx.zip&can=2&q=) +* *Manual install*: [Download this](http://phantomjs.googlecode.com/files/phantomjs-1.9.2-macosx.zip) ### Linux ### -* Download the [32 -bit](http://code.google.com/p/phantomjs/downloads/detail?name=phantomjs-1.8.1-linux-i686.tar.bz2&can=2&q=) -or [64 -bit](http://code.google.com/p/phantomjs/downloads/detail?name=phantomjs-1.8.1-linux-x86_64.tar.bz2&can=2&q=) +* Download the [32 bit](https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-i686.tar.bz2) +or [64 bit](https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-x86_64.tar.bz2) binary. * Extract the tarball and copy `bin/phantomjs` into your `PATH` ### Windows ### -* Download the [precompiled binary](http://phantomjs.org/download.html) for Windows +* Download the [precompiled binary](http://phantomjs.googlecode.com/files/phantomjs-1.9.2-windows.zip) +for Windows ### Manual compilation ### 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. -* Download [the source tarball](http://code.google.com/p/phantomjs/downloads/detail?name=phantomjs-1.8.1-source.zip&can=2&q=) +* Download [the source tarball](http://phantomjs.googlecode.com/files/phantomjs-1.9.2-source.zip) * Extract and cd in * `./build.sh` (See also the [PhantomJS building guide](http://phantomjs.org/build.html).) @@ -81,14 +80,11 @@ ## Running on a CI ## There are no special steps to take. You don't need Xvfb or any running X server at all. -[Travis CI](https://travis-ci.org/) has PhantomJS pre-installed, but it -might not be the latest version. If you need to install the latest -version, [check out the .travis.yml that Poltergeist -uses](https://github.com/jonleighton/poltergeist/blob/master/.travis.yml). +[Travis CI](https://travis-ci.org/) has PhantomJS pre-installed. 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 @@ -103,25 +99,30 @@ * `page.within_frame` * `page.within_window` * `page.status_code` * `page.response_headers` * `page.save_screenshot` -* `page.render_base64` -* `page.scroll_to` +* `page.driver.render_base64(format, options)` +* `page.driver.scroll_to(left, top)` +* `page.driver.basic_authorize(user, password)` +* `element.native.send_keys(*keys)` * cookie handling * drag-and-drop There are some additional features: ### Taking screenshots with some extensions ### You can grab screenshots of the page at any point by calling `save_screenshot('/path/to/file.png')` (this works the same way as the PhantomJS render feature, so you can specify other extensions like `.pdf`, `.gif`, etc.) +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) -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)`. +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)`. 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')`. @@ -196,10 +197,13 @@ 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. +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` ### Manipulating cookies ### The following methods are used to inspect and manipulate cookies: @@ -236,9 +240,28 @@ fill_in "pass", :with => "my_pass" click_button "Log In" end ``` +### 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) ## Customization ## You can customize the way that Capybara sets up Poltegeist via the following code in your test setup: