cuprite 0.15.1 → 0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78b7dde58d02147e2985473da0a7527d338ff086e4a4aaf0fd9302e5faf3ee11
4
- data.tar.gz: 777726c6161975950df923a305b0bdb9da54b5531b7a5339ed0d4beaf264beb6
3
+ metadata.gz: 70fb54b637d782b831b70e9894f65d95deb839abca0dff8355245c1dfaf7f81e
4
+ data.tar.gz: f909e93716a7bffb69e35cf4dbc783c13e4acc9d13a226f2ee5d85d2c49cc427
5
5
  SHA512:
6
- metadata.gz: 04e88a47d9d2d2df68ad11dca8224f6d24001340b1743f538e6fdb64e818381037da7987b9db25284336b469c986d9d9e883192743749c4c6cad6c43adc160a1
7
- data.tar.gz: a059dae9790af13c8a56999d6d76d5920e863e217b346a721a4051f0cc786e295a35c0e574c00e425b87e2d0c7a8b140c991183ab3246d1678566318745c9ecf
6
+ metadata.gz: 521a59b3852efa9a3e770090e56bdcbc508da3465414bc2a72300f10757380103d9b6cb668a426d0af3173a89ad02f5cbf78666d9d33b19235d68f2e955182d4
7
+ data.tar.gz: dd50d8cd20886faa16e5372659c25792847286c954ea1c5a951b5a504d87cb06897e2e0bacd7d86457a6f72529054d99bc3773e163a06d926ef0c21a98cc7375
data/README.md CHANGED
@@ -122,13 +122,17 @@ be automatically cleared at the end of the test.
122
122
 
123
123
  ## Network traffic
124
124
 
125
- * `page.driver.network_traffic` Inspect network traffic (loaded resources) on
126
- the current page. This returns an array of request objects.
125
+ * `page.driver.network_traffic` allows you to inspect network traffic (i.e., loaded resources) on the current page. It returns an array of `Ferrum::Network::Exchange` objects, each representing a network request/response exchange. You can query both the request and response details of each exchange.
127
126
 
128
127
  ```ruby
129
- page.driver.network_traffic # => [Request, ...]
130
- request = page.driver.network_traffic.first
131
- request.response
128
+ # Retrieve all network exchanges
129
+ network_traffic = page.driver.network_traffic
130
+
131
+ # Access the first exchange
132
+ first_exchange = network_traffic.first
133
+
134
+ # Inspect the response of the first request
135
+ response = first_exchange.response
132
136
  ```
133
137
 
134
138
  * `page.driver.wait_for_network_idle` Natively waits for network idle and if
@@ -183,27 +187,29 @@ Besides capybara screenshot method you can get image as Base64:
183
187
 
184
188
  ## Proxy
185
189
 
186
- * `page.driver.set_proxy(ip, port, type, user, password)`
190
+ * `page.driver.set_proxy(ip, port, user, password)`
187
191
 
188
192
 
189
- ## URL Blacklisting & Whitelisting
193
+ ## URL Blocklisting & Allowlisting
190
194
 
191
- Cuprite supports URL blacklisting, which allows you to prevent scripts from
195
+ Cuprite supports URL blocklisting, which allows you to prevent scripts from
192
196
  running on designated domains:
193
197
 
194
198
  ```ruby
195
- page.driver.browser.url_blacklist = %r{http://www.example.com}
199
+ page.driver.browser.url_blocklist = %r{http://www.example.com}
196
200
  ```
197
201
 
198
- and also URL whitelisting, which allows scripts to only run on designated
202
+ and also URL allowlisting, which allows scripts to only run on designated
199
203
  domains:
200
204
 
201
205
  ```ruby
202
- page.driver.browser.url_whitelist = %r{http://www.example.com}
206
+ page.driver.browser.url_allowlist = %r{http://www.example.com}
203
207
  ```
204
208
 
205
- If you are experiencing slower run times, consider creating a URL whitelist of
206
- domains that are essential or a blacklist of domains that are not essential,
209
+ For legacy support, `url_blacklist=` and `url_whitelist=` continue to work respectively.
210
+
211
+ If you are experiencing slower run times, consider creating a URL allowlist of
212
+ domains that are essential or a blocklist of domains that are not essential,
207
213
  such as ad networks or analytics, to your testing environment.
208
214
 
209
215
  ## License
@@ -139,26 +139,33 @@ module Capybara
139
139
  raise NotImplementedError
140
140
  end
141
141
 
142
- def drag(node, other, steps, delay = nil)
142
+ def drag(node, other, steps, delay = nil, scroll = true)
143
143
  x1, y1 = node.find_position
144
- x2, y2 = other.find_position
145
144
 
146
145
  mouse.move(x: x1, y: y1)
147
146
  mouse.down
148
147
  sleep delay if delay
148
+
149
+ other.scroll_into_view if scroll
150
+
151
+ x2, y2 = other.find_position
149
152
  mouse.move(x: x2, y: y2, steps: steps)
153
+
150
154
  mouse.up
151
155
  end
152
156
 
153
- def drag_by(node, x, y, steps, delay = nil)
157
+ def drag_by(node, dx, dy, steps, delay = nil, scroll = true)
154
158
  x1, y1 = node.find_position
