Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6073505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:16:41+00:00 2026-05-23T10:16:41+00:00

I would like to specify a base URL so I don’t have to always

  • 0

I would like to specify a base URL so I don’t have to always specify absolute URLs. How can I specify a base URL for Mechanize to use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:16:42+00:00Added an answer on May 23, 2026 at 10:16 am

    To accomplish the previously proffered answer using Webrat, you can do the following e.g. in your Cucumber env.rb:

    require 'webrat'
    
    Webrat.configure do |config|
      config.mode = :mechanize
    end
    
    World do
      session = Webrat::Session.new
      session.extend(Webrat::Methods)
      session.extend(Webrat::Matchers)
      session.visit 'http://yoursite/yourbasepath/'
      session
    end
    

    To make it more robust, such as for use in different environments, you could do:

    ENV['CUCUMBER_HOST'] ||= 'yoursite'
    ENV['CUCUMBER_BASE_PATH'] ||= '/yourbasepath/'
    
    # Webrat
    require 'webrat'
    
    Webrat.configure do |config|
      config.mode = :mechanize
    end
    
    World do
      session = Webrat::Session.new
      session.extend(Webrat::Methods)
      session.extend(Webrat::Matchers)
      session.visit('http://' + ENV['CUCUMBER_HOST'] + ENV['CUCUMBER_BASE_PATH'])
      session
    end
    

    Note that if you’re using Mechanize, Webrat will also fail to follow your redirects because it won’t interpret the current host correctly. To work around this, you can add session.header('Host', ENV['CUCUMBER_HOST']) to the above.

    To make sure the right paths are being used everywhere for visiting and matching, add ENV['CUCUMBER_BASE_PATH'] + to the beginning of your paths_to method in paths.rb, if you use it. It should look like this:

      def path_to(page_name)
        ENV['CUCUMBER_BASE_PATH'] + 
    
        case page_name
    

    Apologies if anyone got a few e-mails from this — I originally tried to post as a comment and Stack Overflow’s irritating UI got the better of me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base class, with a method, where I would like to use
I have two classes that I would like to specify as follows: class Club
I would like to specify a constraint which is another type with a generic
I would like to specify JNDI name for an EJB3 bean using annotation, but
I'm using NUnit mocks and would like to specify that I expect a call
Is it possible to specify a condition in Count() ? I would like to
I'm building a custom provider and would like to know how to specify a
I would like to use output caching with WCF Data Services and although there's
I want to be able to specify a base url for all my routes
I would like to specify file paths using the JBoss provided substitutions, e.g. ${jboss.server.log.dir}.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.