capybara-box 0.4.0 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -2
  3. data/README.md +30 -42
  4. data/lib/capybara-box.rb +6 -2
  5. data/lib/capybara-box/base.rb +55 -98
  6. data/lib/capybara-box/helper.rb +19 -0
  7. data/lib/capybara-box/screenshot.rb +45 -0
  8. data/lib/capybara-box/version.rb +1 -1
  9. metadata +11 -58
  10. data/spec/lib/capybara_box/base/add_argument_spec.rb +0 -35
  11. data/spec/lib/capybara_box/base/add_preference_spec.rb +0 -35
  12. data/spec/lib/capybara_box/base/apply_arguments_spec.rb +0 -33
  13. data/spec/lib/capybara_box/base/apply_bin_path_spec.rb +0 -34
  14. data/spec/lib/capybara_box/base/apply_preferences_spec.rb +0 -43
  15. data/spec/lib/capybara_box/base/apply_version_spec.rb +0 -37
  16. data/spec/lib/capybara_box/base/arguments_spec.rb +0 -72
  17. data/spec/lib/capybara_box/base/chrome_family_spec.rb +0 -23
  18. data/spec/lib/capybara_box/base/chrome_headless_spec.rb +0 -17
  19. data/spec/lib/capybara_box/base/chrome_spec.rb +0 -17
  20. data/spec/lib/capybara_box/base/configure_screenshot_spec.rb +0 -83
  21. data/spec/lib/capybara_box/base/configure_spec.rb +0 -33
  22. data/spec/lib/capybara_box/base/create_spec.rb +0 -89
  23. data/spec/lib/capybara_box/base/driver_options_spec.rb +0 -74
  24. data/spec/lib/capybara_box/base/driver_spec.rb +0 -97
  25. data/spec/lib/capybara_box/base/firefox_spec.rb +0 -17
  26. data/spec/lib/capybara_box/base/http_client_options_spec.rb +0 -24
  27. data/spec/lib/capybara_box/base/http_client_spec.rb +0 -11
  28. data/spec/lib/capybara_box/base/log_spec.rb +0 -43
  29. data/spec/lib/capybara_box/base/options_spec.rb +0 -43
  30. data/spec/lib/capybara_box/base/preferences_spec.rb +0 -63
  31. data/spec/lib/capybara_box/base/register_spec.rb +0 -17
  32. data/spec/lib/capybara_box/base/self_configure_spec.rb +0 -22
  33. data/spec/lib/capybara_box/base/version_spec.rb +0 -33
  34. data/spec/rails_helper.rb +0 -9
  35. data/spec/support/common.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0deb88846933c0b4cdd24ec64635b968b84a6704043ecf36aa60d8271f9bca5d
4
- data.tar.gz: 3cc96c2a55edffa829341d134e698978cfe1f6b0424b1fbe18a7ecdb077f3fe5
3
+ metadata.gz: 6eb43822ce3b518d701a86c67a72908953c0c49e699b3b29ba263e3b8b4f17f7
4
+ data.tar.gz: e35c51b8daa7efc62aa182d2f3280227d59413d674921f9ce9fe0209b7a326a7
5
5
  SHA512:
6
- metadata.gz: 6a7cef25e696a2cfd356c73d5864544b0150219569dcb3070511dfa9b1a3db67a410be604acca4408a1884cbd2ad521789491967006287563453d9b54a14a40a
7
- data.tar.gz: aadf0bd2d9e84dd0d778e640dd53a8f1593a2ff50f8cf93be24d38fa4e795731fe7ca91632040ba23481fcdca959bf318c68175a72c7de8c1b08da180be5b6de
6
+ metadata.gz: d2992956c71d654754f4c1098fe474cc8df6dcac9516926782f9c8a3876bdccabea3d860d59362451ffe17f08c09f8e40495137d6668c405002455cdf81e6e56
7
+ data.tar.gz: c15d8442bce49d012f6e7f92094619c5afb3d59ae039745a991aeab7b18544778a3715dd5466c90de080fdf1d2f1196d8ab8e5bc1630f814c6b995da7269bc52
@@ -1,3 +1,41 @@
1
+ ## v1.1.2
2
+
3
+ - Fixes
4
+ - Avoid apply blank bin path;
5
+ - Avoid apply blank version;
6
+
7
+ ## v1.1.1
8
+
9
+ - Fixes
10
+ - Removes default args that was avoiding screen render.
11
+
12
+ ## v1.1.0
13
+
14
+ - Fixes
15
+ - S3 config activation;
16
+
17
+ - Update
18
+ - Adds more default arguments;
19
+
20
+ ## v1.0.1
21
+
22
+ - Fixes
23
+ - Registers driver name as symbol;
24
+
25
+ ## v1.0.0
26
+
27
+ - Updates
28
+ - Updated default arguments;
29
+ - Spec files now is excluded from gem pack;
30
+
31
+ - Features
32
+ - Capybara `load_selenium` is called before startup;
33
+ - Screenshot S3 feature now is configure only via ENV;
34
+ - Using new gem `webdrivers`;
35
+
36
+ - Fixes
37
+ - Fix screenshot upload;
38
+
1
39
  ## v0.4.0
2
40
 
3
41
  - Updates Selenium WebDriver deprecated message;
@@ -9,12 +47,12 @@
9
47
 
10
48
  ## v0.2.1
11
49
 
12
- - fixes
50
+ - Fixes
13
51
  - `chrome_headless` was being registered with wrong name.
14
52
 
15
53
  ## v0.2.0
16
54
 
17
- - features
55
+ - Features
18
56
  - Add log feature for Chrome and Chrome Headless.
19
57
 
20
58
  ## v0.1.0
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # Capybara Box
2
2
 
3
- [![Build Status](https://travis-ci.org/wbotelhos/capybara-box.svg)](https://travis-ci.org/wbotelhos/capybara-box)
3
+ [![Build Status](https://travis-ci.org/wbotelhos/capybara-box.svg?branch=master)](https://travis-ci.org/wbotelhos/capybara-box)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/1b13dc12b03be63baaed/maintainability)](https://codeclimate.com/github/wbotelhos/capybara-box/maintainability)
4
5
  [![Gem Version](https://badge.fury.io/rb/capybara-box.svg)](https://badge.fury.io/rb/capybara-box)
6
+ [![Patreon](https://img.shields.io/badge/donate-%3C3-brightgreen.svg)](https://www.patreon.com/wbotelhos)
5
7
 
6
- Configure Capybara with **Chrome**, **Chrome Headless** or **Firefox** with *Screenshot* feature and *Session* without losing your mind with just one line.
8
+ Configure Capybara with **Chrome**, **Chrome Headless**, **Firefox** and **Firefox Headless** with *Screenshot* feature without losing your mind.
7
9
 
8
10
  ## install
9
11
 
@@ -26,42 +28,37 @@ require 'capybara-box'
26
28
  CapybaraBox::Base.configure
27
29
  ```
28
30
 
29
- By default, `chrome` is the driver, but you can use `chrome_headless` and `firefox` too.
31
+ By default, `selenium_chrome` is the driver, but you can use `selenium_chrome_headless` and `selenium_firefox` or `selenium_firefox_headless` too.
30
32
 
31
33
  ## Version
32
34
 
33
- You can use a embbeded driver via `webdrivers` if you do not want to install the `chromedriver` by yourself as following:
35
+ The version is setted via `webdrivers`. You can specify the version:
34
36
 
35
37
  ```ruby
36
- CapybaraBox::Base.configure version: '2.32'
38
+ CapybaraBox::Base.configure(version: '83.0.4103.39')
37
39
  ```
38
40
 
39
- * This works just for `chrome` and `chrome_headless`, for now
40
-
41
41
  ## Screenshot
42
42
 
43
- You can enable screenshot on failure and send it to S3.
43
+ You can enable screenshot on failure:
44
44
 
45
45
  ```ruby
46
- CapybaraBox.configure(
47
- screenshot: {
48
- s3: {
49
- access_key_id: 'KEY',
50
- bucket: 'bucket',
51
- secret_access_key: 'SECRET'
52
- }
53
- }
54
- )
46
+ CapybaraBox.configure(screenshot: { enabled: true })
55
47
  ```
56
48
 
57
- If you want enable it only on CI, use the `enabled` option:
49
+ If you want to send the screenshot and html page to S3 setup your credentials via ENV:
58
50
 
59
- ```ruby
60
- CapybaraBox.configure(
61
- enabled: ENV['CI'],
51
+ ```sh
52
+ ENV['CAPYBARA_BOX__S3_BUCKET_NAME']
53
+ ENV['CAPYBARA_BOX__S3_REGION']
54
+ ENV['CAPYBARA_BOX__S3_ACCESS_KEY_ID']
55
+ ENV['CAPYBARA_BOX__S3_SECRET_ACCESS_KEY']
56
+ ```
57
+
58
+ And then enable S3 feature:
62
59
 
63
- screenshot: { // ... }
64
- )
60
+ ```ruby
61
+ CapybaraBox.configure(screenshot: { enabled: true, s3: true })
65
62
  ```
66
63
 
67
64
  ## Add Argument
@@ -71,7 +68,7 @@ By default some Switches are enabled for a better performance, you can add yours
71
68
  ```ruby
72
69
  capybara_box = CapybaraBox.configure
73
70
 
74
- capybara_box.add_argument '--incognito'
71
+ capybara_box.add_argument('--incognito')
75
72
  ```
76
73
 
77
74
  ## Arguments
@@ -79,7 +76,7 @@ capybara_box.add_argument '--incognito'
79
76
  If you prefere, is possible override all of them:
80
77
 
81
78
  ```ruby
82
- CapybaraBox.configure arguments: ['--incognito']
79
+ CapybaraBox.configure(arguments: ['--incognito'])
83
80
  ```
84
81
 
85
82
  Click [here](https://peter.sh/experiments/chromium-command-line-switches) to see the avaiables.
@@ -91,7 +88,7 @@ By default some Preferences are enabled for a better performance, you can add yo
91
88
  ```ruby
92
89
  capybara_box = CapybaraBox.configure
93
90
 
94
- capybara_box.add_preference :credentials_enable_service, false
91
+ capybara_box.add_preference(:credentials_enable_service, false)
95
92
  ```
96
93
 
97
94
  ## Preferences
@@ -99,7 +96,7 @@ capybara_box.add_preference :credentials_enable_service, false
99
96
  If you prefere, is possible override all of them:
100
97
 
101
98
  ```ruby
102
- CapybaraBox.configure preferences: { credentials_enable_service: false }
99
+ CapybaraBox.configure(preferences: { credentials_enable_service: false })
103
100
  ```
104
101
 
105
102
  You can check [Chrome](https://sites.google.com/a/chromium.org/chromedriver/home) and [Firefox](http://preferential.mozdev.org/preferences.html).
@@ -111,7 +108,7 @@ It has this restrition because with timeout enabled, debugger cannot evaluate th
111
108
  You can override all of them too:
112
109
 
113
110
  ```ruby
114
- CapybaraBox.configure http_client_options: { read_timeout: 60 }
111
+ CapybaraBox.configure(http_client_options: { read_timeout: 60 })
115
112
  ```
116
113
 
117
114
  ## Driver Options
@@ -119,15 +116,18 @@ CapybaraBox.configure http_client_options: { read_timeout: 60 }
119
116
  You can override all driver options:
120
117
 
121
118
  ```ruby
122
- CapybaraBox.configure driver_options: { clear_local_storage: true }
119
+ CapybaraBox.configure(driver_options: { clear_local_storage: true })
123
120
  ```
124
121
 
125
122
  ## Log
126
123
 
127
124
  Log is writen at `log/capybara-box.log` as default.
128
-
129
125
  You can see each command executed. Time spent between them and debug some hanging command. :tada:
130
126
 
127
+ ```ruby
128
+ CapybaraBox.configure(log: true)
129
+ ```
130
+
131
131
  ```
132
132
  [15.479][INFO]: RESPONSE Navigate
133
133
  [15.482][INFO]: COMMAND ExecuteScript {
@@ -137,15 +137,3 @@ You can see each command executed. Time spent between them and debug some hangin
137
137
  [15.483][INFO]: Waiting for pending navigations...
138
138
  [15.545][INFO]: Done waiting for pending navigations. Status: ok
139
139
  ```
140
-
141
- To disable log on CI, for example, use the `log` options:
142
-
143
- ```ruby
144
- CapybaraBox.configure log: ENV['CI'].nil?
145
- ```
146
-
147
- * It works only for **chrome** and **chrome_headless**.
148
-
149
- ## Love it!
150
-
151
- Via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=X8HEP2878NDEG&item_name=capybara-box) or [Gratipay](https://gratipay.com/~wbotelhos). Thanks! (:
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'selenium/webdriver'
4
+ require 'webdrivers'
5
+
3
6
  module CapybaraBox
7
+ require 'capybara-box/base'
8
+ require 'capybara-box/helper'
9
+ require 'capybara-box/screenshot'
4
10
  end
5
-
6
- require 'capybara-box/base'
@@ -1,38 +1,40 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CapybaraBox
4
- require 'selenium/webdriver'
5
-
6
4
  class Base
7
5
  def initialize(parameters = {})
8
- @browser = parameters[:browser] || :chrome
6
+ @browser = parameters.fetch(:browser) { :selenium_chrome }
9
7
  @max_wait_time = parameters[:max_wait_time]
10
8
  @parameters = parameters
11
9
  end
12
10
 
13
11
  def add_argument(value)
14
- options.add_argument value unless options.nil?
12
+ options&.add_argument(value)
15
13
  end
16
14
 
17
15
  def add_preference(key, value)
18
- options.add_preference key, value unless options.nil?
16
+ options&.add_preference(key, value)
19
17
  end
20
18
 
21
19
  def apply_arguments
22
- arguments.each { |argument| add_argument argument }
20
+ arguments.each { |argument| add_argument(argument) }
23
21
 
24
- add_argument '--headless' if chrome_headless?
22
+ if chrome_headless?
23
+ add_argument('--headless')
24
+ add_argument('--no-sandbox')
25
+ add_argument('--disable-gpu')
26
+ end
25
27
  end
26
28
 
27
29
  def apply_preferences
28
- preferences.each { |key, value| add_preference key, value }
30
+ preferences.each { |key, value| add_preference(key, value) }
29
31
  end
30
32
 
31
33
  def apply_version(version)
32
34
  if chrome_family?
33
- require 'chromedriver/helper'
34
-
35
- ::Chromedriver.set_version version
35
+ Webdrivers::Chromedriver.required_version = version
36
+ else
37
+ Webdrivers::Geckodriver.required_version = version
36
38
  end
37
39
  end
38
40
 
@@ -41,7 +43,9 @@ module CapybaraBox
41
43
  return [] unless chrome_family?
42
44
 
43
45
  %w[
46
+ --disable-background-networking
44
47
  --disable-default-apps
48
+ --disable-dev-shm-usage
45
49
  --disable-extensions
46
50
  --disable-infobars
47
51
  --disable-notifications
@@ -50,16 +54,23 @@ module CapybaraBox
50
54
  --disable-password-separated-signin-flow
51
55
  --disable-popup-blocking
52
56
  --disable-save-password-bubble
57
+ --disable-site-isolation-trials
58
+ --disable-sync
53
59
  --disable-translate
60
+ --hide-scrollbars
54
61
  --incognito
62
+ --metrics-recording-only
55
63
  --mute-audio
56
64
  --no-default-browser-check
65
+ --no-first-run
66
+ --safebrowsing-disable-auto-update
57
67
  --start-fullscreen
68
+ --window-size=1920,1080
58
69
  ]
59
70
  end
60
71
 
61
72
  def chrome?
62
- @browser == :chrome
73
+ @browser == :selenium_chrome
63
74
  end
64
75
 
65
76
  def chrome_family?
@@ -67,41 +78,19 @@ module CapybaraBox
67
78
  end
68
79
 
69
80
  def chrome_headless?
70
- @browser == :chrome_headless
81
+ @browser == :selenium_chrome_headless
71
82
  end
72
83
 
73
- def configure
84
+ def configure_capybara
74
85
  Capybara.javascript_driver = @browser
75
86
  Capybara.default_max_wait_time = @max_wait_time if @max_wait_time
76
87
  end
77
88
 
78
89
  def apply_bin_path(path)
79
90
  if firefox?
80
- Selenium::WebDriver::Firefox::Binary.path = path
81
-
82
- Selenium::WebDriver::Firefox::Binary.path
83
- end
84
- end
85
-
86
- def configure_screenshot
87
- return false if @parameters[:screenshot].key?(:enabled) && !true?(@parameters[:screenshot][:enabled])
88
-
89
- require 'capybara-screenshot/rspec'
90
-
91
- Capybara::Screenshot.append_timestamp = false
92
- Capybara::Screenshot.prune_strategy = :keep_last_run
93
- Capybara::Screenshot::RSpec.add_link_to_screenshot_for_failed_examples = false
91
+ ::Selenium::WebDriver::Firefox::Binary.path = path
94
92
 
95
- Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
96
- example.full_description.downcase.gsub('#', '--').tr ' ', '-'
97
- end
98
-
99
- if @parameters[:screenshot][:s3]
100
- Capybara::Screenshot.s3_configuration = screenshot_s3_config
101
- end
102
-
103
- Capybara::Screenshot.register_driver(@browser) do |driver, path|
104
- driver.browser.save_screenshot path
93
+ ::Selenium::WebDriver::Firefox::Binary.path
105
94
  end
106
95
  end
107
96
 
@@ -109,39 +98,40 @@ module CapybaraBox
109
98
  apply_arguments
110
99
  apply_preferences
111
100
 
112
- apply_bin_path @parameters[:bin_path] if @parameters[:bin_path]
113
- apply_version @parameters[:version] if version?
114
- configure_screenshot if @parameters[:screenshot]
101
+ apply_bin_path(@parameters[:bin_path]) if ::CapybaraBox::Helper.present?(@parameters[:bin_path])
102
+ apply_version(@parameters[:version]) if ::CapybaraBox::Helper.present?(@parameters[:version])
103
+
104
+ ::CapybaraBox::Screenshot.configure(@parameters[:screenshot], @browser) if @parameters[:screenshot]
115
105
 
116
- register @browser
106
+ register(@browser)
117
107
 
118
- configure
108
+ configure_capybara
119
109
  end
120
110
 
121
111
  def driver(app)
122
- opts = {}
123
- opts[:options] = options if chrome_family?
124
- opts[:http_client] = http_client if true?(ENV['CI'])
112
+ opts = {}
113
+ opts[:options] = options if chrome_family?
125
114
 
126
- Capybara::Selenium::Driver.new app, opts.merge(driver_options)
115
+ Capybara::Selenium::Driver.load_selenium
116
+
117
+ opts[:http_client] = http_client if ::CapybaraBox::Helper.true?(ENV['CI'])
118
+
119
+ Capybara::Selenium::Driver.new(app, opts.merge(driver_options))
127
120
  end
128
121
 
129
122
  def driver_options
130
123
  return @parameters[:driver_options] if @parameters[:driver_options]
131
124
 
132
125
  opts = {
133
- browser: chrome_family? ? :chrome : @browser,
134
- clear_local_storage: true,
135
- clear_session_storage: true
126
+ browser: chrome_family? ? :chrome : @browser,
127
+ clear_local_storage: true,
128
+ clear_session_storage: true,
136
129
  }
137
130
 
138
- if log?
139
- if chrome_family?
140
- opts[:service] = Selenium::WebDriver::Service.chrome(args: {
141
- log_path: 'log/capybara-box.log',
142
- verbose: true,
143
- })
144
- end
131
+ if log? && chrome_family?
132
+ opts[:service] = ::Selenium::WebDriver::Service.chrome(
133
+ args: { log_path: 'log/capybara-box.log', verbose: true }
134
+ )
145
135
  end
146
136
 
147
137
  opts
@@ -156,16 +146,16 @@ module CapybaraBox
156
146
 
157
147
  {
158
148
  open_timeout: nil,
159
- read_timeout: 120
149
+ read_timeout: 120,
160
150
  }
161
151
  end
162
152
 
163
153
  def http_client
164
- @http_client ||= Selenium::WebDriver::Remote::Http::Default.new(http_client_options)
154
+ @http_client ||= ::Selenium::WebDriver::Remote::Http::Default.new(**http_client_options)
165
155
  end
166
156
 
167
157
  def options
168
- @options ||= Selenium::WebDriver::Chrome::Options.new if chrome_family?
158
+ @options ||= ::Selenium::WebDriver::Chrome::Options.new if chrome_family?
169
159
  end
170
160
 
171
161
  def preferences
@@ -176,31 +166,17 @@ module CapybaraBox
176
166
  credentials_enable_service: false,
177
167
 
178
168
  profile: {
179
- password_manager_enabled: false
180
- }
169
+ password_manager_enabled: false,
170
+ },
181
171
  }
182
172
  end
183
173
 
184
174
  def register(name)
185
- Capybara.register_driver name do |app|
186
- driver app
187
- end
188
- end
189
-
190
- def version
191
- if chrome_family?
192
- require 'chromedriver/helper'
193
-
194
- ::Chromedriver::Helper.new.current_version
195
- end
175
+ Capybara.register_driver(name.to_sym) { |app| driver(app) }
196
176
  end
197
177
 
198
178
  def self.configure(parameters)
199
- box = new(parameters)
200
-
201
- box.create
202
-
203
- box
179
+ new(parameters).tap(&:create)
204
180
  end
205
181
 
206
182
  private
@@ -208,26 +184,7 @@ module CapybaraBox
208
184
  def log?
209
185
  return true if @parameters[:log].nil?
210
186
 
211
- true? @parameters[:log]
212
- end
213
-
214
- def true?(value)
215
- ['true', true].include? value
216
- end
217
-
218
- def screenshot_s3_config
219
- {
220
- s3_client_credentials: {
221
- access_key_id: @parameters[:screenshot][:s3][:access_key_id],
222
- secret_access_key: @parameters[:screenshot][:s3][:secret_access_key]
223
- },
224
-
225
- bucket_name: @parameters[:screenshot][:s3][:bucket]
226
- }
227
- end
228
-
229
- def version?
230
- !!@parameters[:version]
187
+ ::CapybaraBox::Helper.true?(@parameters[:log])
231
188
  end
232
189
  end
233
190
  end