ferrum 0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 977220d1be605d449fd593a263f464707ce1e0bcc9dd3c6cc0a187f64b7e2385
4
- data.tar.gz: 47a490f0c7b99c597fb069eec517c2e42c4466fc1791f0a63d4807e9ec9d7016
3
+ metadata.gz: 8c6a15f2244fefda208b8b35181892fd1287414a31485acf98aa55226210cdb3
4
+ data.tar.gz: 6214c762f7ea1b85558220de3501fa43791f7f2027682b33d3ee0d6c6ba654ae
5
5
  SHA512:
6
- metadata.gz: c0f09cb6f46996f2532add8556ac8c3a7adf4787955274cff1592c36215224f81a2d9835fd66316e61f2cdd0f5919ca3cbbb293ef1d381c1898c5dd4d061b672
7
- data.tar.gz: 8a4e05fe95de8400e5c93c7e192d7903d819ab30831db10b180c705ea87430f6a064404e438f9d79b767d23074968330d0178dbd6375445064e35071c773e96a
6
+ metadata.gz: 41499a98b5c623ce277ea890255bac0ae89c696c0d297b322b60e73594cad6ad1451dff474ff14fbd58cc5dead1f62d3d7962ec81677a89c9bdc5abb52296bf8
7
+ data.tar.gz: 280dc77020f401cdcd0bca4f87214fa83d1899413cda6f1decb761c201cece76a7dec48f4c45973e0726dcf9cb1acaa6b37512fc860f8bfeeea8cf42d1b15d62
data/README.md CHANGED
@@ -6,6 +6,23 @@ It is Ruby clean and high-level API to Chrome. Runs headless by default,
6
6
  but you can configure it to run in a non-headless mode. All you need is Ruby and
7
7
  Chrome/Chromium. Ferrum connects to the browser via DevTools Protocol.
8
8
 
9
+ Relation to [Cuprite](https://github.com/machinio/cuprite). Cuprite used to have
10
+ this code inside in one form or another but the thing is you don't need capybara
11
+ if you are going to crawl sites. You crawl, not test. Besides that clean
12
+ lightweight API to browser is what Ruby was missing, so here it comes.
13
+
14
+ ## Install
15
+
16
+ There's no official Chrome or Chromium package for Linux don't install it this
17
+ way because it either will be outdated or unofficial, both are bad. Download it
18
+ from official [source](https://www.chromium.org/getting-involved/download-chromium).
19
+ Chrome binary should be in the `PATH` or `BROWSER_PATH` or you can pass it as an
20
+ option.
21
+
22
+ ``` ruby
23
+ gem "ferrum"
24
+ ```
25
+
9
26
  Navigate to a website and save a screenshot:
10
27
 
11
28
  ```ruby
@@ -57,7 +74,41 @@ browser.mouse
57
74
  browser.quit
58
75
  ```
59
76
 
60
- #### The API below is correct but a subject to change before `1.0`
77
+ ## Customization ##
78
+
79
+ You can customize options with the following code in your test setup:
80
+
81
+ ``` ruby
82
+ Ferrum::Browser.new(options)
83
+ ```
84
+
85
+ * options `Hash`
86
+ * `:browser_path` (String) - Path to chrome binary, you can also set ENV
87
+ variable as `BROWSER_PATH=some/path/chrome bundle exec rspec`.
88
+ * `:headless` (Boolean) - Set browser as headless or not, `true` by default.
89
+ * `:slowmo` (Integer | Float) - Set a delay to wait before sending command.
90
+ Usefull companion of headless option, so that you have time to see changes.
91
+ * `:logger` (Object responding to `puts`) - When present, debug output is
92
+ written to this object.
93
+ * `:timeout` (Numeric) - The number of seconds we'll wait for a response when
94
+ communicating with browser. Default is 5.
95
+ * `:js_errors` (Boolean) - When true, JavaScript errors get re-raised in Ruby.
96
+ * `:window_size` (Array) - The dimensions of the browser window in which to
97
+ test, expressed as a 2-element array, e.g. [1024, 768]. Default: [1024, 768]
98
+ * `:browser_options` (Hash) - Additional command line options,
99
+ [see them all](https://peter.sh/experiments/chromium-command-line-switches/)
100
+ e.g. `{ "ignore-certificate-errors" => nil }`
101
+ * `:extensions` (Array) - An array of JS files to be preloaded into the browser
102
+ * `:port` (Integer) - Remote debugging port for headless Chrome
103
+ * `:host` (String) - Remote debugging address for headless Chrome
104
+ * `:url` (String) - URL for a running instance of Chrome. If this is set, a
105
+ browser process will not be spawned.
106
+ * `:process_timeout` (Integer) - How long to wait for the Chrome process to
107
+ respond on startup
108
+
109
+
110
+ #### The API below is for master branch and a subject to change before 1.0
111
+
61
112
 
62
113
  ## Navigation
63
114
 
@@ -196,6 +247,7 @@ browser.goto("https://google.com/")
196
247
  browser.body # => '<html itemscope="" itemtype="http://schema.org/WebPage" lang="ru"><head>...
197
248
  ```
198
249
 
250
+
199
251
  ## Screenshots
200
252
 
201
253
  #### screenshot(\*\*options) : `String` | `Integer`
@@ -10,7 +10,7 @@ module Ferrum
10
10
  class Browser
11
11
  class Process
12
12
  KILL_TIMEOUT = 2
13
- PROCESS_TIMEOUT = 1
13
+ PROCESS_TIMEOUT = 2
14
14
  BROWSER_PATH = ENV["BROWSER_PATH"]
15
15
  BROWSER_HOST = "127.0.0.1"
16
16
  BROWSER_PORT = "0"
@@ -28,7 +28,7 @@ module Ferrum
28
28
  while data = @sock.readpartial(512)
29
29
  @driver.parse(data)
30
30
  end
31
- rescue EOFError, Errno::ECONNRESET
31
+ rescue EOFError, Errno::ECONNRESET, Errno::EPIPE
32
32
  @messages.close
33
33
  end
34
34
  end
@@ -62,6 +62,8 @@ module Ferrum
62
62
 
63
63
  def write(data)
64
64
  @sock.write(data)
65
+ rescue EOFError, Errno::ECONNRESET, Errno::EPIPE
66
+ @messages.close
65
67
  end
66
68
 
67
69
  def close
@@ -19,7 +19,7 @@ module Ferrum::Network
19
19
  end
20
20
 
21
21
  def match?(regexp)
22
- url.match?(regexp)
22
+ !!(url =~ regexp)
23
23
  end
24
24
 
25
25
  def abort
@@ -86,8 +86,6 @@ module Ferrum
86
86
  push(target_id, @page)
87
87
  end
88
88
 
89
- private
90
-
91
89
  def find_or_create_page(target_id)
92
90
  page = @targets[target_id]
93
91
  page ||= Page.new(target_id, @browser, true)
@@ -95,6 +93,8 @@ module Ferrum
95
93
  page
96
94
  end
97
95
 
96
+ private
97
+
98
98
  def remove_page(target_id)
99
99
  page = @targets.delete(target_id)
100
100
  @page = nil if page && @page == page
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ferrum
4
- VERSION = "0.2"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ferrum
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Vorotilin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-03 00:00:00.000000000 Z
11
+ date: 2019-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket-driver