155
- x2 = x1 + x
156
- y2 = y1 + y
157
159
 
158
160
  mouse.move(x: x1, y: y1)
159
161
  mouse.down
162
+
160
163
  sleep delay if delay
161
- mouse.move(x: x2, y: y2, steps: steps)
164
+
165
+ evaluate("window.scrollBy(#{dx}, #{dy})") if scroll # should be extracted to Mouse#scroll_by in ferrum
166
+
167
+ x2, y2 = node.find_position
168
+ mouse.move(x: x2 + dx, y: y2 + dy, steps: steps)
162
169
  mouse.up
163
170
  end
164
171
 
@@ -203,6 +210,10 @@ module Capybara
203
210
  evaluate_on(node: node, expression: "_cuprite.path(this)")
204
211
  end
205
212
 
213
+ def obscured?(node)
214
+ evaluate_on(node: node, expression: "_cuprite.isObscured(this)")
215
+ end
216
+
206
217
  def all_text(node)
207
218
  node.text
208
219
  end
@@ -40,7 +40,7 @@ module Capybara
40
40
  end
41
41
 
42
42
  def expires
43
- Time.at(@attributes["expires"]) if (@attributes["expires"]).positive?
43
+ Time.at(@attributes["expires"]) if @attributes["expires"].positive?
44
44
  end
45
45
  end
46
46
  end
@@ -251,7 +251,8 @@ module Capybara
251
251
 
252
252
  def remove_cookie(name, **options)
253
253
  options[:domain] = default_domain if options.empty?
254
- browser.cookies.remove(**options.merge(name: name))
254
+ options = options.merge(name: name)
255
+ browser.cookies.remove(**options)
255
256
  end
256
257
 
257
258
  def clear_cookies
@@ -115,6 +115,35 @@ class Cuprite {
115
115
  return `//${selectors.join("/")}`;
116
116
  }
117
117
 
118
+ /**
119
+ * Returns true if the node is obscured in the viewport.
120
+ *
121
+ * @param {Element} node
122
+ * @return {boolean} true if the node is obscured, false otherwise
123
+ */
124
+ isObscured(node) {
125
+ let win = window;
126
+ let rect = node.getBoundingClientRect();
127
+ let px = rect.left + rect.width / 2;
128
+ let py = rect.top + rect.height / 2;
129
+
130
+ while (win) {
131
+ let topNode = win.document.elementFromPoint(px, py);
132
+
133
+ if (node !== topNode && !node.contains(topNode)) return true;
134
+
135
+ node = win.frameElement;
136
+ if (!node) return false;
137
+
138
+ rect = node.getBoundingClientRect();
139
+ px = rect.left + px;
140
+ py = rect.top + py;
141
+ win = win.parent;
142
+ }
143
+
144
+ return false;
145
+ }
146
+
118
147
  set(node, value) {
119
148
  if (node.readOnly) return;
120
149
 
@@ -110,7 +110,7 @@ module Capybara
110
110
  command(:set, value.to_s)
111
111
  elsif self[:isContentEditable]
112
112
  command(:delete_text)
113
- send_keys(value.to_s)
113
+ click.type(value.to_s)
114
114
  end
115
115
  end
116
116
 
@@ -161,14 +161,16 @@ module Capybara
161
161
 
162
162
  def drag_to(other, **options)
163
163
  options[:steps] ||= 1
164
+ options[:scroll] = true unless options.key?(:scroll)
164
165
 
165
- command(:drag, other.node, options[:steps], options[:delay])
166
+ command(:drag, other.node, options[:steps], options[:delay], options[:scroll])
166
167
  end
167
168
 
168
169
  def drag_by(x, y, **options)
169
170
  options[:steps] ||= 1
171
+ options[:scroll] = true unless options.key?(:scroll)
170
172
 
171
- command(:drag_by, x, y, options[:steps], options[:delay])
173
+ command(:drag_by, x, y, options[:steps], options[:delay], options[:scroll])
172
174
  end
173
175
 
174
176
  def trigger(event)
@@ -211,6 +213,10 @@ module Capybara
211
213
  command(:path)
212
214
  end
213
215
 
216
+ def obscured?
217
+ command(:obscured?)
218
+ end
219
+
214
220
  def inspect
215
221
  %(#<#{self.class} @node=#{@node.inspect}>)
216
222
  end
@@ -123,7 +123,6 @@ module Capybara
123
123
  @frame_stack = []
124
124
  else
125
125
  @frame_stack << handle
126
- inject_extensions
127
126
  end
128
127
  end
129
128
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Capybara
4
4
  module Cuprite
5
- VERSION = "0.15.1"
5
+ VERSION = "0.16"
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.15.1
4
+ version: '0.16'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Vorotilin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-15 00:00:00.000000000 Z
11
+ date: 2025-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.15.0
33
+ version: 0.16.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.15.0
40
+ version: 0.16.0
41
41
  description: Cuprite is a driver for Capybara that allows you to run your tests on
42
42
  a headless Chrome browser
43
43
  email:
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  requirements: []
85
- rubygems_version: 3.5.11
85
+ rubygems_version: 3.5.22
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: Headless Chrome driver for Capybara