capybara-lockstep 0.5.0 → 0.6.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/Gemfile.lock +4 -2
- data/lib/capybara-lockstep/capybara_ext.rb +56 -5
- data/lib/capybara-lockstep/helper.js +1 -1
- data/lib/capybara-lockstep/lockstep.rb +9 -1
- data/lib/capybara-lockstep/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef423eecbf9d793e932d66b056feee733835efa0387ec6740fecb2975585f95e
|
4
|
+
data.tar.gz: 55e8872d7b892567797ded6fb67ed17500bc3daf29e11fbf4fee45588cdab9f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd14f06c4b820e5e0dda482438d282e7a856c790ef0952f44c28a6f18dd9fb863323f782b8e21d9846ec9660fcf804ea257e5c05640482e777408e71ab820ccd
|
7
|
+
data.tar.gz: dc64900722119cc945b6b22113b63d13706d0cfb2ae39e0b8411c62aad0cbfc716ff84433189521f685219ee85f48554852df1204ce0fad1fed4e7f19b1d3cf0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
capybara-lockstep (0.
|
4
|
+
capybara-lockstep (0.6.0)
|
5
5
|
activesupport (>= 3.2)
|
6
6
|
capybara (>= 2.0)
|
7
7
|
selenium-webdriver (>= 3)
|
@@ -32,8 +32,10 @@ GEM
|
|
32
32
|
i18n (1.8.9)
|
33
33
|
concurrent-ruby (~> 1.0)
|
34
34
|
mini_mime (1.0.2)
|
35
|
+
mini_portile2 (2.5.0)
|
35
36
|
minitest (5.14.4)
|
36
|
-
nokogiri (1.11.1
|
37
|
+
nokogiri (1.11.1)
|
38
|
+
mini_portile2 (~> 2.5.0)
|
37
39
|
racc (~> 1.4)
|
38
40
|
public_suffix (4.0.6)
|
39
41
|
racc (1.5.2)
|
@@ -12,13 +12,18 @@ module Capybara
|
|
12
12
|
|
13
13
|
if visiting_remote_url
|
14
14
|
# We're about to leave this screen, killing all in-flight requests.
|
15
|
-
|
15
|
+
# Give pending form submissions etc. a chance to finish before we tear down
|
16
|
+
# the browser environment.
|
17
|
+
#
|
18
|
+
# We force a non-lazy synchronization so we pick up all client-side changes
|
19
|
+
# that have not been caused by Capybara commands.
|
20
|
+
Lockstep.synchronize(lazy: false)
|
16
21
|
end
|
17
22
|
|
18
23
|
super(*args, &block).tap do
|
19
24
|
if visiting_remote_url
|
20
|
-
#
|
21
|
-
|
25
|
+
# We haven't yet synchronized the new screen.
|
26
|
+
Lockstep.synchronized = false
|
22
27
|
end
|
23
28
|
end
|
24
29
|
end
|
@@ -26,11 +31,57 @@ module Capybara
|
|
26
31
|
end
|
27
32
|
end
|
28
33
|
|
29
|
-
|
30
34
|
Capybara::Session.class_eval do
|
31
35
|
prepend Capybara::Lockstep::VisitWithWaiting
|
32
36
|
end
|
33
37
|
|
38
|
+
module Capybara
|
39
|
+
module Lockstep
|
40
|
+
module SynchronizeAroundScriptMethod
|
41
|
+
|
42
|
+
def synchronize_around_script_method(meth)
|
43
|
+
mod = Module.new do
|
44
|
+
define_method meth do |script, *args, &block|
|
45
|
+
# Synchronization uses execute_script itself, so don't synchronize when
|
46
|
+
# we're already synchronizing.
|
47
|
+
if !Lockstep.synchronizing?
|
48
|
+
# It's generally a good idea to synchronize before a JavaScript wants
|
49
|
+
# to access or observe an earlier state change.
|
50
|
+
#
|
51
|
+
# In case the given script navigates away (with `location.href = url`,
|
52
|
+
# `history.back()`, etc.) we would kill all in-flight requests. For this case
|
53
|
+
# we force a non-lazy synchronization so we pick up all client-side changes
|
54
|
+
# that have not been caused by Capybara commands.
|
55
|
+
script_may_navigate_away = script =~ /\b(location|history)\b/
|
56
|
+
Lockstep.log "Synchronizing before script: #{script}"
|
57
|
+
Lockstep.synchronize(lazy: !script_may_navigate_away)
|
58
|
+
end
|
59
|
+
|
60
|
+
super(script, *args, &block).tap do
|
61
|
+
if !Lockstep.synchronizing?
|
62
|
+
# We haven't yet synchronized with whatever changes the JavaScript
|
63
|
+
# did on the frontend.
|
64
|
+
Lockstep.synchronized = false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
prepend(mod)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
Capybara::Session.class_eval do
|
77
|
+
extend Capybara::Lockstep::SynchronizeAroundScriptMethod
|
78
|
+
|
79
|
+
synchronize_around_script_method :execute_script
|
80
|
+
synchronize_around_script_method :evaluate_async_script
|
81
|
+
# Don't synchronize around evaluate_script. It calls execute_script
|
82
|
+
# internally and we don't want to synchronize multiple times.
|
83
|
+
end
|
84
|
+
|
34
85
|
module Capybara
|
35
86
|
module Lockstep
|
36
87
|
module UnsychronizeAfter
|
@@ -38,7 +89,7 @@ module Capybara
|
|
38
89
|
mod = Module.new do
|
39
90
|
define_method meth do |*args, &block|
|
40
91
|
super(*args, &block).tap do
|
41
|
-
|
92
|
+
Lockstep.synchronized = false
|
42
93
|
end
|
43
94
|
end
|
44
95
|
end
|
@@ -39,6 +39,8 @@ module Capybara
|
|
39
39
|
|
40
40
|
log 'Synchronizing'
|
41
41
|
|
42
|
+
start_time = current_seconds
|
43
|
+
|
42
44
|
begin
|
43
45
|
with_max_wait_time(timeout) do
|
44
46
|
message_from_js = evaluate_async_script(<<~JS)
|
@@ -67,7 +69,9 @@ module Capybara
|
|
67
69
|
log(message_from_js)
|
68
70
|
else
|
69
71
|
log message_from_js
|
70
|
-
|
72
|
+
end_time = current_seconds
|
73
|
+
ms_elapsed = ((end_time.to_f - start_time) * 1000).round
|
74
|
+
log "Synchronized successfully [#{ms_elapsed} ms]"
|
71
75
|
self.synchronized = true
|
72
76
|
end
|
73
77
|
end
|
@@ -124,6 +128,10 @@ module Capybara
|
|
124
128
|
# no-op
|
125
129
|
end
|
126
130
|
|
131
|
+
def current_seconds
|
132
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
133
|
+
end
|
134
|
+
|
127
135
|
end
|
128
136
|
|
129
137
|
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: 0.
|
4
|
+
version: 0.6.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-03-
|
11
|
+
date: 2021-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|