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



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

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

#accept_js_promptsObject



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

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

#alert_messagesObject



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

def alert_messages
  JSON.parse(command("JavascriptAlertMessages"))
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



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

def body
  command("Body")
end

#clear_cookiesObject



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

def clear_cookies
  command "ClearCookies"
end

#clear_prompt_textObject



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

def clear_prompt_text
  command("ClearPromptText")
end

#clear_proxyObject



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

def clear_proxy
  command("SetProxy")
end

#command(name, *args) ⇒ Object



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

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



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

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

#console_messagesObject



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

#current_urlObject



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

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



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

#evaluate_script(script) ⇒ Object



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

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

#execute_script(script) ⇒ Object



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

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

#find_css(query) ⇒ Object



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

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

#find_xpath(query) ⇒ Object



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

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

#frame_focus(selector = nil) ⇒ Object



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

#get_cookiesObject



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

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

#get_window_handleObject Also known as: window_handle



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

def get_window_handle
  command('GetWindowHandle')
end

#get_window_handlesObject Also known as: window_handles



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

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



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

def ignore_ssl_errors
  command("IgnoreSslErrors")
end

#prompt_messagesObject



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

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

#reject_js_confirmsObject



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

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

#reject_js_promptsObject



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

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

#render(path, width, height) ⇒ Object



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

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

#reset!Object



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

def reset!
  command("Reset")
end

#resize_window(width, height) ⇒ Object



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

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

#response_headersObject



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

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


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

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

#set_prompt_text_to(string) ⇒ Object



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

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

#set_proxy(options = {}) ⇒ Object



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

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



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

#status_codeObject



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

def status_code
  command("Status").to_i
end

#timeoutObject



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

def timeout
  command("GetTimeout").to_i
end

#timeout=(timeout_in_seconds) ⇒ Object



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

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

#titleObject



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

def title
  command("Title")
end

#url_blacklist=(black_list) ⇒ Object



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

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

#versionObject



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

def version
  command("Version")
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



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

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