6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/dekiru/capybara/legacy_helpers.rb', line 6
def wait_for_event(event)
page.execute_script(<<~"EOS")
(function(){
var eventName = '#{event}';
window._dekiruCapybaraWaitEvents = window._dekiruCapybaraWaitEvents || {};
window._dekiruCapybaraWaitEvents[eventName] = 1;
jQuery(document).one(eventName, function(){window._dekiruCapybaraWaitEvents[eventName] = 0;});
})();
EOS
yield
script = <<~"EOS"
(function(){
var eventName = '#{event}';
return window._dekiruCapybaraWaitEvents && window._dekiruCapybaraWaitEvents[eventName];
})();
EOS
wait_until do
result = page.evaluate_script(script)
raise Error, 'wait_for_event: Missing context. probably moved to another page.' if result.nil?
result == 0
end
end
|