Class: Capybara::Mechanize::Browser

Inherits:
RackTest::Browser
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/capybara/mechanize/browser.rb

Defined Under Namespace

Classes: ResponseProxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver) ⇒ Browser

Returns a new instance of Browser.



14
15
16
17
18
19
# File 'lib/capybara/mechanize/browser.rb', line 14

def initialize(driver)
  @agent = ::Mechanize.new
  @agent.redirect_ok = false
  @agent.user_agent = default_user_agent
  super
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



93
94
95
# File 'lib/capybara/mechanize/browser.rb', line 93

def agent
  @agent
end

#errored_remote_responseObject (readonly)

Returns the value of attribute errored_remote_response.



93
94
95
# File 'lib/capybara/mechanize/browser.rb', line 93

def errored_remote_response
  @errored_remote_response
end

Instance Method Details

#current_urlObject



28
29
30
# File 'lib/capybara/mechanize/browser.rb', line 28

def current_url
  last_request_remote? ? remote_response.current_url : super
end

#find(format, selector) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/capybara/mechanize/browser.rb', line 85

def find(format, selector)
  if format == :css
    dom.css(selector, Capybara::RackTest::CSSHandlers.new)
  else
    dom.xpath(selector)
  end.map { |node| Capybara::Mechanize::Node.new(self, node) }
end

#last_requestObject



36
37
38
# File 'lib/capybara/mechanize/browser.rb', line 36

def last_request
  last_request_remote? ? OpenStruct.new(request_method: @last_method, params: @last_params, url: remote_response.current_url) : super
end

#last_responseObject



32
33
34
# File 'lib/capybara/mechanize/browser.rb', line 32

def last_response
  last_request_remote? ? remote_response : super
end

#refreshObject



62
63
64
65
66
67
68
69
# File 'lib/capybara/mechanize/browser.rb', line 62

def refresh
  if last_request_remote?
    process_remote_request(@last_method, @last_remote_uri.to_s, @last_params, @last_env)
  else
    register_local_request
    super
  end
end

#remote?(url) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/capybara/mechanize/browser.rb', line 71

def remote?(url)
  if Capybara.app_host
    true
  else
    host = URI.parse(url).host

    if host.nil?
      last_request_remote?
    else
      !Capybara::Mechanize.local_hosts.include?(host)
    end
  end
end

#reset_host!Object



21
22
23
24
25
26
# File 'lib/capybara/mechanize/browser.rb', line 21

def reset_host!
  @last_remote_uri = nil
  @last_request_remote = nil
  @errored_remote_response = nil
  super
end