capybara-lockstep 0.4.0 → 1.1.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 +4 -4
- data/.github/workflows/test.yml +50 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +69 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +31 -8
- data/README.md +142 -106
- data/Rakefile +8 -0
- data/capybara-lockstep.gemspec +1 -0
- data/lib/capybara-lockstep/capybara_ext.rb +64 -9
- data/lib/capybara-lockstep/configuration.rb +60 -22
- data/lib/capybara-lockstep/errors.rb +1 -1
- data/lib/capybara-lockstep/helper.js +140 -78
- data/lib/capybara-lockstep/helper.rb +12 -3
- data/lib/capybara-lockstep/lockstep.rb +33 -6
- data/lib/capybara-lockstep/version.rb +1 -1
- metadata +18 -2
@@ -17,13 +17,22 @@ module Capybara
|
|
17
17
|
tag_options[:nonce] = options.fetch(:nonce, true)
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
js = capybara_lockstep_js + capybara_lockstep_config_js(options)
|
21
|
+
javascript_tag(js, tag_options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def capybara_lockstep_config_js(options = {})
|
25
|
+
js = ''
|
21
26
|
|
22
27
|
if (debug = options.fetch(:debug, Lockstep.debug?))
|
23
|
-
|
28
|
+
js += "\nCapybaraLockstep.debug = #{debug.to_json}"
|
29
|
+
end
|
30
|
+
|
31
|
+
if (wait_tasks = options.fetch(:wait_tasks, Lockstep.wait_tasks))
|
32
|
+
js += "\nCapybaraLockstep.waitTasks = #{wait_tasks.to_json}"
|
24
33
|
end
|
25
34
|
|
26
|
-
|
35
|
+
js
|
27
36
|
end
|
28
37
|
|
29
38
|
end
|
@@ -23,14 +23,26 @@ module Capybara
|
|
23
23
|
page.instance_variable_set(:@lockstep_synchronized, value)
|
24
24
|
end
|
25
25
|
|
26
|
-
def synchronize(lazy: false)
|
27
|
-
if (lazy && synchronized?) || synchronizing? ||
|
26
|
+
def synchronize(lazy: false, log: nil)
|
27
|
+
if (lazy && synchronized?) || synchronizing? || mode == :off
|
28
28
|
return
|
29
29
|
end
|
30
30
|
|
31
|
+
# Allow passing a log message that is only logged
|
32
|
+
# when we're actually synchronizing.
|
33
|
+
if log
|
34
|
+
self.log(log)
|
35
|
+
end
|
36
|
+
|
31
37
|
synchronize_now
|
32
38
|
end
|
33
39
|
|
40
|
+
def auto_synchronize(**options)
|
41
|
+
if mode == :auto
|
42
|
+
synchronize(**options)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
34
46
|
private
|
35
47
|
|
36
48
|
def synchronize_now
|
@@ -39,6 +51,8 @@ module Capybara
|
|
39
51
|
|
40
52
|
log 'Synchronizing'
|
41
53
|
|
54
|
+
start_time = current_seconds
|
55
|
+
|
42
56
|
begin
|
43
57
|
with_max_wait_time(timeout) do
|
44
58
|
message_from_js = evaluate_async_script(<<~JS)
|
@@ -54,6 +68,8 @@ module Capybara
|
|
54
68
|
if (protocol === 'data:' || protocol == 'about:') {
|
55
69
|
done(#{ERROR_PAGE_MISSING.to_json})
|
56
70
|
} else if (document.readyState === 'complete') {
|
71
|
+
// WebDriver always waits for the `load` event after a visit(),
|
72
|
+
// unless a different page load strategy was configured.
|
57
73
|
synchronize()
|
58
74
|
} else {
|
59
75
|
window.addEventListener('load', synchronize)
|
@@ -67,14 +83,21 @@ module Capybara
|
|
67
83
|
log(message_from_js)
|
68
84
|
else
|
69
85
|
log message_from_js
|
70
|
-
|
86
|
+
end_time = current_seconds
|
87
|
+
ms_elapsed = ((end_time.to_f - start_time) * 1000).round
|
88
|
+
log "Synchronized successfully [#{ms_elapsed} ms]"
|
71
89
|
self.synchronized = true
|
72
90
|
end
|
73
91
|
end
|
74
92
|
rescue ::Selenium::WebDriver::Error::ScriptTimeoutError
|
75
|
-
|
76
|
-
|
77
|
-
|
93
|
+
timeout_message = "Could not synchronize within #{timeout} seconds"
|
94
|
+
log timeout_message
|
95
|
+
if timeout_with == :error
|
96
|
+
raise Timeout, timeout_message
|
97
|
+
else
|
98
|
+
# Don't raise an error, this may happen if the server is slow to respond.
|
99
|
+
# We will retry on the next Capybara synchronize call.
|
100
|
+
end
|
78
101
|
rescue ::Selenium::WebDriver::Error::UnexpectedAlertOpenError
|
79
102
|
log ERROR_ALERT_OPEN
|
80
103
|
# Don't raise an error, this will happen in an innocent test.
|
@@ -124,6 +147,10 @@ module Capybara
|
|
124
147
|
# no-op
|
125
148
|
end
|
126
149
|
|
150
|
+
def current_seconds
|
151
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
152
|
+
end
|
153
|
+
|
127
154
|
end
|
128
155
|
|
129
156
|
end
|
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:
|
4
|
+
version: 1.1.0
|
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-
|
11
|
+
date: 2021-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruby2_keywords
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- henning.koch@makandra.de
|
@@ -59,9 +73,11 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
76
|
+
- ".github/workflows/test.yml"
|
62
77
|
- ".gitignore"
|
63
78
|
- ".rspec"
|
64
79
|
- ".ruby-version"
|
80
|
+
- CHANGELOG.md
|
65
81
|
- Gemfile
|
66
82
|
- Gemfile.lock
|
67
83
|
- LICENSE.txt
|