Class: Capybara::Apparition::Browser
- Inherits:
-
Object
- Object
- Capybara::Apparition::Browser
- Extended by:
- Forwardable
- Defined in:
- lib/capybara/apparition/browser.rb,
lib/capybara/apparition/browser/auth.rb,
lib/capybara/apparition/browser/frame.rb,
lib/capybara/apparition/browser/modal.rb,
lib/capybara/apparition/browser/cookie.rb,
lib/capybara/apparition/browser/header.rb,
lib/capybara/apparition/browser/render.rb,
lib/capybara/apparition/browser/window.rb,
lib/capybara/apparition/driver/launcher.rb,
lib/capybara/apparition/browser/page_manager.rb
Defined Under Namespace
Modules: Auth, Cookie, Frame, Header, Modal, Render, Window Classes: Launcher, PageManager
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#console ⇒ Object
readonly
Returns the value of attribute console.
-
#debug ⇒ Object
writeonly
Sets the attribute debug.
-
#ignore_https_errors ⇒ Object
Returns the value of attribute ignore_https_errors.
-
#js_errors ⇒ Object
Returns the value of attribute js_errors.
-
#paper_size ⇒ Object
readonly
Returns the value of attribute paper_size.
-
#proxy_auth ⇒ Object
readonly
Returns the value of attribute proxy_auth.
-
#zoom_factor ⇒ Object
readonly
Returns the value of attribute zoom_factor.
Instance Method Summary collapse
- #body ⇒ Object
- #clear_memory_cache ⇒ Object
- #click_coordinates(x, y) ⇒ Object
- #command(name, **params) ⇒ Object
- #command_for_session(session_id, name, params) ⇒ Object
- #console_messages(type = nil) ⇒ Object
- #current_page(allow_nil: false) ⇒ Object
- #extensions=(filenames) ⇒ Object
-
#initialize(client, logger = nil) {|_self| ... } ⇒ Browser
constructor
A new instance of Browser.
- #network_traffic(type = nil) ⇒ Object
- #refresh_pages(opener:) ⇒ Object
- #reset ⇒ Object
- #resize(width, height, screen: nil) ⇒ Object
- #restart ⇒ Object
- #source ⇒ Object
- #url_blacklist=(blacklist) ⇒ Object
- #url_whitelist=(whitelist) ⇒ Object
Methods included from Auth
#set_http_auth, #set_proxy_auth
Methods included from Frame
Methods included from Modal
#accept_alert, #accept_confirm, #accept_prompt, #dismiss_confirm, #dismiss_prompt, #modal_message
Methods included from Cookie
#clear_cookies, #cookies, #cookies_enabled=, #get_raw_cookies, #remove_cookie, #set_cookie
Methods included from Render
#paper_size=, #render, #render_base64
Methods included from Window
#close_window, #current_window_handle, #open_new_window, #switch_to_window, #window_handles
Methods included from Header
#add_header, #add_headers, #headers, #headers=
Constructor Details
#initialize(client, logger = nil) {|_self| ... } ⇒ Browser
Returns a new instance of Browser.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/capybara/apparition/browser.rb', line 31 def initialize(client, logger = nil) @client = client @current_page_handle = nil @pages = PageManager.new(self) @context_id = nil @js_errors = true @ignore_https_errors = false @logger = logger @console = Console.new(logger) @proxy_auth = nil initialize_handlers command('Target.setDiscoverTargets', discover: true) yield self if block_given? reset end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
20 21 22 |
# File 'lib/capybara/apparition/browser.rb', line 20 def client @client end |
#console ⇒ Object (readonly)
Returns the value of attribute console.
20 21 22 |
# File 'lib/capybara/apparition/browser.rb', line 20 def console @console end |
#debug=(value) ⇒ Object (writeonly)
Sets the attribute debug
149 150 151 |
# File 'lib/capybara/apparition/browser.rb', line 149 def debug=(value) @debug = value end |
#ignore_https_errors ⇒ Object
Returns the value of attribute ignore_https_errors.
132 133 134 |
# File 'lib/capybara/apparition/browser.rb', line 132 def ignore_https_errors @ignore_https_errors end |
#js_errors ⇒ Object
Returns the value of attribute js_errors.
132 133 134 |
# File 'lib/capybara/apparition/browser.rb', line 132 def js_errors @js_errors end |
#paper_size ⇒ Object (readonly)
Returns the value of attribute paper_size.
20 21 22 |
# File 'lib/capybara/apparition/browser.rb', line 20 def paper_size @paper_size end |
#proxy_auth ⇒ Object (readonly)
Returns the value of attribute proxy_auth.
20 21 22 |
# File 'lib/capybara/apparition/browser.rb', line 20 def proxy_auth @proxy_auth end |
#zoom_factor ⇒ Object (readonly)
Returns the value of attribute zoom_factor.
20 21 22 |
# File 'lib/capybara/apparition/browser.rb', line 20 def zoom_factor @zoom_factor end |
Instance Method Details
#body ⇒ Object
60 61 62 |
# File 'lib/capybara/apparition/browser.rb', line 60 def body current_page.content end |
#clear_memory_cache ⇒ Object
151 152 153 |
# File 'lib/capybara/apparition/browser.rb', line 151 def clear_memory_cache current_page.command('Network.clearBrowserCache') end |
#click_coordinates(x, y) ⇒ Object
69 70 71 |
# File 'lib/capybara/apparition/browser.rb', line 69 def click_coordinates(x, y) current_page.click_at(x, y) end |
#command(name, **params) ⇒ Object
155 156 157 158 159 160 161 162 163 |
# File 'lib/capybara/apparition/browser.rb', line 155 def command(name, **params) result = client.send_cmd(name, params).result log result result || raise(Capybara::Apparition::ObsoleteNode.new(nil, nil)) rescue DeadClient restart raise end |
#command_for_session(session_id, name, params) ⇒ Object
165 166 167 168 169 170 |
# File 'lib/capybara/apparition/browser.rb', line 165 def command_for_session(session_id, name, params) client.send_cmd_to_session(session_id, name, params) rescue DeadClient restart raise end |
#console_messages(type = nil) ⇒ Object
182 183 184 |
# File 'lib/capybara/apparition/browser.rb', line 182 def (type = nil) console.(type) end |
#current_page(allow_nil: false) ⇒ Object
172 173 174 175 176 177 178 179 180 |
# File 'lib/capybara/apparition/browser.rb', line 172 def current_page(allow_nil: false) @pages[@current_page_handle] || begin puts "No current page: #{@current_page_handle} : #{caller}" if ENV['DEBUG'] @current_page_handle = nil raise NoSuchWindowError unless allow_nil @current_page_handle end end |
#extensions=(filenames) ⇒ Object
134 135 136 137 138 139 |
# File 'lib/capybara/apparition/browser.rb', line 134 def extensions=(filenames) @extensions = filenames Array(filenames).each do |name| current_page(allow_nil: true)&.add_extension(name) end end |
#network_traffic(type = nil) ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/capybara/apparition/browser.rb', line 123 def network_traffic(type = nil) case type when :blocked current_page.network_traffic.select(&:blocked?) else current_page.network_traffic end end |
#refresh_pages(opener:) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/capybara/apparition/browser.rb', line 111 def refresh_pages(opener:) @pages.refresh(opener: opener, ignore_https_errors: ignore_https_errors, js_errors: js_errors, url_blacklist: @url_blacklist, url_whitelist: @url_whitelist) end |
#reset ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/capybara/apparition/browser.rb', line 81 def reset new_context_id = command('Target.createBrowserContext')['browserContextId'] new_target_response = client.send_cmd('Target.createTarget', url: 'about:blank', browserContextId: new_context_id) @pages.reset new_target_id = new_target_response['targetId'] session_id = command('Target.attachToTarget', targetId: new_target_id)['sessionId'] session = Capybara::Apparition::DevToolsProtocol::Session.new(self, client, session_id) @pages.create(new_target_id, session, new_context_id, ignore_https_errors: ignore_https_errors, js_errors: js_errors, extensions: @extensions, url_blacklist: @url_blacklist, url_whitelist: @url_whitelist) .send(:main_frame).loaded! timer = Capybara::Helpers.timer(expire_in: 10) until @pages[new_target_id].usable? if timer.expired? puts 'Timedout waiting for reset' raise TimeoutError, 'reset' end sleep 0.01 end console.clear @current_page_handle = new_target_id true end |
#resize(width, height, screen: nil) ⇒ Object
119 120 121 |
# File 'lib/capybara/apparition/browser.rb', line 119 def resize(width, height, screen: nil) current_page. width: width, height: height, screen: screen end |
#restart ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/capybara/apparition/browser.rb', line 49 def restart # puts 'handle client restart' # client.restart self.debug = @debug if defined?(@debug) self.js_errors = @js_errors if defined?(@js_errors) self.zoom_factor = @zoom_factor if defined?(@zoom_factor) self.extensions = @extensions if @extensions current_page.clear_network_traffic end |
#source ⇒ Object
64 65 66 67 |
# File 'lib/capybara/apparition/browser.rb', line 64 def source # Is this still useful? # command 'source' end |
#url_blacklist=(blacklist) ⇒ Object
145 146 147 |
# File 'lib/capybara/apparition/browser.rb', line 145 def url_blacklist=(blacklist) @url_blacklist = @pages.blacklist = blacklist end |
#url_whitelist=(whitelist) ⇒ Object
141 142 143 |
# File 'lib/capybara/apparition/browser.rb', line 141 def url_whitelist=(whitelist) @url_whitelist = @pages.whitelist = whitelist end |