cuprite 0.14.3 → 0.15

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: e6480f3033eff59cc4f7d261e47c37ae7169ef8dd806c9b1f471d4d59be5b5a7
4
- data.tar.gz: 4d35f4b5df0457b7ea51842738e66c1b6aecc2d1753bdec5d7dbf82d28273ecd
3
+ metadata.gz: '06038d0fa139b71bda9f95ce0d353bfbd0394ff6a09f95c8dc0acb4f0b7f86f9'
4
+ data.tar.gz: 91a79735083b3949663d38d8ed1703c7955ada3ec2299830e7105348a72dd337
5
5
  SHA512:
6
- metadata.gz: c347f3f5555138a6ae5660de778ec13d9e7686007ffdf9d635b826e6fa13a42520cb137693ee0142395b7cb00efa3a5939c9ccfc6fa75411397310f0593fef33
7
- data.tar.gz: 82dd53121faab3a9f700928873d13dc42c33aae6a6065b88efcbadf02094356226ef8d72fa2d3ccfaf460a89ecfaf53950db49a57e6d9222ef9cf968eea7d6d2
6
+ metadata.gz: d1ab5955459610619f457b8ff7ac76fe761e003d20664da614f8b613da2849a65ba23c0c772753864321bf6b346a3e7d468da82dc55d816f33bbb7b13c6784ad
7
+ data.tar.gz: e618d937daea3246787cef4084f07fd7a5b2109fd7e34ff0bfa7f3d7e954c3b258539338a52378e8f9a80d96e4a8d29de3041d568b5dac8850aba61abba614c4
data/README.md CHANGED
@@ -183,6 +183,9 @@ Besides capybara screenshot method you can get image as Base64:
183
183
  ## Authorization
184
184
 
185
185
  * `page.driver.basic_authorize(user, password)`
186
+
187
+ ## Proxy
188
+
186
189
  * `page.driver.set_proxy(ip, port, type, user, password)`
187
190
 
188
191
 
@@ -192,14 +195,14 @@ Cuprite supports URL blacklisting, which allows you to prevent scripts from
192
195
  running on designated domains:
193
196
 
194
197
  ```ruby
195
- page.driver.browser.url_blacklist = ["http://www.example.com"]
198
+ page.driver.browser.url_blacklist = %r{http://www.example.com}
196
199
  ```
197
200
 
198
201
  and also URL whitelisting, which allows scripts to only run on designated
199
202
  domains:
200
203
 
201
204
  ```ruby
202
- page.driver.browser.url_whitelist = ["http://www.example.com"]
205
+ page.driver.browser.url_whitelist = %r{http://www.example.com}
203
206
  ```
204
207
 
205
208
  If you are experiencing slower run times, consider creating a URL whitelist of
@@ -12,6 +12,8 @@ module Capybara
12
12
  dismiss_prompt reset_modals] => :page
13
13
 
14
14
  attr_reader :url_blacklist, :url_whitelist
15
+ alias url_blocklist url_blacklist
16
+ alias url_allowlist url_whitelist
15
17
 
16
18
  def initialize(options = nil)
17
19
  options ||= {}
@@ -46,13 +48,15 @@ module Capybara
46
48
 
47
49
  def url_whitelist=(patterns)
48
50
  @url_whitelist = prepare_wildcards(patterns)
49
- page.network.intercept if @client && !@url_whitelist.empty?
51
+ page.network.whitelist = @url_whitelist if @client && @url_whitelist.any?
50
52
  end
53
+ alias url_allowlist= url_whitelist=
51
54
 
52
55
  def url_blacklist=(patterns)
53
56
  @url_blacklist = prepare_wildcards(patterns)
54
- page.network.intercept if @client && !@url_blacklist.empty?
57
+ page.network.blacklist = @url_blacklist if @client && @url_blacklist.any?
55
58
  end
59
+ alias url_blocklist= url_blacklist=
56
60
 
57
61
  def visit(*args)
58
62
  goto(*args)
@@ -117,24 +121,24 @@ module Capybara
117
121
  raise NotImplementedError
118
122
  end
119
123
 
120
- def drag(node, other)
124
+ def drag(node, other, steps)
121
125
  x1, y1 = node.find_position
122
126
  x2, y2 = other.find_position
123
127
 
124
128
  mouse.move(x: x1, y: y1)
125
129
  mouse.down
126
- mouse.move(x: x2, y: y2)
130
+ mouse.move(x: x2, y: y2, steps: steps)
127
131
  mouse.up
128
132
  end
129
133
 
130
- def drag_by(node, x, y)
134
+ def drag_by(node, x, y, steps)
131
135
  x1, y1 = node.find_position
132
136
  x2 = x1 + x
133
137
  y2 = y1 + y
134
138
 
135
139
  mouse.move(x: x1, y: y1)
136
140
  mouse.down
137
- mouse.move(x: x2, y: y2)
141
+ mouse.move(x: x2, y: y2, steps: steps)
138
142
  mouse.up
139
143
  end
140
144
 
@@ -199,15 +203,22 @@ module Capybara
199
203
  raise
200
204
  end
201
205
 
202
- def prepare_wildcards(wc)
203
- Array(wc).map do |wildcard|
204
- if wildcard.is_a?(Regexp)
205
- wildcard
206
+ def prepare_wildcards(patterns)
207
+ string_passed = false
208
+
209
+ Array(patterns).map do |pattern|
210
+ if pattern.is_a?(Regexp)
211
+ pattern
206
212
  else
207
- wildcard = wildcard.gsub("*", ".*")
208
- Regexp.new(wildcard, Regexp::IGNORECASE)
213
+ string_passed = true
214
+ pattern = pattern.gsub("*", ".*")
215
+ Regexp.new(pattern, Regexp::IGNORECASE)
209
216
  end
210
217
  end
218
+ ensure
219
+ if string_passed
220
+ warn "Passing strings to blacklist/whitelist is deprecated, pass regexp at #{caller(4..4).first}"
221
+ end
211
222
  end
212
223
 
213
224
  def attach_page(target_id = nil)
@@ -3,9 +3,9 @@
3
3
  require "uri"
4
4
  require "forwardable"
5
5
 
6
+ # rubocop:disable Metrics/ClassLength
6
7
  module Capybara
7
8
  module Cuprite
8
- # rubocop:disable Metrics/ClassLength
9
9
  class Driver < Capybara::Driver::Base
10
10
  DEFAULT_MAXIMIZE_SCREEN_SIZE = [1366, 768].freeze
11
11
  EXTENSION = File.expand_path("javascripts/index.js", __dir__)
@@ -14,7 +14,7 @@ module Capybara
14
14
 
15
15
  delegate %i[restart quit status_code timeout timeout= current_url title body
16
16
  window_handles close_window switch_to_window within_window window_handle
17
- back forward refresh wait_for_reload] => :browser
17
+ back forward refresh wait_for_reload viewport_size device_pixel_ratio] => :browser
18
18
  alias html body
19
19
  alias current_window_handle window_handle
20
20
  alias go_back back
@@ -32,8 +32,7 @@ module Capybara
32
32
 
33
33
  @screen_size = @options.delete(:screen_size)
34
34
  @screen_size ||= DEFAULT_MAXIMIZE_SCREEN_SIZE
35
-
36
- @options[:save_path] = File.expand_path(Capybara.save_path) if Capybara.save_path
35
+ @options[:save_path] ||= File.expand_path(Capybara.save_path) if Capybara.save_path
37
36
 
38
37
  ENV["FERRUM_DEBUG"] = "true" if ENV["CUPRITE_DEBUG"]
39
38
 
@@ -206,16 +205,7 @@ module Capybara
206
205
  end
207
206
 
208
207
  def set_proxy(host, port, user = nil, password = nil, bypass = nil)
209
- browser_options = @options.fetch(:browser_options, {})
210
- browser_options = browser_options.merge("proxy-server" => "#{host}:#{port}")
211
- browser_options = browser_options.merge("proxy-bypass-list" => bypass) if bypass
212
- @options[:browser_options] = browser_options
213
-
214
- return unless user && password
215
-
216
- browser.network.authorize(user: user, password: password, type: :proxy) do |request, _index, _total|
217
- request.continue
218
- end
208
+ @options.merge!(proxy: { host: host, port: port, user: user, password: password, bypass: bypass })
219
209
  end
220
210
 
221
211
  def headers
@@ -423,6 +413,6 @@ module Capybara
423
413
  options[:format].to_s == "pdf"
424
414
  end
425
415
  end
