capybara-lockstep 2.3.2 → 2.4.0

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: cc60ce49170390b7a2160291bcee08a08a22bceacaf58e12b2f2bc5ebadf484e
4
- data.tar.gz: dd6c60d318fe9f336462a3dcff507acf0120036d8ea160a97a5125ab94dc4248
3
+ metadata.gz: eb5ab18d6ec37825a825c3da9fdde70e7203b68609242a8a4738cb3034a0c3b2
4
+ data.tar.gz: d74acc6c1c2b73bbeea372f91d54068c548723d28e46cf5a4a01520004d4ef1e
5
5
  SHA512:
6
- metadata.gz: fcf26ef14e209a4fd8f6353c129fe9b88b97feb58dd787ebccddc3e19980802ebec1403a374cf580c1798ecf3bc30e365eba1218f40d3b0af3bbbc6f80ca9904
7
- data.tar.gz: f8db9ee7dbc655724cab11b6f2e3a181ae182579ba78b5f193174b7a78951f407275e49dbceec0b10b4f41cb9abbdc28233a271b781ba686f4bc030e2b932c35
6
+ metadata.gz: d67cc0d38dc1ab56ff728010cfde78016b357ac5964ab70ed18b7d8173599129eb9ff06bfd4a5e84754698cc568bb14e78378334910afcdabb7a1055f8f1f1ea
7
+ data.tar.gz: 8a8e007d57eb6f2e661a158156aefe4844d26f1de755939040229da146ae32e850b26aacb674cbd02de0ddd196c8e4ee2a39d8b8cb6b526af85ad96eda2d930f
data/CHANGELOG.md CHANGED
@@ -13,6 +13,13 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
13
13
  -
14
14
 
15
15
 
16
+ # 2.4.0 - 2026-10-15
17
+
18
+ ## Compatible changes
19
+
20
+ - Skip the check for an open alert before synchronizing when the Selenium driver ignores unhandled prompts (`unhandled_prompt_behavior: 'ignore'` or `{ default: 'ignore' }`). Such a driver keeps the alert open while synchronizing, so the check only cost an additional roundtrip to the browser. Configure this with the new option `Capybara::Lockstep.check_alerts` (`true`, `false` or `nil` for auto-detection).
21
+
22
+
16
23
  # 2.3.2 - 2026-09-11
17
24
 
18
25
  ## Compatible changes
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capybara-lockstep (2.3.2)
4
+ capybara-lockstep (2.4.0)
5
5
  activesupport (>= 7.0)
6
6
  capybara (>= 3.0)
7
7
 
@@ -65,7 +65,7 @@ GEM
65
65
  mustermann (3.0.0)
66
66
  ruby2_keywords (~> 0.0.1)
67
67
  nio4r (2.6.1)
68
- nokogiri (1.15.5)
68
+ nokogiri (1.19.4)
69
69
  mini_portile2 (~> 2.8.2)
70
70
  racc (~> 1.4)
71
71
  ostruct (0.6.3)
data/README.md CHANGED
@@ -184,7 +184,7 @@ use Capybara::Lockstep::Middleware
184
184
  ### Configuring Selenium WebDriver (recommended)
185
185
 
186
186
  By default, webdrivers will automatically dismiss any user prompts (like alerts) when trying to perform an action.
187
- While capybara-lockstep carefully detects alerts before synchronizing, and will skip interaction with the browser to avoid accidentally dismissing alerts, it can not synchronize around some rare race conditions.
187
+ With this default, capybara-lockstep checks for an open alert before synchronizing, and will skip interaction with the browser to avoid accidentally dismissing alerts. However, it can not synchronize around some rare race conditions, and the check costs an additional roundtrip to the browser.
188
188
 
189
189
  [We recommend](https://makandracards.com/makandra/617366-how-to-configure-selenium-webdriver-to-not-automatically-close-alerts-or-other-browser-dialogs) you configure your webdriver to not automatically dismiss user prompts by setting the "unhandled prompt behavior" capability to [`ignore`](https://w3c.github.io/webdriver/#dfn-known-prompt-handling-approaches-table). Using "ignore", errors are raised like with the default behavior, but user prompts are kept open.
190
190
 
@@ -199,6 +199,18 @@ Capybara.register_driver(:selenium) do |app|
199
199
  end
200
200
  ```
201
201
 
202
+ When your driver ignores user prompts, capybara-lockstep no longer checks for an open alert before synchronizing. The driver keeps the alert open and capybara-lockstep retries synchronization on the next Capybara command. This also works when you configure the capability by prompt type, e.g. `unhandled_prompt_behavior: { default: 'ignore' }`, as long as alerts, confirms and prompts are all ignored. Note that selenium-webdriver 4.35 and older convert such a map to a string when passed through `Options`. On these versions, pass it as `Selenium::WebDriver::Remote::Capabilities.new(unhandled_prompt_behavior: { default: 'ignore' })` alongside your options.
203
+
204
+ You can override this detection:
205
+
206
+ ```ruby
207
+ Capybara::Lockstep.check_alerts = true # always check for an open alert before synchronizing
208
+ Capybara::Lockstep.check_alerts = false # never check for an open alert before synchronizing
209
+ Capybara::Lockstep.check_alerts = nil # check unless the driver ignores user prompts (default)
210
+ ```
211
+
212
+ Only disable the check if your driver keeps alerts open, otherwise synchronization will dismiss them.
213
+
202
214
  ### Verify successful integration
203
215
 
204
216
  capybara-lockstep will automatically patch Capybara to wait for the browser after every command.
@@ -49,9 +49,9 @@ module Capybara
49
49
  return
50
50
  end
51
51
 
52
- # Running the synchronization script while an alert is open would close the alert,
53
- # most likely causing subsequent expectations to fail.
54
- if alert_present?
52
+ # Unless the driver ignores unhandled prompts, running the synchronization script while an alert
53
+ # is open would close the alert, most likely causing subsequent expectations to fail.
54
+ if check_alerts? && alert_present?
55
55
  log ERROR_ALERT_OPEN
56
56
  # Don't raise an error, this will happen in an innocent test.
57
57
  # We will retry on the next Capybara synchronize call.
@@ -110,6 +110,10 @@ module Capybara
110
110
  raise e
111
111
  end
112
112
 
113
+ def check_alerts?
114
+ Lockstep.check_alerts?
115
+ end
116
+
113
117
  def timeout
114
118
  Lockstep.timeout
115
119
  end
@@ -18,6 +18,16 @@ module Capybara
18
18
  @timeout_with = action&.to_sym
19
19
  end
20
20
 
21
+ def check_alerts?
22
+ # A driver that ignores unhandled prompts keeps an alert open while running our synchronization script.
23
+ # It raises an UnexpectedAlertOpenError instead, which we handle like an open alert.
24
+ @check_alerts.nil? ? !unhandled_prompts_ignored? : @check_alerts
25
+ end
26
+
27
+ def check_alerts=(value)
28
+ @check_alerts = value
29
+ end
30
+
21
31
  def debug
22
32
  @debug.nil? ? false : @debug
23
33
  end
@@ -25,6 +25,23 @@ module Capybara
25
25
  false
26
26
  end
27
27
 
28
+ def unhandled_prompts_ignored?
29
+ return false unless selenium_driver?
30
+
31
+ # The capabilities were returned when the session was created, so this does not talk to the browser.
32
+ # The behavior is either a string ("ignore") or a map by prompt type ({ "default" => "ignore" }).
33
+ behavior = page.driver.browser.capabilities[:unhandled_prompt_behavior]
34
+
35
+ if behavior.is_a?(Hash)
36
+ # We don't consider "beforeUnload" prompts: the string form doesn't apply to them, WebDriver accepts them instead.
37
+ %w[alert confirm prompt].all? do |type|
38
+ behavior.fetch(type) { behavior['default'] } == 'ignore'
39
+ end
40
+ else
41
+ behavior == 'ignore'
42
+ end
43
+ end
44
+
28
45
  def selenium_driver?
29
46
  defined?(Capybara::Selenium::Driver) && driver.is_a?(Capybara::Selenium::Driver)
30
47
  end
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Lockstep
3
- VERSION = "2.3.2"
3
+ VERSION = "2.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-lockstep
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch