Class: Capybara::Webkit::Browser

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

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Browser

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

#accept_js_confirmsObject



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

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

#accept_js_promptsObject



128
129
130
# File 'lib/capybara/webkit/browser.rb', line 128

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

#alert_messagesObject



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

def alert_messages
  command("JavascriptAlertMessages").split("\n")
end

#authenticate(username, password) ⇒ Object



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

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

#bodyObject



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

def body
  command("Body")
end

#clear_cookiesObject



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

def clear_cookies
  command "ClearCookies"
end

#clear_prompt_textObject



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

def clear_prompt_text
  command("ClearPromptText")
end

#clear_proxyObject



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

def clear_proxy
  command("SetProxy")
end

#command(name, *args) ⇒ Object



144
145
146
147
148
149
150
151
152
153
# File 'lib/capybara/webkit/browser.rb', line 144

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

#confirm_messagesObject



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

def confirm_messages
  command("JavascriptConfirmMessages").split("\n")
end

#console_messagesObject



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

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

#current_urlObject



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

def current_url
  command("CurrentUrl")
end

#enable_loggingObject



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

def enable_logging
  command "EnableLogging"
end

#error_messagesObject



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

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

#evaluate_script(script) ⇒ Object



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

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

#execute_script(script) ⇒ Object



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

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

#find(query) ⇒ Object



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

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

#frame_focus(frame_id_or_index = nil) ⇒ Object



86
87
88
89
90
91
92
93
94
# File 'lib/capybara/webkit/browser.rb', line 86

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



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

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

#get_window_handleObject Also known as: window_handle



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

def get_window_handle
  command('GetWindowHandle')
end

#get_window_handlesObject Also known as: window_handles



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

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

#header(key, value) ⇒ Object



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

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

#ignore_ssl_errorsObject



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

def ignore_ssl_errors
  command("IgnoreSslErrors")
end

#prompt_messagesObject



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

def prompt_messages
  command("JavascriptPromptMessages").split("\n")
end

#reject_js_confirmsObject



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

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

#reject_js_promptsObject



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

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

#render(path, width, height) ⇒ Object



164
165
166
# File 'lib/capybara/webkit/browser.rb', line 164

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

#requested_urlObject



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

def requested_url
  command("RequestedUrl")
end

#reset!Object



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

def reset!
  command("Reset")
end

#resize_window(width, height) ⇒ Object



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

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

#response_headersObject



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

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


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

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

#set_prompt_text_to(string) ⇒ Object



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

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

#set_proxy(options = {}) ⇒ Object



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

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

#set_skip_image_loading(skip_image_loading) ⇒ Object



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

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

#sourceObject



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

def source
  command("Source")
end

#status_codeObject



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

def status_code
  command("Status").to_i
end

#timeoutObject



172
173
174
# File 'lib/capybara/webkit/browser.rb', line 172

def timeout
  command("GetTimeout").to_i
end

#timeout=(timeout_in_seconds) ⇒ Object



168
169
170
# File 'lib/capybara/webkit/browser.rb', line 168

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

#urlObject



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

def url
  command("Url")
end

#visit(url) ⇒ Object



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

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

#window_focus(selector) ⇒ Object



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

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