426
- # rubocop:enable Metrics/ClassLength
427
416
  end
428
417
  end
418
+ # rubocop:enable Metrics/ClassLength
@@ -151,7 +151,7 @@ class Cuprite {
151
151
  // call the following functions in order, if one returns false (preventDefault),
152
152
  // stop the call chain
153
153
  [
154
- () => this.keyupdowned(node, "keydown", keyCode),
154
+ () => this.keyupdowned(node, "keydown", char, keyCode),
155
155
  () => this.keypressed(node, false, false, false, false, char.charCodeAt(0), char.charCodeAt(0)),
156
156
  () => {
157
157
  this.setValue(node, node.value + char)
@@ -159,7 +159,7 @@ class Cuprite {
159
159
  }
160
160
  ].some(fn => fn())
161
161
 
162
- this.keyupdowned(node, "keyup", keyCode);
162
+ this.keyupdowned(node, "keyup", char, keyCode);
163
163
  }
164
164
  }
165
165
 
@@ -180,19 +180,22 @@ class Cuprite {
180
180
  }
181
181
 
182
182
  input(node) {
183
- let event = document.createEvent("HTMLEvents");
184
- event.initEvent("input", true, false);
183
+ let event = new InputEvent("input", { inputType: "insertText", bubbles: true, cancelable: false });
185
184
  node.dispatchEvent(event);
186
185
  }
187
186
 
188
187
  /**
189
188
  * @return {boolean} false when an event handler called preventDefault()
190
189
  */
