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:
parent
5b0c2d6f3c
commit
bbda59c34b
1 changed files with 22 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue