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,19 +188,31 @@ module QA ...@@ -188,19 +188,31 @@ module QA
end end
def has_element?(name, **kwargs) def has_element?(name, **kwargs)
wait_for_requests(skip_finished_loading_check: !!kwargs.delete(:skip_finished_loading_check))
disabled = kwargs.delete(:disabled) disabled = kwargs.delete(:disabled)
original_kwargs = kwargs.dup
wait = kwargs.delete(:wait) || Capybara.default_max_wait_time
text = kwargs.delete(:text)
klass = kwargs.delete(:class)
if disabled.nil? try_find_element = ->(wait) do
wait = kwargs.delete(:wait) || Capybara.default_max_wait_time if disabled.nil?
text = kwargs.delete(:text) has_css?(element_selector_css(name, kwargs), text: text, wait: wait, class: klass)
klass = kwargs.delete(:class) else
find_element(name, original_kwargs).disabled? == disabled
has_css?(element_selector_css(name, kwargs), text: text, wait: wait, class: klass) end
else
find_element(name, 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 end
def has_no_element?(name, **kwargs) def has_no_element?(name, **kwargs)
......
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