Skip to content

Instantly share code, notes, and snippets.

@andrewwheal
Created April 21, 2015 10:14
Show Gist options
  • Save andrewwheal/6f921ec761913babad82 to your computer and use it in GitHub Desktop.
Save andrewwheal/6f921ec761913babad82 to your computer and use it in GitHub Desktop.
Abstract Selenium Test Case - checking for Internal Server Error pages
<?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