From bdfd9f07f17de1751a7e4d94940acb426af4be77 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 6 Aug 2015 18:12:45 +0200 Subject: Fix tests work around stale references by explicitly waiting --- tests/test_tools/PradoGenericSelenium2Test.php | 50 ++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'tests/test_tools') diff --git a/tests/test_tools/PradoGenericSelenium2Test.php b/tests/test_tools/PradoGenericSelenium2Test.php index 23dfeb61..535d500d 100755 --- a/tests/test_tools/PradoGenericSelenium2Test.php +++ b/tests/test_tools/PradoGenericSelenium2Test.php @@ -20,6 +20,15 @@ class PradoGenericSelenium2Test extends PHPUnit_Extensions_Selenium2TestCase 'host' => '127.0.0.1', 'port' => 4444, ), +/* + array( + 'name' => 'Safari on OSX', + 'browserName' => 'safari', + 'sessionStrategy' => 'shared', + 'host' => '127.0.0.1', + 'port' => 4444, + ), +*/ /* array( 'name' => 'Firefox on WindowsXP', @@ -89,12 +98,24 @@ class PradoGenericSelenium2Test extends PHPUnit_Extensions_Selenium2TestCase protected function assertVisible($id) { - $this->assertTrue($this->getElement($id)->displayed()); + try{ + $this->assertTrue($this->getElement($id)->displayed()); + } catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) { + //stale element reference. try second time. + $this->pause(50); + $this->assertTrue($this->getElement($id)->displayed()); + } } protected function assertNotVisible($id) { - $this->assertFalse($this->getElement($id)->displayed()); + try{ + $this->assertFalse($this->getElement($id)->displayed()); + } catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) { + //stale element reference. try second time. + $this->pause(50); + $this->assertFalse($this->getElement($id)->displayed()); + } } protected function assertElementPresent($id) @@ -227,4 +248,27 @@ class PradoGenericSelenium2Test extends PHPUnit_Extensions_Selenium2TestCase usleep($msec*1000); } -} \ No newline at end of file + public function assertSourceContains($text) + { + $found = strpos($this->source(), $text) !== false; + for($i=0;$i<10 && ! $found; $i++) { + $this->pause(20); + $found = strpos($this->source(), $text) !== false; + } + $this->assertTrue($found, "Failed asserting that page source contains $text"); + } + + public function assertSourceNotContains($text) + { + $found = strpos($this->source(), $text) !== false; + for($i=0;$i<10 && $found; $i++) { + $this->pause(20); + $found = strpos($this->source(), $text) !== false; + } + $this->assertFalse($found, "Failed asserting that page source does not contain $text"); + } + + + + +} -- cgit v1.2.3