Created
April 21, 2015 10:14
-
-
Save andrewwheal/6f921ec761913babad82 to your computer and use it in GitHub Desktop.
Abstract Selenium Test Case - checking for Internal Server Error pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AbstractTestCase extends PHPUnit_Extensions_Selenium2TestCase | |
{ | |
/** | |
* Check for internal server errors and reload the page upto 3 times | |
*/ | |
protected function checkInternalServerError() | |
{ | |
$url = $this->url(); | |
$i = 0; | |
while ($this->check500Error() and $i++ < 3) | |
{ | |
$cliOutput = "500 error detected. Retrying attempt " . $i; | |
fwrite(STDOUT, PHP_EOL . $cliOutput . PHP_EOL); | |
$this->url($url); | |
} | |
} | |
/** | |
* Check 500 type error (internal server error) | |
* | |
* @return bool | |
*/ | |
protected function check500Error() | |
{ | |
try | |
{ | |
// Check for Internal server error header | |
$errorHeader = $this->byCssSelector('h1'); | |
return $errorHeader and $errorHeader->text() === 'Internal Server Error'; | |
} | |
catch(Exception $e) | |
{ | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment