Discussion:
[wtr-general] Suggested code amendment for: Watir::Element#flash
p***@datacom.co.nz
2017-04-29 08:33:42 UTC
Permalink
I'd like to suggest a minor update to Watir::Element#flash

I have added three parameters to remove the hard coded values only. I gave
them defaults so if not provided the function is backwards compatible.

But this allows the external caller to choose what color they want to flash
the element , how many time, and how fast.

#
# Flashes (change background color to a new color and back a few times)
element.
#
# @examples
# browser.text_field(name: "new_user_first_name").flash
# browser.text_field(name:
"new_user_first_name").flash("green",3,0.05)
#

def flash(color="yellow",flashes=5,delay=0.1)
background_color = style("backgroundColor")
element_color =
driver.execute_script("arguments[0].style.backgroundColor", @element)

flashes.times do |n|
nextcolor = (n % 2 == 0) ? color : background_color
driver.execute_script("arguments[0].style.backgroundColor =
'#{nextcolor}'", @element)
sleep(delay)
end

driver.execute_script("arguments[0].style.backgroundColor =
arguments[1]", @element, element_color)

self
end
--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Titus Fortner
2017-04-29 21:48:08 UTC
Permalink
Please submit a Pull Request
- https://github.com/watir/watir#note-on-patchespull-requests
Post by p***@datacom.co.nz
I'd like to suggest a minor update to Watir::Element#flash
I have added three parameters to remove the hard coded values only. I
gave them defaults so if not provided the function is backwards compatible.
But this allows the external caller to choose what color they want to
flash the element , how many time, and how fast.
#
# Flashes (change background color to a new color and back a few
times) element.
#
# browser.text_field(name: "new_user_first_name").flash
"new_user_first_name").flash("green",3,0.05)
#
def flash(color="yellow",flashes=5,delay=0.1)
background_color = style("backgroundColor")
element_color =
flashes.times do |n|
nextcolor = (n % 2 == 0) ? color : background_color
driver.execute_script("arguments[0].style.backgroundColor =
sleep(delay)
end
driver.execute_script("arguments[0].style.backgroundColor =
self
end
--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...