3

I'm runnig Selenium tests with PHPUnit.

I have some long test sequences split into several test files to make them easier to maintain. For higher speed I would like to re-use the browser session for these cases.

I am able to reuse the sessions (PHPUnit_Extensions_SeleniumTestCase::shareSession(true)), but I cannot figure out how to end the session and open a new one before starting the next tests (which require a fresh browser session).

I have tried using the following line in the tearDown() method of the test to kill the current browser session

$this->stop();

this kills the browser, but generates an error: "Session xxxxxx does not exist or was ended"

=> Exactly, but how do I get Selenium to start a new session in this case?

Thanks for any clues.

Thomas
  • 31
  • 1
  • 2

2 Answers2

0

When I create a few tests method in my test class (test file), I don't use

$this->stop();
in tearDown() method. I noticed that at the end of each test, the browser simply closes itself. I just set browser and browser URL in setUp() method and I open it in every test method by using
$this->open('/');


Have you tried in this simple way?

faramka
  • 2,164
  • 1
  • 18
  • 21
  • Thank you for your input - yes indeed, this works as you describe, but I want to keep the browser session open after a test and re-use it for the next one. After a chain of tests I want to kill the browser session and start a new one. In short: I want the browser sessions to be re-used by default, but for some tests I would like to be able to close the session and open a new one. – Thomas Jan 16 '12 at 21:00
  • OK, I get it. Maybe this could help: http://groups.google.com/group/selenium-users/browse_frm/thread/418087a0f93ece04/bc325d34b998241c?lnk=gst&q=Reusing+same+browser+#bc325d34b998241c – faramka Jan 17 '12 at 07:23
0

Try adding the

-browserSessionReuse

parameter when launching an Selenium RC node.

Jochen
  • 1,853
  • 3
  • 20
  • 28
  • Hello Jochen, thanks for your answer. The way I understand it, `PHPUnit_Extensions_SeleniumTestCase::shareSession(TRUE)` does exactly the same. My problem is how to end a browser session and start a new one when using this option – Thomas Jan 19 '12 at 13:14