Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle stale or invisible elements automatically in acceptance tests #4718

Conversation

danxuliu
Copy link
Member

@danxuliu danxuliu commented May 6, 2017

This is the last of the needed changes to fix/minimize the sporadic failures of the acceptance tests (or I hope so; there may be other different sporadic failures that have not manifested themselves yet ;) ).

Sometimes, acceptance tests fail because a StaleElementReference exception is thrown when executing a command on an element (Element is no longer attached to the DOM). This can happen even in an apparently safe chained call like $actor->find($locator)->click(); in the milliseconds between finding the element and clicking it the element could have been removed from the page (for example, if a previous interaction with the page started an asynchronous update of the DOM). Ah, the beauty of concurrency... :P

In other cases, acceptance tests fail because an ElementNotVisible exception is thrown when executing a command on an element that should be visible but it is not (Element is not currently visible and so may not be interacted with). Finding an element only guarantees that (at that time) the element is attached to the DOM, but it does not provide any guarantee regarding its visibility.

It is possible to handle both exceptions in a generic way: a StaleElementReference exception can be handled by finding the element again and executing the command on the new element, and an ElementNotVisible exception can be handled by waiting for the element to be visible and then executing the command again. Therefore the ElementWrapper class was introduced to wrap Mink elements and automatically take care of those situations.

However, the ElementWrapper is not a silver bullet; it handles the most common situations, but it does not handle every possible scenario. For example, the acceptance tests would still fail sporadically if an element can become staled several times in a row (uncommon) or if it does not become visible before the timeout expires (which could still happen in a loaded system even if the components under test work right, but obviously it is not possible to wait indefinitely for them).

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Commands executed on Mink elements may fail for several reasons.
ElementWrapper is introduced to automatically handle some of those
situations, like StaleElementReference exceptions and ElementNotVisible
exceptions.

StaleElementReference exceptions are thrown when the command is executed
on an element that is no longer attached to the DOM. When that happens
the ElementWrapper finds again the element and executes the command
again on the new element.

ElementNotVisible exceptions are thrown when the command requires the
element to be visible but the element is not. When that happens the
ElementWrapper waits for the element to be visible before executing the
command again.

These changes are totally compatible with the current acceptance tests.
They just make the tests more robust, but they do not change their
behaviour. In fact, this should minimize some of the sporadic failures
in the acceptance tests caused by their concurrent nature with respect
to the web browser executing the commands.

However, the ElementWrapper is not a silver bullet; it handles the most
common situations, but it does not handle every possible scenario. For
example, the acceptance tests would still fail sporadically if an
element can become staled several times in a row (uncommon) or if it
does not become visible before the timeout expires (which could still
happen in a loaded system even if the components under test work right,
but obviously it is not possible to wait indefinitely for them).

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
@danxuliu danxuliu added the 3. to review Waiting for reviews label May 6, 2017
@danxuliu danxuliu changed the title Handle stalled or invisible elements automatically in acceptance tests Handle stale or invisible elements automatically in acceptance tests May 6, 2017
Copy link
Member

@MorrisJobke MorrisJobke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

@MorrisJobke
Copy link
Member

As this is CI only for the acceptance tests and has purely the goal to make them more stable I will merge this one now.

@MorrisJobke MorrisJobke merged commit 1a83f11 into master May 8, 2017
@MorrisJobke MorrisJobke deleted the handle-stalled-or-invisible-elements-automatically-in-acceptance-tests branch May 8, 2017 17:52
@MorrisJobke MorrisJobke added this to the Nextcloud 12.0 milestone May 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants