Class: Capybara::Driver::Webkit::Browser

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/driver/webkit/browser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Browser

Returns a new instance of Browser.



10
11
12
13
14
15
16
17
18
# File 'lib/capybara/driver/webkit/browser.rb', line 10

def initialize(options = {})
  @socket_class = options[:socket_class] || TCPSocket
  @stdout       = options.has_key?(:stdout) ?
                    options[:stdout] :
                    $stdout
  @ignore_ssl_errors = options[:ignore_ssl_errors]
  start_server
  connect
end

Instance Attribute Details

#server_portObject (readonly)

Returns the value of attribute server_port.



8
9
10
# File 'lib/capybara/driver/webkit/browser.rb', line 8

def server_port
  @server_port
end

Instance Method Details

#bodyObject



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

def body
  command("Body")
end

#clear_cookiesObject



94
95
96
# File 'lib/capybara/driver/webkit/browser.rb', line 94

def clear_cookies
  command "ClearCookies"
end

#clear_proxyObject



107
108
109
# File 'lib/capybara/driver/webkit/browser.rb', line 107

def clear_proxy
  command("SetProxy")
end

#command(name, *args) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/capybara/driver/webkit/browser.rb', line 66

def command(name, *args)
  @socket.puts name
  @socket.puts args.size
  args.each do |arg|
    @socket.puts arg.to_s.bytesize
    @socket.print arg.to_s
  end
  check
  read_response
end

#evaluate_script(script) ⇒ Object



77
78
79
80
# File 'lib/capybara/driver/webkit/browser.rb', line 77

def evaluate_script(script)
  json = command('Evaluate', script)
  JSON.parse("[#{json}]").first
end

#execute_script(script) ⇒ Object



82
83
84
# File 'lib/capybara/driver/webkit/browser.rb', line 82

def execute_script(script)
  command('Execute', script)
end

#find(query) ⇒ Object



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

def find(query)
  command("Find", query).split(",")
end

#frame_focus(frame_id_or_index = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/capybara/driver/webkit/browser.rb', line 56

def frame_focus(frame_id_or_index=nil)
  if frame_id_or_index.is_a? Fixnum
    command("FrameFocus", "", frame_id_or_index.to_s)
  elsif frame_id_or_index
    command("FrameFocus", frame_id_or_index)
  else
    command("FrameFocus")
  end
end

#get_cookiesObject



98
99
100
# File 'lib/capybara/driver/webkit/browser.rb', line 98

def get_cookies
  command("GetCookies").lines.map{ |line| line.strip }.select{ |line| !line.empty? }
end

#header(key, value) ⇒ Object



24
25
26
# File 'lib/capybara/driver/webkit/browser.rb', line 24

def header(key, value)
  command("Header", key, value)
end

#render(path, width, height) ⇒ Object



86
87
88
# File 'lib/capybara/driver/webkit/browser.rb', line 86

def render(path, width, height)
  command "Render", path, width, height
end

#reset!Object



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

def reset!
  command("Reset")
end

#response_headersObject



48
49
50
# File 'lib/capybara/driver/webkit/browser.rb', line 48

def response_headers
  Hash[command("Headers").split("\n").map { |header| header.split(": ") }]
end


90
91
92
# File 'lib/capybara/driver/webkit/browser.rb', line 90

def set_cookie(cookie)
  command "SetCookie", cookie
end

#set_proxy(options = {}) ⇒ Object



102
103
104
105
# File 'lib/capybara/driver/webkit/browser.rb', line 102

def set_proxy(options = {})
  options = default_proxy_options.merge(options)
  command("SetProxy", options[:type], options[:host], options[:port], options[:user], options[:pass])
end

#sourceObject



40
41
42
# File 'lib/capybara/driver/webkit/browser.rb', line 40

def source
  command("Source")
end

#status_codeObject



44
45
46
# File 'lib/capybara/driver/webkit/browser.rb', line 44

def status_code
  command("Status").to_i
end

#urlObject



52
53
54
# File 'lib/capybara/driver/webkit/browser.rb', line 52

def url
  command("Url")
end

#visit(url) ⇒ Object



20
21
22
# File 'lib/capybara/driver/webkit/browser.rb', line 20

def visit(url)
  command "Visit", url
end