Capybara-mechanize

Forked from mobzilla/capybara-mechanize and modified to suit the needs of using capybara mechanize from behind a proxy or firewall.

Installation

gem install capybara-mechanize-with-proxy

Usage without Cucumber

require 'capybara/mechanize'

Usage with Cucumber and tags

A @mechanize tag is added to your hooks when you add the following line to your env.rb

require 'capybara/mechanize/cucumber'

The following scenario will then be using the Mechanize driver

@mechanize
Scenario: do something remote
  When I click the remote link

Remote testing

When you want to use this driver to test a remote application. You have to set the app_host:

Capybara.app_host = "http://www.yourapp.com"

Note that I haven't tested this case for my self yet. The Capybara tests pass for this situation though so it should work! Please provide me with feedback if it doesn't.

Mechanize using proxy

If you are behind a proxy, you can specify an PROXY=ON ENV variable on the command line and setup mechanize to use proxy or not as below:

Capybara.register_driver :mechanize do |app|
    Capybara.app_host = "http://www.yourapp.com"
    if ENV['PROXY'] == 'ON'
        Capybara::Mechanize::Driver.new(app,{:proxy =>"http://yourproxy.com"})
    else
        Capybara::Mechanize::Driver.new(app)
    end
end

Running tests

Until this library is merged with capybara there needs to be local app and you need to add the following to your host file:

127.0.0.1 capybara-testapp.heroku.com 

Run bundler

bundle install

Run the app with the following line:

bundle exec ruby -rrubygems lib/capybara/spec/extended_test_app.rb

Then you are ready to run the test like so

rake spec

Todo

  • Make the last 12 failing remote session spec pass, see remote_mechanize_spec and uncomment one line there to see them fail
  • Test this driver with non-rack/non-ruby projects

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright (c) 2010 Jeroen van Dijk. See LICENSE for details.