Method: Frameworks::EnvHelper#setup_mechanize

Defined in:
lib/frameworks/cucumber.rb

#setup_mechanize(agent, http_proxy = nil) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/frameworks/cucumber.rb', line 102

def setup_mechanize(agent, http_proxy=nil)
  http_proxy = http_proxy || ENV['HTTP_PROXY'] || ENV['http_proxy']

  if ENV['FW_CERT_LOCATION']
    agent.cert, agent.key = ENV['FW_CERT_LOCATION'], ENV['FW_CERT_LOCATION'] 
  end

  agent.ca_file = ENV['CA_CERT_LOCATION'] if ENV['CA_CERT_LOCATION']
  agent.set_proxy(http_proxy.scan(/http:\/\/(.*):80/)[0][0].to_s,80) if http_proxy && !http_proxy.empty?

  # The above proxy setting ignores any no_proxy variable setting:
  # added the following to circumvent this
  if(http_proxy)
    no_proxy = ENV['NO_PROXY'] || ENV['no_proxy']
    if(no_proxy)
      # The no_proxy query string argument must not contain spaces
      no_proxy_qs = no_proxy.gsub(/[, ]+/,',')
      agent.agent.http.proxy = URI(http_proxy + '?no_proxy=' + no_proxy_qs)
    end
  end

  #This is necessary because Mech2 does not ship with root certs like Mech1 did and boxes may not have the OpenSSL set installed
  agent.verify_mode = OpenSSL::SSL::VERIFY_NONE

  # This prevents Mechanize from raising a Mechanize::ResponseCodeError
  # when the HTTP Response Code is 404 or 503. This lets capybara continue the journey.
  agent.agent.allowed_error_codes = ['404', '503']
end