2018-12-19 14:47:15 +00:00
|
|
|
class Capybara::Node::Element
|
|
|
|
|
|
|
|
# This is an extension to each node to check if the element
|
|
|
|
# is moving or in a fixed position. This is especially helpful
|
|
|
|
# for animated elements that cause flanky tests.
|
|
|
|
# NOTE: In CI env a special sleep is performed between checks
|
|
|
|
# because animations can be slow.
|
|
|
|
#
|
|
|
|
# @param [Integer] checks the number of performed movement checks
|
|
|
|
#
|
|
|
|
# @example
|
2020-08-24 13:40:28 +00:00
|
|
|
# find('.clues-close').in_fixed_position.click
|
2018-12-19 14:47:15 +00:00
|
|
|
# => waits till clues moved to final position and performs click afterwards
|
|
|
|
#
|
|
|
|
# @raise [RuntimeError] raised in case the element is
|
|
|
|
# still moving after max number of checks was passed
|
|
|
|
#
|
|
|
|
# @return [Capybara::Node::Element] the element/node
|
2020-12-09 15:55:11 +00:00
|
|
|
def in_fixed_position(checks: 100, wait: 0.2)
|
2020-08-24 21:15:24 +00:00
|
|
|
previous = native.location
|
2018-12-19 14:47:15 +00:00
|
|
|
|
2020-08-24 21:15:24 +00:00
|
|
|
(checks + 1).times do
|
2020-12-09 15:55:11 +00:00
|
|
|
sleep wait
|
2018-12-19 14:47:15 +00:00
|
|
|
|
|
|
|
current = native.location
|
2020-08-24 21:15:24 +00:00
|
|
|
|
|
|
|
return self if previous == current
|
2018-12-19 14:47:15 +00:00
|
|
|
|
|
|
|
previous = current
|
|
|
|
end
|
|
|
|
|
2020-08-24 21:15:24 +00:00
|
|
|
raise "Element still moving after #{checks} checks"
|
2018-12-19 14:47:15 +00:00
|
|
|
end
|
|
|
|
end
|