Need help with capybara-mechanize?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

jeroenvandijk
206 Stars 54 Forks MIT License 196 Commits 7 Opened issues

Description

RackTest driver for Capybara with remote request support

Services available

!
?

Need anything else?

Contributors list

# 230,684
Clojure...
Clojure
C++
error-m...
78 commits
# 47,101
Ruby
Objecti...
Vue.js
migrate
39 commits
# 46,507
Ruby
sidekiq
activem...
Rails
21 commits
# 11,111
Ruby
seleniu...
.NET
Rails
5 commits
# 46,774
Ruby
Shell
Rails
activem...
5 commits
# 11,693
Ruby
Lisp
pypi
GitHub
4 commits
# 28,999
Ruby
Elixir
Shell
rubygem...
2 commits
# 45,009
Ruby
Shell
windows...
apns2
2 commits
# 672,216
Ruby
2 commits
# 22,521
Ruby
Elixir
Rails
Sass
2 commits
# 33,006
Ruby
Webpack
jQuery
React
2 commits
# 375,950
Ruby
Shell
R
2 commits
# 74,256
cloudfl...
Rails
passwor...
feature...
1 commit
# 207,040
Shell
TeX
R
dissert...
1 commit
# 136,476
Ruby
CSS
jQuery
ruby-on...
1 commit
# 356,839
Shell
Scala
Clojure
dcos
1 commit
# 91,600
Ruby
Rails
jQuery
CSS
1 commit

Capybara-mechanize

Build Status

This gems makes it possible to use Capybara for (partially) remote testing. It inherits most functionality from the RackTest driver and only uses Mechanize for remote requests.

It is currently in use to test the integration between a Rails application and Twitter authorization and sharing.

This gem is a Capybara extension. I have been inspired by the Capybara driver and some earlier efforts for a Mechanize driver.

Thanks to Pinkelstar for giving me the time and the need to develop this gem.

Installation

gem install capybara-mechanize

Usage without Cucumber

require 'capybara/mechanize'

Further configuration of Mechanize

Upon instantiation of a

Driver
, you can configure
mechanize
agent options
in a
#configure
block:
Capybara.register_driver :mechanize do |app|
  driver = Capybara::Mechanize::Driver.new(app)
  driver.configure do |agent|
    # Configure other Mechanize options here.
    agent.log = Logger.new "mech.log"
    agent.user_agent_alias = 'Mac Safari'
  end
  driver
end

Usage without rack app

You can configure it to use for external servers. Until this issue https://github.com/jeroenvandijk/capybara-mechanize/issues/66 is resolved, you can configure with

Capybara.register_driver :mechanize do |app|
  Capybara::Mechanize::Driver.new(proc {})
end
and use like this
session = Capybara::Session.new :mechanize
session.visit 'https://github.com'

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.

HTTP errors

If you receive the error

Net::HTTP::Persistent::Error: too many connection resets
, try setting a timeout value:
page.driver.browser.agent.idle_timeout = 0.4
.

Running tests

Run bundler

bundle install

Then you are ready to run the test like so

bundle exec rake spec

Todo

  • 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

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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.