ElementProxy was introduced so the presence of elements on the page could be queried.
class SomePage < AePageObjects::Document
element :some_element
end
some_page = SomePage.visit
some_page.some_element.present?
ElementProxy#present? accesses the element and retries on Capybara::ElementNotFound until Capybara.default_wait_time.
When the underlying element is found, it is cached so subsequent calls through ElementProxy don't incur another lookup.
ElementProxy#not_present? was intended to work the same way, whereby the underlying element is accessed and retries until it is no longer present (i.e. absent) on the page.
However, due to the element caching, if not_present? is called after the underlying element has been cached, the page is not polled for the absence of the element.
not_present? should work just like present? and poll the page until the underlying element is not present.
Additionally, the query methods present? and not_present? do not communicate to the reader that the page is polled and the presence or absence of the element is queried until achieved. In some tests, these methods are called with the intent of waiting and in others these methods are called with the intent of querying the state of the element.
With the intent of waiting:
modal = some_page.modal
do_modal_things(modal)
some_page.modal.not_present?
With the intent of querying:
modal = some_page.modal
if modal.present?
do_modal_things(modal)
end
While the underlying implementation should wait for the state in both cases, the methods called should reflect the intent.
The following reads much better:
With the intent of waiting:
modal = some_page.modal
do_modal_things(modal)
modal.wait_for_absence
With the intent of querying:
modal = some_page.modal
if modal.present?
do_modal_things(modal)
end
ElementProxy was introduced so the presence of elements on the page could be queried.
ElementProxy#present?accesses the element and retries onCapybara::ElementNotFounduntilCapybara.default_wait_time.When the underlying element is found, it is cached so subsequent calls through ElementProxy don't incur another lookup.
ElementProxy#not_present?was intended to work the same way, whereby the underlying element is accessed and retries until it is no longer present (i.e. absent) on the page.However, due to the element caching, if
not_present?is called after the underlying element has been cached, the page is not polled for the absence of the element.not_present?should work just likepresent?and poll the page until the underlying element is not present.Additionally, the query methods
present?andnot_present?do not communicate to the reader that the page is polled and the presence or absence of the element is queried until achieved. In some tests, these methods are called with the intent of waiting and in others these methods are called with the intent of querying the state of the element.With the intent of waiting:
With the intent of querying:
While the underlying implementation should wait for the state in both cases, the methods called should reflect the intent.
The following reads much better:
With the intent of waiting:
With the intent of querying: