capybara-lockstep 0.3.2 → 0.3.3
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 +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +3 -1
- data/README.md +6 -6
- data/lib/capybara-lockstep/helper.js +0 -14
- data/lib/capybara-lockstep/lockstep.rb +33 -15
- data/lib/capybara-lockstep/logging.rb +1 -1
- data/lib/capybara-lockstep/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86fa6ca6223224f8ac4b53c973cf961287964d11b129d8aa89b7b4dc81d4bba4
|
4
|
+
data.tar.gz: f250e201b8ef467fd46d1e30654d8e2c88366c23ad8cb314e1031cb44268dcd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 846816f82797d02dc81869e449afaf99c3fdfe89682d6584a56b3416cbb5942138a38ae457dfebcbb4fc7f20ed2673766a02287911b258445c5a9b800d613f9c
|
7
|
+
data.tar.gz: 30064e290e2caed298e5868b0f1cb9c1f5aa34444895fa8cefd4d283b0433528dd1ee7793526f0652fbc11511ed3e50e9a6eb999b00f6a898411480616422199
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
capybara-lockstep (0.3.
|
4
|
+
capybara-lockstep (0.3.3)
|
5
5
|
activesupport (>= 3.2)
|
6
6
|
capybara (>= 2.0)
|
7
7
|
selenium-webdriver (>= 3)
|
@@ -17,6 +17,7 @@ GEM
|
|
17
17
|
zeitwerk (~> 2.3)
|
18
18
|
addressable (2.7.0)
|
19
19
|
public_suffix (>= 2.0.2, < 5.0)
|
20
|
+
byebug (11.1.3)
|
20
21
|
capybara (3.35.3)
|
21
22
|
addressable
|
22
23
|
mini_mime (>= 0.1.3)
|
@@ -70,6 +71,7 @@ PLATFORMS
|
|
70
71
|
ruby
|
71
72
|
|
72
73
|
DEPENDENCIES
|
74
|
+
byebug
|
73
75
|
capybara-lockstep!
|
74
76
|
rake (~> 13.0)
|
75
77
|
rspec (~> 3.0)
|
data/README.md
CHANGED
@@ -173,9 +173,9 @@ capybara-lockstep will automatically patch Capybara to wait for the browser afte
|
|
173
173
|
Run your test suite to see if integration was successful and whether stability improves. During validation we recommend to activate `Capybara::Lockstep.debug = true` in your `spec_helper.rb` (RSpec) or `env.rb` (Cucumber). You should see messages like this in your console:
|
174
174
|
|
175
175
|
```text
|
176
|
-
[
|
177
|
-
[
|
178
|
-
[
|
176
|
+
[capybara-lockstep] Synchronizing
|
177
|
+
[capybara-lockstep] Finished waiting for JavaScript
|
178
|
+
[capybara-lockstep] Synchronized successfully
|
179
179
|
```
|
180
180
|
|
181
181
|
Note that you may see some failures from tests with wrong assertions, which sometimes passed due to lucky timing.
|
@@ -201,9 +201,9 @@ Capybara::Lockstep.debug = true
|
|
201
201
|
You should now see messages like this during your test runs:
|
202
202
|
|
203
203
|
```
|
204
|
-
[
|
205
|
-
[
|
206
|
-
[
|
204
|
+
[capybara-lockstep] Synchronizing
|
205
|
+
[capybara-lockstep] Finished waiting for JavaScript
|
206
|
+
[capybara-lockstep] Synchronized successfully
|
207
207
|
```
|
208
208
|
|
209
209
|
You may also configure logging to an existing logger object:
|
@@ -95,19 +95,6 @@ window.CapybaraLockstep = (function() {
|
|
95
95
|
startWorkForMicrotask()
|
96
96
|
}
|
97
97
|
|
98
|
-
function trackHistory() {
|
99
|
-
['popstate'].forEach(function(eventType) {
|
100
|
-
document.addEventListener(eventType, onHistoryEvent)
|
101
|
-
})
|
102
|
-
}
|
103
|
-
|
104
|
-
function onHistoryEvent() {
|
105
|
-
// After calling history.back() or history.forward() the popstate event will *not*
|
106
|
-
// fire synchronously. It will also not fire in the next task. Chrome sometimes fires
|
107
|
-
// it after 10ms, but sometimes it takes longer.
|
108
|
-
startWorkForTime(100)
|
109
|
-
}
|
110
|
-
|
111
98
|
function trackDynamicScripts() {
|
112
99
|
if (!window.MutationObserver) {
|
113
100
|
return
|
@@ -201,7 +188,6 @@ window.CapybaraLockstep = (function() {
|
|
201
188
|
trackFetch()
|
202
189
|
trackXHR()
|
203
190
|
trackInteraction()
|
204
|
-
trackHistory()
|
205
191
|
trackDynamicScripts()
|
206
192
|
trackJQuery()
|
207
193
|
trackHydration()
|
@@ -1,10 +1,16 @@
|
|
1
1
|
module Capybara
|
2
2
|
module Lockstep
|
3
|
+
ERROR_SNIPPET_MISSING = 'Cannot synchronize: capybara-lockstep JavaScript snippet is missing'
|
4
|
+
ERROR_PAGE_MISSING = 'Cannot synchronize before initial Capybara visit'
|
5
|
+
ERROR_ALERT_OPEN = 'Cannot synchronize while an alert is open'
|
6
|
+
ERROR_NAVIGATED_AWAY = "Browser navigated away while synchronizing"
|
7
|
+
|
3
8
|
class << self
|
4
9
|
include Configuration
|
5
10
|
include Logging
|
6
11
|
|
7
|
-
attr_accessor :
|
12
|
+
attr_accessor :synchronizing
|
13
|
+
alias synchronizing? synchronizing
|
8
14
|
|
9
15
|
def synchronized?
|
10
16
|
value = page.instance_variable_get(:@lockstep_synchronized)
|
@@ -17,16 +23,19 @@ module Capybara
|
|
17
23
|
page.instance_variable_set(:@lockstep_synchronized, value)
|
18
24
|
end
|
19
25
|
|
20
|
-
ERROR_SNIPPET_MISSING = 'Cannot synchronize: Capybara::Lockstep JavaScript snippet is missing on page'
|
21
|
-
ERROR_PAGE_MISSING = 'Cannot synchronize before initial Capybara visit'
|
22
|
-
ERROR_ALERT_OPEN = 'Cannot synchronize while an alert is open'
|
23
|
-
|
24
26
|
def synchronize(lazy: false)
|
25
|
-
if (lazy && synchronized?) ||
|
27
|
+
if (lazy && synchronized?) || synchronizing? || disabled?
|
26
28
|
return
|
27
29
|
end
|
28
30
|
|
29
|
-
|
31
|
+
synchronize_now
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def synchronize_now
|
37
|
+
self.synchronizing = true
|
38
|
+
self.synchronized = false
|
30
39
|
|
31
40
|
log 'Synchronizing'
|
32
41
|
|
@@ -54,10 +63,8 @@ module Capybara
|
|
54
63
|
case message_from_js
|
55
64
|
when ERROR_PAGE_MISSING
|
56
65
|
log(message_from_js)
|
57
|
-
self.synchronized = false
|
58
66
|
when ERROR_SNIPPET_MISSING
|
59
67
|
log(message_from_js)
|
60
|
-
self.synchronized = false
|
61
68
|
else
|
62
69
|
log message_from_js
|
63
70
|
log "Synchronized successfully"
|
@@ -66,19 +73,30 @@ module Capybara
|
|
66
73
|
end
|
67
74
|
rescue ::Selenium::WebDriver::Error::UnexpectedAlertOpenError
|
68
75
|
log ERROR_ALERT_OPEN
|
69
|
-
@synchronized = false
|
70
76
|
# Don't raise an error, this will happen in an innocent test.
|
71
77
|
# We will retry on the next Capybara synchronize call.
|
78
|
+
rescue ::Selenium::WebDriver::Error::JavascriptError => e
|
79
|
+
# When the URL changes while a script is running, my current selenium-webdriver
|
80
|
+
# raises a Selenium::WebDriver::Error::JavascriptError with the message:
|
81
|
+
# "javascript error: document unloaded while waiting for result".
|
82
|
+
# We will retry on the next Capybara synchronize call, by then we should see
|
83
|
+
# the new page.
|
84
|
+
if e.message.include?('unload')
|
85
|
+
log ERROR_NAVIGATED_AWAY
|
86
|
+
else
|
87
|
+
unhandled_synchronize_error(e)
|
88
|
+
end
|
72
89
|
rescue StandardError => e
|
73
|
-
|
74
|
-
@synchronized = false
|
75
|
-
raise e
|
90
|
+
unhandled_synchronize_error(e)
|
76
91
|
ensure
|
77
|
-
|
92
|
+
self.synchronizing = false
|
78
93
|
end
|
79
94
|
end
|
80
95
|
|
81
|
-
|
96
|
+
def unhandled_synchronize_error(e)
|
97
|
+
log "#{e.class.name} while synchronizing: #{e.message}"
|
98
|
+
raise e
|
99
|
+
end
|
82
100
|
|
83
101
|
def page
|
84
102
|
Capybara.current_session
|
@@ -3,7 +3,7 @@ module Capybara
|
|
3
3
|
module Logging
|
4
4
|
def log(message)
|
5
5
|
if debug? && message.present?
|
6
|
-
message = "[
|
6
|
+
message = "[capybara-lockstep] #{message}"
|
7
7
|
if @debug.respond_to?(:debug)
|
8
8
|
# If someone set Capybara::Lockstep to a logger, use that
|
9
9
|
@debug.debug(message)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-lockstep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henning Koch
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
|
-
rubygems_version: 3.2.
|
103
|
+
rubygems_version: 3.2.6
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
106
|
summary: Synchronize Capybara commands with client-side JavaScript and AJAX requests
|