Commit 832ce1f3 authored by Mark Lapierre's avatar Mark Lapierre Committed by Ramya Authappan

Try to find elements before waiting for requests

parent 2779d69b
......@@ -188,21 +188,33 @@ module QA
end
def has_element?(name, **kwargs)
wait_for_requests(skip_finished_loading_check: !!kwargs.delete(:skip_finished_loading_check))
disabled = kwargs.delete(:disabled)
if disabled.nil?
original_kwargs = kwargs.dup
wait = kwargs.delete(:wait) || Capybara.default_max_wait_time
text = kwargs.delete(:text)
klass = kwargs.delete(:class)
try_find_element = ->(wait) do
if disabled.nil?
has_css?(element_selector_css(name, kwargs), text: text, wait: wait, class: klass)
else
find_element(name, kwargs).disabled? == disabled
find_element(name, original_kwargs).disabled? == disabled
end
end
# Check for the element before waiting for requests, just in case unrelated requests are in progress.
# This is to avoid waiting unnecessarily after the element we're interested in has already appeared.
return true if try_find_element.call(wait)
# If the element didn't appear, wait for requests and then check again
wait_for_requests(skip_finished_loading_check: !!kwargs.delete(:skip_finished_loading_check))
# We only wait one second now because we previously waited the full expected duration,
# plus however long it took for requests to complete. One second should be enough
# for the UI to update after requests complete.
try_find_element.call(1)
end
def has_no_element?(name, **kwargs)
wait_for_requests
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment