Otaqui.Com

Pete Otaqui’s blog about web development and everything else

Using a Proxy with Cucumber, Webrat and Mechanize

one comment

If you’re writing Cucumber tests using Webrat and Mechanize to test a site, and you are behind a proxy server, you can do something like this to tell mechanize about it in your webrat_steps.rb file:


When /^I am on (.+)$/ do |page_name|
webrat.adapter.mechanize.set_proxy('proxy.host.com',8080)
visit path_to(page_name)
end

I’m sure there’s a tidier way to do this, but it’s quick and it works with the following gem versions:

Cucumber 0.3.11
Webrat 0.5.3
Mechanize 0.9.3

Written by pete

December 17th, 2009 at 4:15 pm

Posted in Professional

Tagged with , ,

One Response to 'Using a Proxy with Cucumber, Webrat and Mechanize'

Subscribe to comments with RSS or TrackBack to 'Using a Proxy with Cucumber, Webrat and Mechanize'.

  1. Hi, nice blog!

    You can also add this to your world so you need only set it once.

    class MechanizeWorld < Webrat::MechanizeSession

    def mechanize

    return @mechanize unless @mechanize.nil?

    @mechanize = Mechanize.new

    # Get proxy from http_porxy environment var
    if ENV['http_proxy'] != nil
    proxy = URI.parse(ENV['http_proxy'])
    @mechanize.set_proxy(proxy.host, proxy.port)
    end

    @mechanize

    end

    end

    World do
    MechanizeWorld.new
    end

    matth

    9 Jul 10 at 10:47 pm

Leave a Reply