Class: Ferrum::Browser
- Inherits:
-
Object
- Object
- Ferrum::Browser
- Extended by:
- Forwardable
- Defined in:
- lib/ferrum/browser.rb,
lib/ferrum/browser/client.rb,
lib/ferrum/browser/process.rb,
lib/ferrum/browser/subscriber.rb,
lib/ferrum/browser/web_socket.rb
Defined Under Namespace
Classes: Client, Process, Subscriber, WebSocket
Constant Summary collapse
- DEFAULT_TIMEOUT =
ENV.fetch("FERRUM_DEFAULT_TIMEOUT", 5).to_i
- WINDOW_SIZE =
[1024, 768].freeze
- BASE_URL_SCHEMA =
%w[http https].freeze
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#contexts ⇒ Object
readonly
Returns the value of attribute contexts.
-
#js_errors ⇒ Object
readonly
Returns the value of attribute js_errors.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#process ⇒ Object
readonly
Returns the value of attribute process.
-
#slowmo ⇒ Object
readonly
Returns the value of attribute slowmo.
- #timeout ⇒ Object
-
#window_size ⇒ Object
readonly
Returns the value of attribute window_size.
Instance Method Summary collapse
- #command(*args) ⇒ Object
- #crash ⇒ Object
- #extensions ⇒ Object
-
#initialize(options = nil) ⇒ Browser
constructor
A new instance of Browser.
- #quit ⇒ Object
- #reset ⇒ Object
- #resize(**options) ⇒ Object
- #restart ⇒ Object
Constructor Details
#initialize(options = nil) ⇒ Browser
Returns a new instance of Browser.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ferrum/browser.rb', line 32 def initialize( = nil) ||= {} @client = nil @window_size = .fetch(:window_size, WINDOW_SIZE) @original_window_size = @window_size @options = Hash(.merge(window_size: @window_size)) @logger, @timeout = @options.values_at(:logger, :timeout) @js_errors = @options.fetch(:js_errors, false) @slowmo = @options[:slowmo].to_i if @options.key?(:base_url) self.base_url = @options[:base_url] end if ENV["FERRUM_DEBUG"] && !@logger STDOUT.sync = true @logger = STDOUT @options[:logger] = @logger end @options.freeze start end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
28 29 30 |
# File 'lib/ferrum/browser.rb', line 28 def base_url @base_url end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
28 29 30 |
# File 'lib/ferrum/browser.rb', line 28 def client @client end |
#contexts ⇒ Object (readonly)
Returns the value of attribute contexts.
28 29 30 |
# File 'lib/ferrum/browser.rb', line 28 def contexts @contexts end |
#js_errors ⇒ Object (readonly)
Returns the value of attribute js_errors.
28 29 30 |
# File 'lib/ferrum/browser.rb', line 28 def js_errors @js_errors end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
28 29 30 |
# File 'lib/ferrum/browser.rb', line 28 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
28 29 30 |
# File 'lib/ferrum/browser.rb', line 28 def @options end |
#process ⇒ Object (readonly)
Returns the value of attribute process.
28 29 30 |
# File 'lib/ferrum/browser.rb', line 28 def process @process end |
#slowmo ⇒ Object (readonly)
Returns the value of attribute slowmo.
28 29 30 |
# File 'lib/ferrum/browser.rb', line 28 def slowmo @slowmo end |
#timeout ⇒ Object
72 73 74 |
# File 'lib/ferrum/browser.rb', line 72 def timeout @timeout || DEFAULT_TIMEOUT end |
#window_size ⇒ Object (readonly)
Returns the value of attribute window_size.
28 29 30 |
# File 'lib/ferrum/browser.rb', line 28 def window_size @window_size end |
Instance Method Details
#command(*args) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/ferrum/browser.rb', line 76 def command(*args) @client.command(*args) rescue DeadBrowserError restart raise end |
#crash ⇒ Object
104 105 106 |
# File 'lib/ferrum/browser.rb', line 104 def crash command("Browser.crash") end |
#extensions ⇒ Object
68 69 70 |
# File 'lib/ferrum/browser.rb', line 68 def extensions @extensions ||= Array(@options[:extensions]).map { |p| File.read(p) } end |
#quit ⇒ Object
93 94 95 96 97 |
# File 'lib/ferrum/browser.rb', line 93 def quit @client.close @process.stop @client = @process = @contexts = nil end |
#reset ⇒ Object
83 84 85 86 |
# File 'lib/ferrum/browser.rb', line 83 def reset @window_size = @original_window_size contexts.reset end |
#resize(**options) ⇒ Object
99 100 101 102 |
# File 'lib/ferrum/browser.rb', line 99 def resize(**) @window_size = [[:width], [:height]] page.resize(**) end |
#restart ⇒ Object
88 89 90 91 |
# File 'lib/ferrum/browser.rb', line 88 def restart quit start end |