Class: Capybara::Mechanize::Driver

Inherits:
Object
  • Object
show all
Defined in:
lib/kimurai/capybara_ext/mechanize/driver.rb

Instance Method Summary collapse

Instance Method Details

#add_header(name, value) ⇒ Object


23
24
25
# File 'lib/kimurai/capybara_ext/mechanize/driver.rb', line 23

def add_header(name, value)
  browser.agent.request_headers[name] = value
end

#clear_cookiesObject


47
48
49
# File 'lib/kimurai/capybara_ext/mechanize/driver.rb', line 47

def clear_cookies
  browser.agent.cookie_jar.clear!
end

#current_memoryObject

Reset parent method `current_memory` for mechanize (we can't measure memory of Mechanize driver)


60
61
62
# File 'lib/kimurai/capybara_ext/mechanize/driver.rb', line 60

def current_memory
  nil
end

#get_cookiesObject


29
30
31
# File 'lib/kimurai/capybara_ext/mechanize/driver.rb', line 29

def get_cookies
  browser.agent.cookies
end

#headersObject


15
16
17
# File 'lib/kimurai/capybara_ext/mechanize/driver.rb', line 15

def headers
  browser.agent.request_headers
end

#headers=(headers) ⇒ Object


19
20
21
# File 'lib/kimurai/capybara_ext/mechanize/driver.rb', line 19

def headers=(headers)
  browser.agent.request_headers = headers
end

#pidObject


64
65
66
# File 'lib/kimurai/capybara_ext/mechanize/driver.rb', line 64

def pid
  nil
end

#portObject


68
69
70
# File 'lib/kimurai/capybara_ext/mechanize/driver.rb', line 68

def port
  nil
end

#quitObject


53
54
55
# File 'lib/kimurai/capybara_ext/mechanize/driver.rb', line 53

def quit
  browser.agent.shutdown
end

33
34
35
36
37
38
39
# File 'lib/kimurai/capybara_ext/mechanize/driver.rb', line 33

def set_cookie(name, value, options = {})
  options[:name]  ||= name
  options[:value] ||= value

  cookie = Mechanize::Cookie.new(options.merge path: "/")
  browser.agent.cookie_jar << cookie
end

#set_cookies(cookies) ⇒ Object


41
42
43
44
45
# File 'lib/kimurai/capybara_ext/mechanize/driver.rb', line 41

def set_cookies(cookies)
  cookies.each do |cookie|
    set_cookie(cookie[:name], cookie[:value], cookie)
  end
end

#set_proxy(ip, port, type, user = nil, password = nil) ⇒ Object

Extend capybara-mechnize to support Poltergeist-like methods www.rubydoc.info/gems/poltergeist/Capybara/Poltergeist/Driver


8
9
10
11
# File 'lib/kimurai/capybara_ext/mechanize/driver.rb', line 8

def set_proxy(ip, port, type, user = nil, password = nil)
  # type is always "http", "socks" is not supported (yet)
  browser.agent.set_proxy(ip, port, user, password)
end