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

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

Instance Method Summary (collapse)

Constructor Details

- (Browser) initialize(connection)



5
6
7
# File 'lib/capybara/driver/webkit/browser.rb', line 5

def initialize(connection)
  @connection = connection
end

Instance Method Details

- (Object) body



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

def body
  command("Body")
end

- (Object) clear_cookies



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

def clear_cookies
  command "ClearCookies"
end

- (Object) clear_proxy



121
122
123
# File 'lib/capybara/driver/webkit/browser.rb', line 121

def clear_proxy
  command("SetProxy")
end

- (Object) command(name, *args)



80
81
82
83
84
85
86
87
88
89
# File 'lib/capybara/driver/webkit/browser.rb', line 80

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

- (Object) console_messages



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

def console_messages
  command("ConsoleMessages").split("\n").map do |messages|
    parts = messages.split("|", 3)
    { :source => parts.first, :line_number => Integer(parts[1]), :message => parts.last }
  end
end

- (Object) current_url



62
63
64
# File 'lib/capybara/driver/webkit/browser.rb', line 62

def current_url
  command("CurrentUrl")
end

- (Object) error_messages



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

def error_messages
  console_messages.select do |message|
    message[:message] =~ /Error:/
  end
end

- (Object) evaluate_script(script)



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

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

- (Object) execute_script(script)



96
97
98
# File 'lib/capybara/driver/webkit/browser.rb', line 96

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

- (Object) find(query)



17
18
19
# File 'lib/capybara/driver/webkit/browser.rb', line 17

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

- (Object) frame_focus(frame_id_or_index = nil)



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

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

- (Object) get_cookies



112
113
114
# File 'lib/capybara/driver/webkit/browser.rb', line 112

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

- (Object) header(key, value)



13
14
15
# File 'lib/capybara/driver/webkit/browser.rb', line 13

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

- (Object) ignore_ssl_errors



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

def ignore_ssl_errors
  command("IgnoreSslErrors")
end

- (Object) render(path, width, height)



100
101
102
# File 'lib/capybara/driver/webkit/browser.rb', line 100

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

- (Object) requested_url



58
59
60
# File 'lib/capybara/driver/webkit/browser.rb', line 58

def requested_url
  command("RequestedUrl")
end

- (Object) reset!



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

def reset!
  command("Reset")
end

- (Object) resize_window(width, height)



125
126
127
# File 'lib/capybara/driver/webkit/browser.rb', line 125

def resize_window(width, height)
  command("ResizeWindow", width.to_i, height.to_i)
end

- (Object) response_headers



50
51
52
# File 'lib/capybara/driver/webkit/browser.rb', line 50

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


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

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

- (Object) set_proxy(options = {})



116
117
118
119
# File 'lib/capybara/driver/webkit/browser.rb', line 116

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

- (Object) source



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

def source
  command("Source")
end

- (Object) status_code



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

def status_code
  command("Status").to_i
end

- (Object) url



54
55
56
# File 'lib/capybara/driver/webkit/browser.rb', line 54

def url
  command("Url")
end

- (Object) visit(url)



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

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