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.
gem install phantom_menaceYou have to run the phantomjs server first. This server accepts JSON commands.
phantomjs bin/phantom_menace.coffeeYou 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"]
endWhen the server is running, run the example by doing.
bundle exec ruby examples/simple.rbUnfortunately, we still don't have an automated test suite to run the different services.
We have to run three things.
- The
phantom_menacebinary
phantomjs bin/phantom_menace.coffee- 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