Class: Capybara::Driver::Webkit::Browser
- Inherits:
-
Object
- Object
- Capybara::Driver::Webkit::Browser
- Defined in:
- lib/capybara/driver/webkit/browser.rb
Instance Attribute Summary collapse
-
#server_port ⇒ Object
readonly
Returns the value of attribute server_port.
Instance Method Summary collapse
- #body ⇒ Object
- #clear_cookies ⇒ Object
- #clear_proxy ⇒ Object
- #command(name, *args) ⇒ Object
- #evaluate_script(script) ⇒ Object
- #execute_script(script) ⇒ Object
- #find(query) ⇒ Object
- #frame_focus(frame_id_or_index = nil) ⇒ Object
- #get_cookies ⇒ Object
- #header(key, value) ⇒ Object
-
#initialize(options = {}) ⇒ Browser
constructor
A new instance of Browser.
- #render(path, width, height) ⇒ Object
- #reset! ⇒ Object
- #response_headers ⇒ Object
- #set_cookie(cookie) ⇒ Object
- #set_proxy(options = {}) ⇒ Object
- #source ⇒ Object
- #status_code ⇒ Object
- #url ⇒ Object
- #visit(url) ⇒ Object
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( = {}) @socket_class = [:socket_class] || TCPSocket @stdout = .has_key?(:stdout) ? [:stdout] : $stdout @ignore_ssl_errors = [:ignore_ssl_errors] start_server connect end |
Instance Attribute Details
#server_port ⇒ Object (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
#body ⇒ Object
36 37 38 |
# File 'lib/capybara/driver/webkit/browser.rb', line 36 def body command("Body") end |
#clear_cookies ⇒ Object
94 95 96 |
# File 'lib/capybara/driver/webkit/browser.rb', line 94 def command "ClearCookies" end |
#clear_proxy ⇒ Object
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_cookies ⇒ Object
98 99 100 |
# File 'lib/capybara/driver/webkit/browser.rb', line 98 def 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_headers ⇒ Object
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 |
#set_cookie(cookie) ⇒ Object
90 91 92 |
# File 'lib/capybara/driver/webkit/browser.rb', line 90 def () command "SetCookie", end |
#set_proxy(options = {}) ⇒ Object
102 103 104 105 |
# File 'lib/capybara/driver/webkit/browser.rb', line 102 def set_proxy( = {}) = .merge() command("SetProxy", [:type], [:host], [:port], [:user], [:pass]) end |
#source ⇒ Object
40 41 42 |
# File 'lib/capybara/driver/webkit/browser.rb', line 40 def source command("Source") end |
#status_code ⇒ Object
44 45 46 |
# File 'lib/capybara/driver/webkit/browser.rb', line 44 def status_code command("Status").to_i end |
#url ⇒ Object
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 |