capybara-box 0.4.0 → 1.0.0

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 +15 -2
  3. data/README.md +32 -42
  4. data/lib/capybara-box.rb +6 -2
  5. data/lib/capybara-box/base.rb +43 -98
  6. data/lib/capybara-box/helper.rb +11 -0
  7. data/lib/capybara-box/screenshot.rb +41 -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: 012a0f0743be254b6cfe3cbb5353ecad6e8abeb00c1498370656c52d26f34d98
4
+ data.tar.gz: c07e5d764ab4af59c4136ea93c93c10086dee9cf98abc5b202283758b98f89b9
5
5
  SHA512:
6
- metadata.gz: 6a7cef25e696a2cfd356c73d5864544b0150219569dcb3070511dfa9b1a3db67a410be604acca4408a1884cbd2ad521789491967006287563453d9b54a14a40a
7
- data.tar.gz: aadf0bd2d9e84dd0d778e640dd53a8f1593a2ff50f8cf93be24d38fa4e795731fe7ca91632040ba23481fcdca959bf318c68175a72c7de8c1b08da180be5b6de
6
+ metadata.gz: 208d41d18d4f3d6a8776717c30ca9471ea1281ea59b3f374b9d40ecfde1cbe1e4cfb9300f0db8ec9ea424fd50ee17d1597587e91b26077bb60f5517101a431c4
7
+ data.tar.gz: 6172f0ded5edbb4f6ec7aa12ff90fd727859d03fb9ab548c71dfb6fe42a5783d922f8948d8779ab3962bf51905b10cba2d724f683e05b4046be58aa8bfc759f1
@@ -1,3 +1,16 @@
1
+ ## v1.0.0
2
+
3
+ - Updates
4
+ - Updated default arguments;
5
+
6
+ - Features
7
+ - Capybara `load_selenium` is called before startup;
8
+ - Screenshot S3 feature now is configure only via ENV;
9
+ - Using new gem `webdrivers`;
10
+
11
+ - Fixes
12
+ - Fix screenshot upload;
13
+
1
14
  ## v0.4.0
2
15
 
3
16
  - Updates Selenium WebDriver deprecated message;
@@ -9,12 +22,12 @@
9
22
 
10
23
  ## v0.2.1
11
24
 
12
- - fixes
25
+ - Fixes
13
26
  - `chrome_headless` was being registered with wrong name.
14
27
 
15
28
  ## v0.2.0
16
29
 
17
- - features
30
+ - Features
18
31
  - Add log feature for Chrome and Chrome Headless.
19
32
 
20
33
  ## 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,44 +28,41 @@ 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
 
64
+ If you want enable it only on CI, use the `enabled` option:
65
+
67
66
  ## Add Argument
68
67
 
69
68
  By default some Switches are enabled for a better performance, you can add yours too:
@@ -71,7 +70,7 @@ By default some Switches are enabled for a better performance, you can add yours
71
70
  ```ruby
72
71
  capybara_box = CapybaraBox.configure
73
72
 
74
- capybara_box.add_argument '--incognito'
73
+ capybara_box.add_argument('--incognito')
75
74
  ```
76
75
 
77
76
  ## Arguments
@@ -79,7 +78,7 @@ capybara_box.add_argument '--incognito'
79
78
  If you prefere, is possible override all of them:
80
79
 
81
80
  ```ruby
82
- CapybaraBox.configure arguments: ['--incognito']
81
+ CapybaraBox.configure(arguments: ['--incognito'])
83
82
  ```
84
83
 
