diff --git a/docs/tests.markdown b/docs/tests.markdown index 6070f3c..cc758cd 100644 --- a/docs/tests.markdown +++ b/docs/tests.markdown @@ -62,7 +62,7 @@ The following `phpunit.xml` is used to run phpunit on a linux system with apache assertEquals($this->expectedCounterUnread, $this->getCounterUnread(), 'unread counter differ from expectation'); + $this->assertTrue($this->waitForElementByIdText('page-counter', $this->expectedCounterPage), 'page-counter differ from expected'); + $this->assertTrue($this->waitForElementByIdText('nav-counter', $this->expectedCounterUnread), 'unread counter differ from expectation'); // url has not been changed (its likely that everything was done via javascript then) $this->assertEquals($this->expectedPageUrl, $this->url(), 'URL has been changed.'); @@ -157,25 +157,6 @@ abstract class minifluxTestCase extends PHPUnit_Extensions_Selenium2TestCase return static::$databaseTester; } - private function getCounterUnread() - { - $value = $this->element($this->using('id')->value('nav-counter'))->text(); - return $value; - } - - private function getCounterPage() - { - $value = NULL; - - $elements = $this->elements($this->using('id')->value('page-counter')); - - if (count($elements) === 1) { - $value = $elements[0]->text(); - } - - return $value; - } - // public to be accessible within an closure public function isElementVisible($element) { @@ -258,6 +239,45 @@ abstract class minifluxTestCase extends PHPUnit_Extensions_Selenium2TestCase return $value; } + private function waitForElementByIdText($id, $text) + { + // return false in case of timeout + try { + // Workaround for PHP < 5.4 + $CI = $this; + + $value = $this->waitUntil(function() use($CI, $id, $text) { + try { + $elements = $this->elements($this->using('id')->value($id)); + + if (count($elements) === 1 && $elements[0]->text() == $text + || count($elements) === 0 && is_null($text)) { + return TRUE; + } + } + catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) { + $noSuchElement = ($e->getCode() === PHPUnit_Extensions_Selenium2TestCase_WebDriverException::NoSuchElement + || $e->getCode() === PHPUnit_Extensions_Selenium2TestCase_WebDriverException::StaleElementReference); + + // everything else than "No such Element" or + // "Stale Element Reference" is unexpected + if (! $noSuchElement) { + throw $e; + } + } + }, $this->waitTimeout); + } + catch(PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) { + if ($e->getCode() === PHPUnit_Extensions_Selenium2TestCase_WebDriverException::Timeout) { + return FALSE; + } else { + throw $e; + } + } + + return $value; + } + private function waitForElementAttributeHasValue($element, $attribute, $attributeValue, $invertMatch = FALSE) { // return false in case of timeout diff --git a/tests/integration/pageHistoryTest.php b/tests/integration/pageHistoryTest.php index 629ecd2..dc085b6 100644 --- a/tests/integration/pageHistoryTest.php +++ b/tests/integration/pageHistoryTest.php @@ -246,8 +246,6 @@ class pageHistoryTest extends minifluxTestCase $link = $this->getLinkReadStatusToogle($article); $link->click(); - $this->waitForIconMarkReadInvisible($article); - $this->expectedCounterPage = static::DEFAULT_COUNTER_PAGE + static::DEFAULT_COUNTER_UNREAD - 1; $this->expectedCounterUnread = 1; $this->expectedDataSet = $this->getDataSet('fixture_OneUnreadArticle');