Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
UI tests default timeout constant and accurate timer calculations
Signed-off-by: Phil Davis <phil@jankaritech.com>
  • Loading branch information
phil-davis committed Jul 4, 2017
commit 4e996fc5d4050b0420193875995895eccfd89a30
3 changes: 3 additions & 0 deletions tests/ui/features/bootstrap/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
14 changes: 10 additions & 4 deletions tests/ui/features/lib/FilesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,17 @@ 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);'
);

// 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
Expand All @@ -181,6 +183,7 @@ public function scrollDownAppContent ($numberOfFilesOld, Session $session, $time
break;
}
usleep(STANDARDSLEEPTIMEMICROSEC);
$currentTime = microtime(true);
}
}

Expand Down Expand Up @@ -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);
}
Expand Down
25 changes: 17 additions & 8 deletions tests/ui/features/lib/OwncloudPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,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'
Expand All @@ -43,6 +45,7 @@ public function waitTillPageIsLoaded(Session $session, $timeout_msec=10000)
break;
}
usleep(STANDARDSLEEPTIMEMICROSEC);
$currentTime = microtime(true);
}
$this->waitForOutstandingAjaxCalls($session);
}
Expand All @@ -52,9 +55,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) {
Expand All @@ -64,6 +69,7 @@ public function waitTillElementIsNull ($xpath, $timeout_msec=10000)
break;
}
usleep(STANDARDSLEEPTIMEMICROSEC);
$currentTime = microtime(true);
}
}

Expand All @@ -72,9 +78,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()) {
Expand All @@ -84,6 +92,7 @@ public function waitTillElementIsNotNull ($xpath, $timeout_msec=10000)
}
} catch (WebDriverException $e) {
usleep(STANDARDSLEEPTIMEMICROSEC);
$currentTime = microtime(true);
}
}
}
Expand Down Expand Up @@ -145,7 +154,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) {
Expand Down Expand Up @@ -204,7 +213,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);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/features/lib/SharingDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down