191
- keyupdowned(node, eventName, keyCode) {
192
- let event = document.createEvent("UIEvents");
193
- event.initEvent(eventName, true, true);
194
- event.keyCode = keyCode;
195
- event.charCode = 0;
190
+ keyupdowned(node, eventName, char, keyCode) {
191
+ let event = new KeyboardEvent(
192
+ eventName, {
193
+ bubbles: true,
194
+ cancelable: true,
195
+ key: char,
196
+ keyCode: keyCode
197
+ }
198
+ );
196
199
  return !node.dispatchEvent(event);
197
200
  }
198
201
 
@@ -200,15 +203,18 @@ class Cuprite {
200
203
  * @return {boolean} false when an event handler called preventDefault()
201
204
  */
202
205
  keypressed(node, altKey, ctrlKey, shiftKey, metaKey, keyCode, charCode) {
203
- event = document.createEvent("UIEvents");
204
- event.initEvent("keypress", true, true);
205
- event.window = window;
206
- event.altKey = altKey;
207
- event.ctrlKey = ctrlKey;
208
- event.shiftKey = shiftKey;
209
- event.metaKey = metaKey;
210
- event.keyCode = keyCode;
211
- event.charCode = charCode;
206
+ let event = new KeyboardEvent(
207
+ "keypress", {
208
+ bubbles: true,
209
+ cancelable: true,
210
+ altKey: altKey,
211
+ ctrlKey: ctrlKey,
212
+ shiftKey: shiftKey,
213
+ metaKey: metaKey,
214
+ keyCode: keyCode,
215
+ charCode: charCode
216
+ }
217
+ );
212
218
  return !node.dispatchEvent(event);
213
219
  }
214
220
 
@@ -159,12 +159,16 @@ module Capybara
159
159
  command(:hover)
160
160
  end
161
161
 
162
- def drag_to(other)
163
- command(:drag, other.node)
162
+ def drag_to(other, **options)
163
+ options[:steps] ||= 1
164
+
165
+ command(:drag, other.node, options[:steps])
164
166
  end
165
167
 
166
- def drag_by(x, y)
167
- command(:drag_by, x, y)
168
+ def drag_by(x, y, **options)
169
+ options[:steps] ||= 1
170
+
171
+ command(:drag_by, x, y, options[:steps])
168
172
  end
169
173
 
170
174
  def trigger(event)
@@ -17,6 +17,7 @@ module Capybara
17
17
  @frame_stack = []
18
18
  @accept_modal = []
19
19
  @modal_messages = []
20
+ @modal_response = nil
20
21
  super
21
22
  end
22
23
 
@@ -130,35 +131,13 @@ module Capybara
130
131
 
131
132
  private
132
133
 
133
- # rubocop:disable Metrics/CyclomaticComplexity
134
- # rubocop:disable Metrics/PerceivedComplexity
135
- # rubocop:disable Style/GuardClause
136
134
  def prepare_page
137
135
  super
138
136
 
139
- network.intercept if !Array(@browser.url_whitelist).empty? ||
140
- !Array(@browser.url_blacklist).empty?
141
-
142
- on(:request) do |request, index, total|
143
- if @browser.url_blacklist && !@browser.url_blacklist.empty?
144
- if @browser.url_blacklist.any? { |r| request.match?(r) }
145
- request.abort and next
146
- else
147
- request.continue and next
148
- end
149
- elsif @browser.url_whitelist && !@browser.url_whitelist.empty?
150
- if @browser.url_whitelist.any? { |r| request.match?(r) }
151
- request.continue and next
152
- else
153
- request.abort and next
154
- end
155
- elsif index + 1 < total
156
- # There are other callbacks that may handle this request
157
- next
158
- else
159
- # If there are no callbacks then just continue
160
- request.continue
161
- end
137
+ if @browser.url_blacklist.any?
138
+ network.blacklist = @browser.url_blacklist
139
+ elsif @browser.url_whitelist.any?
140
+ network.whitelist = @browser.url_whitelist
162
141
  end
163
142
 
164
143
  on("Page.javascriptDialogOpening") do |params|
@@ -181,9 +160,6 @@ module Capybara
181
160
  command("Page.handleJavaScriptDialog", **options)
182
161
  end
183
162
  end
184
- # rubocop:enable Metrics/CyclomaticComplexity
185
- # rubocop:enable Metrics/PerceivedComplexity
186
- # rubocop:enable Style/GuardClause
187
163
 
188
164
  def find_position(node, **options)
189
165
  node.find_position(**options)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Capybara
4
4
  module Cuprite
5
- VERSION = "0.14.3"
5
+ VERSION = "0.15"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuprite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.3
4
+ version: '0.15'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Vorotilin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-12 00:00:00.000000000 Z
11
+ date: 2023-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -30,140 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.13.0
33
+ version: 0.14.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.13.0
41
- - !ruby/object:Gem::Dependency
42
- name: byebug
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '11.1'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '11.1'
55
- - !ruby/object:Gem::Dependency
56
- name: chunky_png
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.4'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.4'
69
- - !ruby/object:Gem::Dependency
70
- name: image_size
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.0'
83
- - !ruby/object:Gem::Dependency
84
- name: launchy
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '2.5'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '2.5'
97
- - !ruby/object:Gem::Dependency
98
- name: pdf-reader
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '2.5'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '2.5'
111
- - !ruby/object:Gem::Dependency
112
- name: puma
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '4.3'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '4.3'
125
- - !ruby/object:Gem::Dependency
126
- name: rake
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '13.0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '13.0'
139
- - !ruby/object:Gem::Dependency
140
- name: rspec
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '3.10'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '3.10'
153
- - !ruby/object:Gem::Dependency
154
- name: sinatra
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '2.1'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: '2.1'
40
+ version: 0.14.0
167
41
  description: Cuprite is a driver for Capybara that allows you to run your tests on
168
42
  a headless Chrome browser
169
43
  email:
@@ -189,7 +63,7 @@ licenses:
189
63
  metadata:
190
64
  homepage_uri: https://cuprite.rubycdp.com/
191
65
  bug_tracker_uri: https://github.com/rubycdp/cuprite/issues
192
- documentation_uri: https://github.com/rubycdp/cuprite/blob/master/README.md
66
+ documentation_uri: https://github.com/rubycdp/cuprite/blob/main/README.md
193
67
  source_code_uri: https://github.com/rubycdp/cuprite
194
68
  rubygems_mfa_required: 'true'
195
69
  post_install_message:
@@ -200,14 +74,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
200
74
  requirements:
201
75
  - - ">="
202
76
  - !ruby/object:Gem::Version
203
- version: 2.6.0
77
+ version: 2.7.0
204
78
  required_rubygems_version: !ruby/object:Gem::Requirement
205
79
  requirements:
206
80
  - - ">="
207
81
  - !ruby/object:Gem::Version
208
82
  version: '0'
209
83
  requirements: []
210
- rubygems_version: 3.3.7
84
+ rubygems_version: 3.4.13
211
85
  signing_key:
212
86
  specification_version: 4
213
87
  summary: Headless Chrome driver for Capybara