Class: Capybara::Webkit::Browser

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

Instance Method Summary (collapse)

Constructor Details

- (Browser) initialize(connection)

Returns a new instance of Browser



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

def initialize(connection)
  @connection = connection
end

Instance Method Details

- (Object) accept_js_confirms



137
138
139
# File 'lib/capybara/webkit/browser.rb', line 137

def accept_js_confirms
  command("SetConfirmAction", "Yes")
end

- (Object) accept_js_prompts



145
146
147
# File 'lib/capybara/webkit/browser.rb', line 145

def accept_js_prompts
  command("SetPromptAction", "Yes")
end

- (Object) alert_messages



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

def alert_messages
  JSON.parse(command("JavascriptAlertMessages"))
end

- (Object) authenticate(username, password)



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

def authenticate(username, password)
  command("Authenticate", username, password)
end

- (Object) body



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

def body
  command("Body")
end

- (Object) clear_cookies



201
202
203
# File 'lib/capybara/webkit/browser.rb', line 201

def clear_cookies
  command "ClearCookies"
end

- (Object) clear_prompt_text



157
158
159
# File 'lib/capybara/webkit/browser.rb', line 157

def clear_prompt_text
  command("ClearPromptText")
end

- (Object) clear_proxy



214
215
216
# File 'lib/capybara/webkit/browser.rb', line 214

def clear_proxy
  command("SetProxy")
end

- (Object) command(name, *args)



165
166
167
168
169
170
171
172
173
174
# File 'lib/capybara/webkit/browser.rb', line 165

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) confirm_messages



65
66
67
# File 'lib/capybara/webkit/browser.rb', line 65

def confirm_messages
  JSON.parse(command("JavascriptConfirmMessages"))
end

- (Object) console_messages



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

def console_messages
  JSON.parse(command("ConsoleMessages")).map do |message|
    message.inject({}) { |m,(k,v)| m.merge(k.to_sym => v) }
  end
end

- (Object) current_url



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

def current_url
  command("CurrentUrl")
end

- (Object) enable_logging



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

def enable_logging
  command "EnableLogging"
end

- (Object) error_messages



55
56
57
58
59
# File 'lib/capybara/webkit/browser.rb', line 55

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

- (Object) evaluate_script(script)



176
177
178
179
# File 'lib/capybara/webkit/browser.rb', line 176

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

- (Object) execute_script(script)



181
182
183
# File 'lib/capybara/webkit/browser.rb', line 181

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

- (Object) find_css(query)



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

def find_css(query)
  command("FindCss", query).split(",")
end

- (Object) find_xpath(query)



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

def find_xpath(query)
  command("FindXpath", query).split(",")
end

- (Object) frame_focus(selector = nil)



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

def frame_focus(selector=nil)
  if selector.respond_to?(:base)
    selector.base.invoke('focus')
  elsif selector.is_a? Fixnum
    command("FrameFocus", "", selector.to_s)
  elsif selector
    command("FrameFocus", selector)
  else
    command("FrameFocus")
  end
end

- (Object) get_cookies



205
206
207
# File 'lib/capybara/webkit/browser.rb', line 205

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

- (Object) get_window_handle Also known as: window_handle



131
132
133
# File 'lib/capybara/webkit/browser.rb', line 131

def get_window_handle
  command('GetWindowHandle')
end

- (Object) get_window_handles Also known as: window_handles



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

def get_window_handles
  JSON.parse(command('GetWindowHandles'))
end

- (Object) go_back



222
223
224
# File 'lib/capybara/webkit/browser.rb', line 222

def go_back
  command("GoBack")
end

- (Object) go_forward



226
227
228
# File 'lib/capybara/webkit/browser.rb', line 226

def go_forward
  command("GoForward")
end

- (Object) header(key, value)



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

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

- (Object) ignore_ssl_errors



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

def ignore_ssl_errors
  command("IgnoreSslErrors")
end

- (Object) prompt_messages



69
70
71
# File 'lib/capybara/webkit/browser.rb', line 69

def prompt_messages
  JSON.parse(command("JavascriptPromptMessages"))
end

- (Object) reject_js_confirms



141
142
143
# File 'lib/capybara/webkit/browser.rb', line 141

def reject_js_confirms
  command("SetConfirmAction", "No")
end

- (Object) reject_js_prompts



149
150
151
# File 'lib/capybara/webkit/browser.rb', line 149

def reject_js_prompts
  command("SetPromptAction", "No")
end

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



185
186
187
# File 'lib/capybara/webkit/browser.rb', line 185

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

- (Object) reset!



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

def reset!
  command("Reset")
end

- (Object) response_headers



73
74
75
# File 'lib/capybara/webkit/browser.rb', line 73

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


197
198
199
# File 'lib/capybara/webkit/browser.rb', line 197

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

- (Object) set_prompt_text_to(string)



153
154
155
# File 'lib/capybara/webkit/browser.rb', line 153

def set_prompt_text_to(string)
  command("SetPromptText", string)
end

- (Object) set_proxy(options = {})



209
210
211
212
# File 'lib/capybara/webkit/browser.rb', line 209

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

- (Object) set_skip_image_loading(skip_image_loading)



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

def set_skip_image_loading(skip_image_loading)
  command("SetSkipImageLoading", skip_image_loading)
end

- (Object) status_code



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

def status_code
  command("Status").to_i
end

- (Object) timeout



193
194
195
# File 'lib/capybara/webkit/browser.rb', line 193

def timeout
  command("GetTimeout").to_i
end

- (Object) timeout=(timeout_in_seconds)



189
190
191
# File 'lib/capybara/webkit/browser.rb', line 189

def timeout=(timeout_in_seconds)
  command "SetTimeout", timeout_in_seconds
end

- (Object) title



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

def title
  command("Title")
end

- (Object) url_blacklist=(black_list)



161
162
163
# File 'lib/capybara/webkit/browser.rb', line 161

def url_blacklist=(black_list)
  command("SetUrlBlacklist", *Array(black_list))
end

- (Object) version



218
219
220
# File 'lib/capybara/webkit/browser.rb', line 218

def version
  command("Version")
end

- (Object) visit(url)



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

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

- (Object) window_close(selector)



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

def window_close(selector)
  command("WindowClose", selector)
end

- (Object) window_focus(selector)



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

def window_focus(selector)
  command("WindowFocus", selector)
end

- (Object) window_maximize(handle)



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

def window_maximize(handle)
  command("WindowMaximize", handle)
end

- (Object) window_open



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

def window_open
  command("WindowOpen")
end

- (Object) window_resize(handle, width, height)



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

def window_resize(handle, width, height)
  command("WindowResize", handle, width.to_i, height.to_i)
end

- (Object) window_size(handle)



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

def window_size(handle)
  JSON.parse(command("WindowSize", handle))
end