``` Important Notice This repo has rewrote its history and as such is not compatible with the main Akephalos repo. Further development will be done here. You can get the unaltered pristine copy at: [https://github.com/Nerian/akephalos](https://github.com/Nerian/akephalos) The reason why its history was rewrote was to remove .jar vendor files that were making its size huge. ``` # Akephalos Akephalos is a full-stack headless browser for integration testing with Capybara. It is built on top of [HtmlUnit](http://htmlunit.sourceforge.net), a GUI-less browser for the Java platform, but can be run on both JRuby and MRI with no need for JRuby to be installed on the system. ## Installation ``` ruby gem install akephalos # Official gem ``` Or ``` ruby gem 'akephalos', :git => 'git://github.com/Nerian/akephalos.git' ``` # Development ``` bash git clone https://github.com/Nerian/akephalos2 git submodule update --init ``` The last line will grab the HTMLUnit jar files from [https://github.com/Nerian/html-unit-vendor](https://github.com/Nerian/html-unit-vendor) ## Setup Configuring akephalos is as simple as requiring it and setting Capybara's javascript driver: ``` ruby require 'akephalos' Capybara.javascript_driver = :akephalos ``` ## Basic Usage Akephalos provides a driver for Capybara, so using Akephalos is no different than using Selenium or Rack::Test. For a full usage guide, check out Capybara's DSL [documentation](http://github.com/jnicklas/capybara). It makes no assumptions about the testing framework being used, and works with RSpec, Cucumber, and Test::Unit. Here's some sample RSpec code: ``` ruby describe "Home Page" do before { visit "/" } context "searching" do before do fill_in "Search", :with => "akephalos" click_button "Go" end it "returns results" { page.should have_css("#results") } it "includes the search term" { page.should have_content("akephalos") } end end ``` ## Configuration There are now a few configuration options available through Capybara's new `register_driver` API. ### Configuring the max memory that Java Virtual Machine can use The max memory that the JVM is going to use can be set using an environment variable in your spec_helper or .bashrc file. ``` ruby ENV['akephalos_jvm_max_memory'] ``` The default value is 256 MB. If you use akephalos's bin the parameter `-m [memory]` sets the max memory for the JVM. ``` bash $ akephalos -m 670 ``` ### Using a different browser HtmlUnit supports a few browser implementations, and you can choose which browser you would like to use through Akephalos. By default, Akephalos uses Firefox 3.6. ``` ruby Capybara.register_driver :akephalos do |app| # available options: # :ie6, :ie7, :ie8, :firefox_3, :firefox_3_6 Capybara::Driver::Akephalos.new(app, :browser => :ie8) end ``` ### Using a Proxy Server ``` ruby Capybara.register_driver :akephalos do |app| Capybara::Driver::Akephalos.new(app, :http_proxy => 'myproxy.com', :http_proxy_port => 8080) end ``` ### Ignoring javascript errors By default HtmlUnit (and Akephalos) will raise an exception when an error is encountered in javascript files. This is generally desirable, except that certain libraries aren't supported by HtmlUnit. If possible, it's best to keep the default behaviour, and use Filters (see below) to mock offending libraries. If needed, however, you can configure Akephalos to ignore javascript errors. ``` ruby Capybara.register_driver :akephalos do |app| Capybara::Driver::Akephalos.new(app, :validate_scripts => false) end ``` ### Setting the HtmlUnit log level By default it uses the 'fatal' level. You can change that like this: ``` ruby Capybara.register_driver :akephalos do |app| # available options # "trace", "debug", "info", "warn", "error", or "fatal" Capybara::Driver::Akephalos.new(app, :htmlunit_log_level => 'fatal') end ``` ### Running Akephalos with Spork ``` ruby Spork.prefork do ... Akephalos::RemoteClient.manager end Spork.each_run do ... Thread.current['DRb'] = { 'server' => DRb::DRbServer.new } end ``` More info at : [sporking-with-akephalos](http://spacevatican.org/2011/7/3/sporking-with-akephalos) ### Filters Akephalos allows you to filter requests originating from the browser and return mock responses. This will let you easily filter requests for external resources when running your tests, such as Facebook's API and Google Analytics. Configuring filters in Akephalos should be familiar to anyone who has used FakeWeb or a similar library. The simplest filter requires only an HTTP method (:get, :post, :put, :delete, :any) and a string or regex to match against. ``` ruby Akephalos.filter(:get, "http://www.google.com") Akephalos.filter(:any, %r{^http://(api\.)?twitter\.com/.*$}) ``` By default, all filtered requests will return an empty body with a 200 status code. You can change this by passing additional options to your filter call. ``` ruby Akephalos.filter(:get, "http://google.com/missing", :status => 404, :body => "...