Skip to content

Commit d1547ee

Browse files
authored
Merge pull request #8738 from nextcloud/stable13-8728-better-handling-of-invisible-elements-in-acceptance-tests
[stable13] Better handling of invisible elements in acceptance tests
2 parents b593fd1 + fc6c290 commit d1547ee

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

tests/acceptance/features/core/ElementWrapper.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
* the element is stale it is found again using the same parameters to find it
3939
* in the first place.
4040
*
41+
* NoSuchElement exceptions are sometimes thrown instead of
42+
* StaleElementReference exceptions. This can happen when the Selenium2 driver
43+
* for Mink performs an action on an element through the WebDriver session
44+
* instead of directly through the WebDriver element. In that case, if the
45+
* element with the given ID does not exist, a NoSuchElement exception would be
46+
* thrown instead of a StaleElementReference exception, so those cases are
47+
* handled like StaleElementReference exceptions.
48+
*
4149
* ElementNotVisible exceptions are thrown when the command requires the element
4250
* to be visible but the element is not. Finding an element only guarantees that
4351
* (at that time) the element is attached to the DOM, but it does not provide
@@ -50,11 +58,22 @@
5058
* exceptions; if the element is not visible it is waited for it to be visible
5159
* up to the timeout set to find it.
5260
*
61+
* MoveTargetOutOfBounds exceptions are sometimes thrown instead of
62+
* ElementNotVisible exceptions. This can happen when the Selenium2 driver for
63+
* Mink moves the cursor on an element using the "moveto" method of the
64+
* WebDriver session, for example, before clicking on an element. In that case,
65+
* if the element is not visible, "moveto" would throw a MoveTargetOutOfBounds
66+
* exception instead of an ElementNotVisible exception, so those cases are
67+
* handled like ElementNotVisible exceptions.
68+
*
5369
* Despite the automatic handling it is possible for the commands to throw those
5470
* exceptions when they are executed again; this class does not handle cases
5571
* like an element becoming stale several times in a row (uncommon) or an
5672
* element not becoming visible before the timeout expires (which would mean
57-
* that the timeout is too short or that the test has to, indeed, fail).
73+
* that the timeout is too short or that the test has to, indeed, fail). In a
74+
* similar way, MoveTargetOutOfBounds exceptions would be thrown again if
75+
* originally they were thrown because the element was visible but "out of
76+
* reach".
5877
*
5978
* If needed, automatically handling failed commands can be disabled calling
6079
* "doNotHandleFailedCommands()"; as it returns the ElementWrapper it can be
@@ -189,8 +208,8 @@ public function click() {
189208
/**
190209
* Executes the given command.
191210
*
192-
* If a StaleElementReference exception is thrown the wrapped element is
193-
* found again and, then, the command is executed again.
211+
* If a StaleElementReference or a NoSuchElement exception is thrown the
212+
* wrapped element is found again and, then, the command is executed again.
194213
*
195214
* @param \Closure $commandCallback the command to execute.
196215
* @param string $errorMessage an error message that describes the failed
@@ -205,6 +224,8 @@ private function executeCommand(\Closure $commandCallback, $errorMessage) {
205224
return $commandCallback();
206225
} catch (\WebDriver\Exception\StaleElementReference $exception) {
207226
$this->printFailedCommandMessage($exception, $errorMessage);
227+
} catch (\WebDriver\Exception\NoSuchElement $exception) {
228+
$this->printFailedCommandMessage($exception, $errorMessage);
208229
}
209230

210231
$this->element = $this->elementFinder->find();
@@ -215,10 +236,11 @@ private function executeCommand(\Closure $commandCallback, $errorMessage) {
215236
/**
216237
* Executes the given command on a visible element.
217238
*
218-
* If a StaleElementReference exception is thrown the wrapped element is
219-
* found again and, then, the command is executed again. If an
220-
* ElementNotVisible exception is thrown it is waited for the wrapped
221-
* element to be visible and, then, the command is executed again.
239+
* If a StaleElementReference or a NoSuchElement exception is thrown the
240+
* wrapped element is found again and, then, the command is executed again.
241+
* If an ElementNotVisible or a MoveTargetOutOfBounds exception is thrown it
242+
* is waited for the wrapped element to be visible and, then, the command is
243+
* executed again.
222244
*
223245
* @param \Closure $commandCallback the command to execute.
224246
* @param string $errorMessage an error message that describes the failed
@@ -233,6 +255,8 @@ private function executeCommandOnVisibleElement(\Closure $commandCallback, $erro
233255
return $this->executeCommand($commandCallback, $errorMessage);
234256
} catch (\WebDriver\Exception\ElementNotVisible $exception) {
235257
$this->printFailedCommandMessage($exception, $errorMessage);
258+
} catch (\WebDriver\Exception\MoveTargetOutOfBounds $exception) {
259+
$this->printFailedCommandMessage($exception, $errorMessage);
236260
}
237261

238262
$this->waitForElementToBeVisible();

0 commit comments

Comments
 (0)