I am using PHPUnit & Selenium2 server. I am using PageObject pattern. To a page object I get an instance of the webdriver and perform necessary functions.
To keep a single browser running I implemented a crude solution which I found in the net where I initialize the driver within a static class:
class SessionHelper {
public static $first;
}
SessionHelper::$first = 0;
Then in my test case class setup() method;
public function setUp(){
if (SessionHelper::$first == 0 )
{
$this->setHost('localhost');
$this->setPort((int)4444);
$this->setBrowser('firefox');
$this->setBrowserUrl('http://domain.com/lucky/web');
$this->shareSession(TRUE);
$this->prepareSession();
SessionHelper::$first = 1 ;
}
}
This way I manage to execute all tests in a single browser. However if one test case fails; say by trying to find a non-existent element, all the other test cases fails with a message "Undefined index: browserUrl". If I change it to look for a known element in the page, it works fine. So for example;
test_method_1 : if an element is not found anything after this test fails with the "Undefined index: browserUrl".
if test_method_1 went ok, rest of the tests will execute until another test case fails.
So, what can be the reason for me to get this error? When one test case fails does my session get destroyed?
PHPUnit_Extensions_Selenium2TestCase::shareSession(true);in your phpunit bootstrap?