phantom_menace
A real headless "browser." It uses phantomjs and provides an API like a real browser does. Much like poltergeist but decoupled from capybara.
At the heart of phantom-menace is a run loop inside the phantomjs script that makes it synchronous.
It is perfect for scraping or doing any browser related tasks.
Install
gem install phantom_menace
Getting Started
You have to run the phantomjs server first. This server accepts JSON commands.
phantom_menace
You can then run a quick example:
require "phantom_menace"
browser = PhantomMenace::Browser.new
browser.goto "http://facebook.com"
links = browser.find_all_links
links.each do |link|
link.attributes["href"]
end
Running The Example
When the server is running, run the example by doing.
bundle exec ruby examples/simple.rb
Running The Tests
Unfortunately, we still don't have an automated test suite to run the different services.
We have to run three things.
- The
phantom_menacebinary
bundle exec ./bin/phantom_menace
- The sinatra test server - This serves the files needed for the tests instead of hitting third party sites. This ensures that we can run the tests without internet.
bundle exec ruby ./spec/test_server/server.rb
- Finally we can run the specs
bundle exec rake spec