1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Add basic Element#flash for debugging

This commit is contained in:
Thomas Walpole 2019-07-31 15:33:37 -07:00
parent 5b0c2d6f3c
commit bbda59c34b

View file

@ -515,6 +515,28 @@ module Capybara
JS
end
##
#
# Toggle the elements background color between white and black for a period of time.
#
# @return [Capybara::Node::Element] The element
def flash
execute_script(<<~JS, 100)
async function flash(el, delay){
var old_bg = el.style.backgroundColor;
var colors = ["black", "white"];
for(var i=0; i<20; i++){
el.style.backgroundColor = colors[i % colors.length];
await new Promise(resolve => setTimeout(resolve, delay));
}
el.style.backgroundColor = old_bg;
}
flash(this, arguments[0]);
JS
self
end
# @api private
def reload
if @allow_reload