问题
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.
回答1:
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?
回答2:
Try adding the
-browserSessionReuse
parameter when launching an Selenium RC node.
来源:https://stackoverflow.com/questions/8874241/selenium-phpunit-end-a-session-when-re-using-browser-sessions