views:

47

answers:

1

I have a loop that checks for the existence of urls. If one does not exist Selenium exits: *XHR ERROR: URL = http://localhost/pages/156.php Response_Code = 404 Error_Message = Not Found.*

If i catch the exception:

try {
     $this->selenium->open($url);
}
catch(PHPUnit_Framework_Exception $e) { echo "caught\n"; }

Anything i do afterwards gives me this error: ERROR Server Exception: sessionId should not be null; has this session been started yet?

I even tried to set the exception as expected:

$this->selenium->setExpectedException('PHPUnit_Framework_Exception');

But still the session is stopped and the test is completed. How can i make Selenium keep testing the urls? Thanks.

+1  A: 

Create new selenium instance for every url!

$this->selenium = new Testing_Selenium("*firefox", "http://your-app-under-test.org/");
$result = $this->selenium->start();
$this->selenium->open("/the-page-to-test.php");

or see http://pear.php.net/package/Testing_Selenium/docs/0.4.3/Selenium/Testing_Selenium.html#method__construct for reference, there are more arguments to the constructor.

Moritz Both
Thanks Moritz, you are right. Actually i can catch the exception and then start a new session. This works!
f.siafarikas