]> source.dussan.org Git - nextcloud-server.git/commitdiff
Verify WaitFor::element... results with an assertion
authorDaniel Calviño Sánchez <danxuliu@gmail.com>
Fri, 5 Mar 2021 19:17:53 +0000 (20:17 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Mon, 8 Mar 2021 07:59:32 +0000 (07:59 +0000)
WaitFor::element... calls only perform the waiting and return whether
the condition succeeded or not, but that result needs to be explicitly
checked to prevent further steps from being executed if the wait failed.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
tests/acceptance/features/bootstrap/AppNavigationContext.php
tests/acceptance/features/bootstrap/AppSettingsContext.php
tests/acceptance/features/bootstrap/AppsManagementContext.php
tests/acceptance/features/bootstrap/DialogContext.php
tests/acceptance/features/bootstrap/UsersSettingsContext.php

index df6ed228960e3b8c42f89716891e6bc394913c77..06a1c563b0321db0c1d01764746ad25c8e924c6b 100644 (file)
@@ -112,14 +112,24 @@ class AppNavigationContext implements Context, ActorAwareInterface {
         * @Then I see that the section :section is shown
         */
        public function iSeeThatTheSectionIsShown($section) {
-               WaitFor::elementToBeEventuallyShown($this->actor, self::appNavigationSectionItemFor($section));
+               if (!WaitFor::elementToBeEventuallyShown(
+                               $this->actor,
+                               self::appNavigationSectionItemFor($section),
+                               $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
+                       PHPUnit_Framework_Assert::fail("The section $section in the app navigation is not shown yet after $timeout seconds");
+               }
        }
 
        /**
         * @Then I see that the section :section is not shown
         */
        public function iSeeThatTheSectionIsNotShown($section) {
-               WaitFor::elementToBeEventuallyNotShown($this->actor, self::appNavigationSectionItemFor($section));
+               if (!WaitFor::elementToBeEventuallyNotShown(
+                               $this->actor,
+                               self::appNavigationSectionItemFor($section),
+                               $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
+                       PHPUnit_Framework_Assert::fail("The section $section in the app navigation is still shown after $timeout seconds");
+               }
        }
 
        /**
index d7ee4a2eb004bbbb7b71a803584f9daad672981c..eda9fe200d0e3d6359272dbcf01b04fd98591da3 100644 (file)
@@ -95,6 +95,11 @@ class AppSettingsContext implements Context, ActorAwareInterface {
         * @Then I see that the settings are opened
         */
        public function iSeeThatTheSettingsAreOpened() {
-               WaitFor::elementToBeEventuallyShown($this->actor, self::appSettingsContent());
+               if (!WaitFor::elementToBeEventuallyShown(
+                               $this->actor,
+                               self::appSettingsContent(),
+                               $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
+                       PHPUnit_Framework_Assert::fail("The app settings are not open yet after $timeout seconds");
+               }
        }
 }
index d86b972c85bdb092e44086dc5f06d22bc329a84c..b692e77ca60f15a2f9fe980d19fff47f66c69a7c 100644 (file)
@@ -164,7 +164,12 @@ class AppsManagementContext implements Context, ActorAwareInterface {
         * @Then /^I see that there some apps listed from the app store$/
         */
        public function iSeeThatThereSomeAppsListedFromTheAppStore() {
-               WaitFor::elementToBeEventuallyShown($this->actor, self::appEntries(), 10);
+               if (!WaitFor::elementToBeEventuallyShown(
+                               $this->actor,
+                               self::appEntries(),
+                               $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
+                       PHPUnit_Framework_Assert::fail("The apps from the app store were not shown yet after $timeout seconds");
+               }
        }
 
        /**
index f9d2d6244e9798815710b679458c3f210e1ff325..e2dccf7b11343ef0720abb637baef75371bd6646 100644 (file)
@@ -54,13 +54,23 @@ class DialogContext implements Context, ActorAwareInterface {
         * @Then I see that the confirmation dialog is shown
         */
        public function iSeeThatTheConfirmationDialogIsShown() {
-               WaitFor::elementToBeEventuallyShown($this->actor, self::theDialog());
+               if (!WaitFor::elementToBeEventuallyShown(
+                               $this->actor,
+                               self::theDialog(),
+                               $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
+                       PHPUnit_Framework_Assert::fail("The confirmation dialog was not shown yet after $timeout seconds");
+               }
        }
 
        /**
         * @Then I see that the confirmation dialog is not shown
         */
        public function iSeeThatTheConfirmationDialogIsNotShown() {
-               WaitFor::elementToBeEventuallyNotShown($this->actor, self::theDialog());
+               if (!WaitFor::elementToBeEventuallyNotShown(
+                               $this->actor,
+                               self::theDialog(),
+                               $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
+                       PHPUnit_Framework_Assert::fail("The confirmation dialog is still shown after $timeout seconds");
+               }
        }
 }
index cc542bf2fc412ec0f4ca5b4ade6e6ee563ba5f65..6b0aa7877918192919c0dac59a4fd9e2b36b39e0 100644 (file)
@@ -267,14 +267,24 @@ class UsersSettingsContext implements Context, ActorAwareInterface {
         * @Then I see that the list of users contains the user :user
         */
        public function iSeeThatTheListOfUsersContainsTheUser($user) {
-               WaitFor::elementToBeEventuallyShown($this->actor, self::rowForUser($user));
+               if (!WaitFor::elementToBeEventuallyShown(
+                               $this->actor,
+                               self::rowForUser($user),
+                               $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
+                       PHPUnit_Framework_Assert::fail("The user $user in the list of users is not shown yet after $timeout seconds");
+               }
        }
 
        /**
         * @Then I see that the list of users does not contains the user :user
         */
        public function iSeeThatTheListOfUsersDoesNotContainsTheUser($user) {
-               WaitFor::elementToBeEventuallyNotShown($this->actor, self::rowForUser($user));
+               if (!WaitFor::elementToBeEventuallyNotShown(
+                               $this->actor,
+                               self::rowForUser($user),
+                               $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
+                       PHPUnit_Framework_Assert::fail("The user $user in the list of users is still shown after $timeout seconds");
+               }
        }
 
        /**
@@ -321,8 +331,26 @@ class UsersSettingsContext implements Context, ActorAwareInterface {
         * @Then I see that the :cell cell for user :user is done loading
         */
        public function iSeeThatTheCellForUserIsDoneLoading($cell, $user) {
-               WaitFor::elementToBeEventuallyShown($this->actor, self::classCellForUser($cell . ' icon-loading-small', $user));
-               WaitFor::elementToBeEventuallyNotShown($this->actor, self::classCellForUser($cell . ' icon-loading-small', $user));
+               // It could happen that the cell for the user was done loading and thus
+               // the loading icon hidden again even before finding the loading icon
+               // started. Therefore, if the loading icon could not be found it is just
+               // assumed that it was already hidden again. Nevertheless, this check
+               // should be done anyway to ensure that the following scenario steps are
+               // not executed before the cell for the user was done loading.
+               try {
+                       $this->actor->find(self::classCellForUser($cell . ' icon-loading-small', $user), 1);
+               } catch (NoSuchElementException $exception) {
+                       echo "The loading icon for user $user was not found after " . (1 * $this->actor->getFindTimeoutMultiplier()) . " seconds, assumming that it was shown and hidden again before the check started and continuing";
+
+                       return;
+               }
+
+               if (!WaitFor::elementToBeEventuallyNotShown(
+                               $this->actor,
+                               self::classCellForUser($cell . ' icon-loading-small', $user),
+                               $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
+                       PHPUnit_Framework_Assert::fail("The loading icon for user $user is still shown after $timeout seconds");
+               }
        }
 
        /**
@@ -337,6 +365,11 @@ class UsersSettingsContext implements Context, ActorAwareInterface {
         * @Then I see that the edit mode is on for user :user
         */
        public function iSeeThatTheEditModeIsOn($user) {
-               WaitFor::elementToBeEventuallyShown($this->actor, self::editModeOn($user));
+               if (!WaitFor::elementToBeEventuallyShown(
+                               $this->actor,
+                               self::editModeOn($user),
+                               $timeout = 10 * $this->actor->getFindTimeoutMultiplier())) {
+                       PHPUnit_Framework_Assert::fail("The edit mode for user $user in the list of users is not on yet after $timeout seconds");
+               }
        }
 }