85
84
  Click [here](https://peter.sh/experiments/chromium-command-line-switches) to see the avaiables.
@@ -91,7 +90,7 @@ By default some Preferences are enabled for a better performance, you can add yo
91
90
  ```ruby
92
91
  capybara_box = CapybaraBox.configure
93
92
 
94
- capybara_box.add_preference :credentials_enable_service, false
93
+ capybara_box.add_preference(:credentials_enable_service, false)
95
94
  ```
96
95
 
97
96
  ## Preferences
@@ -99,7 +98,7 @@ capybara_box.add_preference :credentials_enable_service, false
99
98
  If you prefere, is possible override all of them:
100
99
 
101
100
  ```ruby
102
- CapybaraBox.configure preferences: { credentials_enable_service: false }
101
+ CapybaraBox.configure(preferences: { credentials_enable_service: false })
103
102
  ```
104
103
 
105
104
  You can check [Chrome](https://sites.google.com/a/chromium.org/chromedriver/home) and [Firefox](http://preferential.mozdev.org/preferences.html).
@@ -111,7 +110,7 @@ It has this restrition because with timeout enabled, debugger cannot evaluate th
111
110
  You can override all of them too:
112
111
 
113
112
  ```ruby
114
- CapybaraBox.configure http_client_options: { read_timeout: 60 }
113
+ CapybaraBox.configure(http_client_options: { read_timeout: 60 })
115
114
  ```
116
115
 
117
116
  ## Driver Options
@@ -119,15 +118,18 @@ CapybaraBox.configure http_client_options: { read_timeout: 60 }
119
118
  You can override all driver options:
120
119
 
121
120
  ```ruby
122
- CapybaraBox.configure driver_options: { clear_local_storage: true }
121
+ CapybaraBox.configure(driver_options: { clear_local_storage: true })
123
122
  ```
124
123
 
125
124
  ## Log
126
125
 
127
126
  Log is writen at `log/capybara-box.log` as default.
128
-
129
127
  You can see each command executed. Time spent between them and debug some hanging command. :tada:
130
128
 
129
+ ```ruby
130
+ CapybaraBox.configure(log: true)
131
+ ```
132
+
131
133
  ```
132
134
  [15.479][INFO]: RESPONSE Navigate
133
135
  [15.482][INFO]: COMMAND ExecuteScript {
@@ -137,15 +139,3 @@ You can see each command executed. Time spent between them and debug some hangin
137
139
  [15.483][INFO]: Waiting for pending navigations...
138
140
  [15.545][INFO]: Done waiting for pending navigations. Status: ok
139
141
  ```
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,36 @@
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
+ add_argument('--headless') if chrome_headless?
25
23
  end
26
24
 
27
25
  def apply_preferences
28
- preferences.each { |key, value| add_preference key, value }
26
+ preferences.each { |key, value| add_preference(key, value) }
29
27
  end
30
28
 
31
29
  def apply_version(version)
32
30
  if chrome_family?
33
- require 'chromedriver/helper'
34
-
35
- ::Chromedriver.set_version version
31
+ Webdrivers::Chromedriver.required_version = version
32
+ else
33
+ Webdrivers::Geckodriver.required_version = version
36
34
  end
37
35
  end
38
36
 
@@ -50,6 +48,7 @@ module CapybaraBox
50
48
  --disable-password-separated-signin-flow
51
49
  --disable-popup-blocking
52
50
  --disable-save-password-bubble
51
+ --disable-site-isolation-trials
53
52
  --disable-translate
54
53
  --incognito
55
54
  --mute-audio
@@ -59,7 +58,7 @@ module CapybaraBox
59
58
  end
60
59
 
61
60
  def chrome?
62
- @browser == :chrome
61
+ @browser == :selenium_chrome
63
62
  end
64
63
 
65
64
  def chrome_family?
@@ -67,41 +66,19 @@ module CapybaraBox
67
66
  end
68
67
 
69
68
  def chrome_headless?
70
- @browser == :chrome_headless
69
+ @browser == :selenium_chrome_headless
71
70
  end
72
71
 
73
- def configure
72
+ def configure_capybara
74
73
  Capybara.javascript_driver = @browser
75
74
  Capybara.default_max_wait_time = @max_wait_time if @max_wait_time
76
75
  end
77
76
 
78
77
  def apply_bin_path(path)
79
78
  if firefox?
80
- Selenium::WebDriver::Firefox::Binary.path = path
79
+ ::Selenium::WebDriver::Firefox::Binary.path = path
81
80
 
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
94
-
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
81
+ ::Selenium::WebDriver::Firefox::Binary.path
105
82
  end
106
83
  end
107
84
 
@@ -109,39 +86,40 @@ module CapybaraBox
109
86
  apply_arguments
110
87
  apply_preferences
111
88
 
112
- apply_bin_path @parameters[:bin_path] if @parameters[:bin_path]
113
- apply_version @parameters[:version] if version?
114
- configure_screenshot if @parameters[:screenshot]
89
+ apply_bin_path(@parameters[:bin_path]) if @parameters[:bin_path]
90
+ apply_version(@parameters[:version]) if !!@parameters[:version]
91
+
92
+ ::CapybaraBox::Screenshot.configure(@parameters[:screenshot], @browser) if @parameters[:screenshot]
115
93
 
116
- register @browser
94
+ register(@browser)
117
95
 
118
- configure
96
+ configure_capybara
119
97
  end
120
98
 
121
99
  def driver(app)
122
- opts = {}
123
- opts[:options] = options if chrome_family?
124
- opts[:http_client] = http_client if true?(ENV['CI'])
100
+ opts = {}
101
+ opts[:options] = options if chrome_family?
125
102
 
126
- Capybara::Selenium::Driver.new app, opts.merge(driver_options)
103
+ Capybara::Selenium::Driver.load_selenium
104
+
105
+ opts[:http_client] = http_client if ::CapybaraBox::Helper.true?(ENV['CI'])
106
+
107
+ Capybara::Selenium::Driver.new(app, opts.merge(driver_options))
127
108
  end
128
109
 
129
110
  def driver_options
130
111
  return @parameters[:driver_options] if @parameters[:driver_options]
131
112
 
132
113
  opts = {
133
- browser: chrome_family? ? :chrome : @browser,
134
- clear_local_storage: true,
135
- clear_session_storage: true
114
+ browser: chrome_family? ? :chrome : @browser,
115
+ clear_local_storage: true,
116
+ clear_session_storage: true,
136
117
  }
137
118
 
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
119
+ if log? && chrome_family?
120
+ opts[:service] = ::Selenium::WebDriver::Service.chrome(
121
+ args: { log_path: 'log/capybara-box.log', verbose: true }
122
+ )
145
123
  end
146
124
 
147
125
  opts
@@ -156,16 +134,16 @@ module CapybaraBox
156
134
 
157
135
  {
158
136
  open_timeout: nil,
159
- read_timeout: 120
137
+ read_timeout: 120,
160
138
  }
161
139
  end
162
140
 
163
141
  def http_client
164
- @http_client ||= Selenium::WebDriver::Remote::Http::Default.new(http_client_options)
142
+ @http_client ||= ::Selenium::WebDriver::Remote::Http::Default.new(**http_client_options)
165
143
  end
166
144
 
167
145
  def options
168
- @options ||= Selenium::WebDriver::Chrome::Options.new if chrome_family?
146
+ @options ||= ::Selenium::WebDriver::Chrome::Options.new if chrome_family?
169
147
  end
170
148
 
171
149
  def preferences
@@ -176,31 +154,17 @@ module CapybaraBox
176
154
  credentials_enable_service: false,
177
155
 
178
156
  profile: {
179
- password_manager_enabled: false
180
- }
157
+ password_manager_enabled: false,
158
+ },
181
159
  }
182
160
  end
183
161
 
184
162
  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
163
+ Capybara.register_driver(name) { |app| driver(app) }
196
164
  end
197
165
 
198
166
  def self.configure(parameters)
199
- box = new(parameters)
200
-
201
- box.create
202
-
203
- box
167
+ new(parameters).tap(&:create)
204
168
  end
205
169
 
206
170
  private
@@ -208,26 +172,7 @@ module CapybaraBox
208
172
  def log?
209
173
  return true if @parameters[:log].nil?
210
174
 
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]
175
+ ::CapybaraBox::Helper.true?(@parameters[:log])
231
176
  end
232
177
  end
233
178
  end