diff --git a/tests/ui/features/bootstrap/bootstrap.php b/tests/ui/features/bootstrap/bootstrap.php index 4ed3f7c017d4..5b3aec8c9b85 100644 --- a/tests/ui/features/bootstrap/bootstrap.php +++ b/tests/ui/features/bootstrap/bootstrap.php @@ -10,3 +10,6 @@ // Sleep for 10 milliseconds const STANDARDSLEEPTIMEMILLISEC = 10; const STANDARDSLEEPTIMEMICROSEC = STANDARDSLEEPTIMEMILLISEC * 1000; + +// Default timeout for use in code that needs to wait for the UI +const STANDARDUIWAITTIMEOUTMILLISEC = 10000; diff --git a/tests/ui/features/lib/FilesPage.php b/tests/ui/features/lib/FilesPage.php index 5d36bd699c78..f9b085dd51e2 100644 --- a/tests/ui/features/lib/FilesPage.php +++ b/tests/ui/features/lib/FilesPage.php @@ -164,7 +164,7 @@ public function openSharingDialog ($name, Session $session) * @param Session $session * @param int $timeout_msec */ - public function scrollDownAppContent ($numberOfFilesOld, Session $session, $timeout_msec=5000) + public function scrollDownAppContent ($numberOfFilesOld, Session $session, $timeout_msec=STANDARDUIWAITTIMEOUTMILLISEC) { $session->evaluateScript( '$("#' . $this->appContentId . '").scrollTop($("#' . $this->appContentId . '")[0].scrollHeight);' @@ -172,7 +172,9 @@ public function scrollDownAppContent ($numberOfFilesOld, Session $session, $time // there is no loading indicator here, so we are going to wait until we have // more files than before - for ($counter = 0; $counter <= $timeout_msec; $counter += STANDARDSLEEPTIMEMILLISEC) { + $currentTime = microtime(true); + $end = $currentTime + ($timeout_msec / 1000); + while ($currentTime <= $end) { $this->waitForOutstandingAjaxCalls($session); $fileNameSpans = $this->find("xpath", $this->fileListXpath)->findAll( "xpath", $this->fileNamesXpath @@ -181,6 +183,7 @@ public function scrollDownAppContent ($numberOfFilesOld, Session $session, $time break; } usleep(STANDARDSLEEPTIMEMICROSEC); + $currentTime = microtime(true); } } @@ -292,15 +295,18 @@ public function findDeleteByNo($number) { //there is no reliable loading indicator on the files page, so wait for //the table or the Empty Folder message to be shown - public function waitTillPageIsLoaded(Session $session, $timeout_msec=10000) + public function waitTillPageIsLoaded(Session $session, $timeout_msec=STANDARDUIWAITTIMEOUTMILLISEC) { - for ($counter = 0; $counter <= $timeout_msec; $counter += STANDARDSLEEPTIMEMILLISEC) { + $currentTime = microtime(true); + $end = $currentTime + ($timeout_msec / 1000); + while ($currentTime <= $end) { $fileList = $this->findById("fileList"); if ($fileList !== null && ($fileList->has("xpath", "//a") || ! $this->find("xpath", $this->emptyContentXpath)->hasClass("hidden"))) { break; } usleep(STANDARDSLEEPTIMEMICROSEC); + $currentTime = microtime(true); } $this->waitForOutstandingAjaxCalls($session); } diff --git a/tests/ui/features/lib/OwncloudPage.php b/tests/ui/features/lib/OwncloudPage.php index 0c1587b95bfc..ca7b3cd79518 100644 --- a/tests/ui/features/lib/OwncloudPage.php +++ b/tests/ui/features/lib/OwncloudPage.php @@ -31,9 +31,11 @@ class OwncloudPage extends Page { protected $userNameDispayId = "expandDisplayName"; - public function waitTillPageIsLoaded(Session $session, $timeout_msec=10000) + public function waitTillPageIsLoaded(Session $session, $timeout_msec=STANDARDUIWAITTIMEOUTMILLISEC) { - for ($counter = 0; $counter <= $timeout_msec; $counter += STANDARDSLEEPTIMEMILLISEC) { + $currentTime = microtime(true); + $end = $currentTime + ($timeout_msec / 1000); + while ($currentTime <= $end) { $loadingIndicator=$this->find("css", '.loading'); $visibility = $this->elementHasCSSValue( $loadingIndicator, 'visibility', 'visible' @@ -42,6 +44,7 @@ public function waitTillPageIsLoaded(Session $session, $timeout_msec=10000) break; } usleep(STANDARDSLEEPTIMEMICROSEC); + $currentTime = microtime(true); } $this->waitForOutstandingAjaxCalls($session); } @@ -51,9 +54,11 @@ public function waitTillPageIsLoaded(Session $session, $timeout_msec=10000) * @param string $xpath * @param int $timeout_msec */ - public function waitTillElementIsNull ($xpath, $timeout_msec=10000) + public function waitTillElementIsNull ($xpath, $timeout_msec=STANDARDUIWAITTIMEOUTMILLISEC) { - for ($counter = 0; $counter <= $timeout_msec; $counter += STANDARDSLEEPTIMEMILLISEC) { + $currentTime = microtime(true); + $end = $currentTime + ($timeout_msec / 1000); + while ($currentTime <= $end) { try { $element = $this->find("xpath",$xpath); } catch (WebDriverException $e) { @@ -63,6 +68,7 @@ public function waitTillElementIsNull ($xpath, $timeout_msec=10000) break; } usleep(STANDARDSLEEPTIMEMICROSEC); + $currentTime = microtime(true); } } @@ -71,9 +77,11 @@ public function waitTillElementIsNull ($xpath, $timeout_msec=10000) * @param string $xpath * @param int $timeout_msec */ - public function waitTillElementIsNotNull ($xpath, $timeout_msec=10000) + public function waitTillElementIsNotNull ($xpath, $timeout_msec=STANDARDUIWAITTIMEOUTMILLISEC) { - for ($counter = 0; $counter <= $timeout_msec; $counter += STANDARDSLEEPTIMEMILLISEC) { + $currentTime = microtime(true); + $end = $currentTime + ($timeout_msec / 1000); + while ($currentTime <= $end) { try { $element = $this->find("xpath",$xpath); if ($element === null || !$element->isValid()) { @@ -83,6 +91,7 @@ public function waitTillElementIsNotNull ($xpath, $timeout_msec=10000) } } catch (WebDriverException $e) { usleep(STANDARDSLEEPTIMEMICROSEC); + $currentTime = microtime(true); } } } @@ -144,7 +153,7 @@ public function getWindowHeight($session) * @param number $timeout_msec * @throws \Exception */ - public function waitForOutstandingAjaxCalls (Session $session, $timeout_msec=5000) + public function waitForOutstandingAjaxCalls (Session $session, $timeout_msec=STANDARDUIWAITTIMEOUTMILLISEC) { $timeout_msec = (int) $timeout_msec; if ($timeout_msec <= 0) { @@ -203,7 +212,7 @@ public function waitForAjaxCallsToStart (Session $session, $timeout_msec=1000) * @param Session $session * @param int $timeout_msec */ - public function waitForAjaxCallsToStartAndFinish (Session $session, $timeout_msec=5000) + public function waitForAjaxCallsToStartAndFinish (Session $session, $timeout_msec=STANDARDUIWAITTIMEOUTMILLISEC) { $start = microtime(true); $this->waitForAjaxCallsToStart($session); diff --git a/tests/ui/features/lib/SharingDialog.php b/tests/ui/features/lib/SharingDialog.php index 68159df5ead1..655a60f49e59 100644 --- a/tests/ui/features/lib/SharingDialog.php +++ b/tests/ui/features/lib/SharingDialog.php @@ -61,7 +61,7 @@ private function _findShareWithField () * @return \Behat\Mink\Element\NodeElement AutocompleteElement * @throws \SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException */ - public function fillShareWithField ($input, Session $session, $timeout_msec = 10000) + public function fillShareWithField ($input, Session $session, $timeout_msec = STANDARDUIWAITTIMEOUTMILLISEC) { $shareWithField = $this->_findShareWithField(); $shareWithField->setValue($input);