2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
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
|
2021-06-15 06:26:52 +00:00
|
|
|
|
|
|
|
module ZammadCapybarActionDelegator
|
2021-07-06 07:52:22 +00:00
|
|
|
def select(...)
|
2021-06-15 06:26:52 +00:00
|
|
|
super.tap do
|
|
|
|
await_empty_ajax_queue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-06 07:52:22 +00:00
|
|
|
def click(...)
|
2021-06-15 06:26:52 +00:00
|
|
|
super.tap do
|
|
|
|
await_empty_ajax_queue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-06 07:52:22 +00:00
|
|
|
def click_on(...)
|
2021-06-15 06:26:52 +00:00
|
|
|
super.tap do
|
|
|
|
await_empty_ajax_queue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-06 07:52:22 +00:00
|
|
|
def click_link_or_button(...)
|
2021-06-15 06:26:52 +00:00
|
|
|
super.tap do
|
|
|
|
await_empty_ajax_queue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-06 07:52:22 +00:00
|
|
|
def click_button(...)
|
2021-06-15 06:26:52 +00:00
|
|
|
super.tap do
|
|
|
|
await_empty_ajax_queue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-06 07:52:22 +00:00
|
|
|
def select_option(...)
|
2021-06-15 06:26:52 +00:00
|
|
|
super.tap do
|
|
|
|
await_empty_ajax_queue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-06 07:52:22 +00:00
|
|
|
def send_keys(...)
|
2021-06-15 06:26:52 +00:00
|
|
|
super.tap do
|
|
|
|
await_empty_ajax_queue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module ZammadCapybarSelectorDelegator
|
2021-07-06 07:52:22 +00:00
|
|
|
def find_field(...)
|
2021-06-15 06:26:52 +00:00
|
|
|
ZammadCapybaraElementDelegator.new(element: super, context: self)
|
|
|
|
end
|
|
|
|
|
2021-07-06 07:52:22 +00:00
|
|
|
def find_button(...)
|
2021-06-15 06:26:52 +00:00
|
|
|
ZammadCapybaraElementDelegator.new(element: super, context: self)
|
|
|
|
end
|
|
|
|
|
2021-07-06 07:52:22 +00:00
|
|
|
def find_by_id(...)
|
2021-06-15 06:26:52 +00:00
|
|
|
ZammadCapybaraElementDelegator.new(element: super, context: self)
|
|
|
|
end
|
|
|
|
|
2021-07-06 07:52:22 +00:00
|
|
|
def find_link(...)
|
2021-06-15 06:26:52 +00:00
|
|
|
ZammadCapybaraElementDelegator.new(element: super, context: self)
|
|
|
|
end
|
|
|
|
|
2021-07-06 07:52:22 +00:00
|
|
|
def find(...)
|
2021-06-15 06:26:52 +00:00
|
|
|
ZammadCapybaraElementDelegator.new(element: super, context: self)
|
|
|
|
end
|
|
|
|
|
2021-07-06 07:52:22 +00:00
|
|
|
def first(...)
|
2021-06-15 06:26:52 +00:00
|
|
|
ZammadCapybaraElementDelegator.new(element: super, context: self)
|
|
|
|
end
|
|
|
|
|
2021-07-06 07:52:22 +00:00
|
|
|
def all(...)
|
2021-06-15 06:26:52 +00:00
|
|
|
super.map { |element| ZammadCapybaraElementDelegator.new(element: element, context: self) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ZammadCapybaraSessionDelegator < SimpleDelegator
|
|
|
|
extend Forwardable
|
|
|
|
|
|
|
|
def_delegator :@context, :await_empty_ajax_queue
|
|
|
|
|
|
|
|
include ZammadCapybarSelectorDelegator
|
|
|
|
|
|
|
|
def initialize(context:, element:)
|
|
|
|
@context = context
|
|
|
|
|
|
|
|
super(element)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ZammadCapybaraElementDelegator < ZammadCapybaraSessionDelegator
|
|
|
|
include ZammadCapybarActionDelegator
|
|
|
|
end
|
|
|
|
|
|
|
|
module CapybaraCustomExtensions
|
|
|
|
include ZammadCapybarActionDelegator
|
|
|
|
include ZammadCapybarSelectorDelegator
|
|
|
|
|
2021-07-06 07:52:22 +00:00
|
|
|
def page(...)
|
2021-06-15 06:26:52 +00:00
|
|
|
ZammadCapybaraSessionDelegator.new(element: super, context: self)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
config.include CapybaraCustomExtensions, type: :system
|
|
|
|
end
|