Reputation: 8575
I'm using Selenium Webdriver (Java) and PhantomJS to test a complex JS driven website. My problem is, that the PhantomJS browser keeps the session between two tests which leads to errors in the test setup.
If I run the tests with Firefox everything works fine because Firefox uses a clean session for every test case.
My first attempt to solve the problem was to just clear the local storage by JS injection. Cookies are deleted by the Selenium exposed API driver.manage().deleteAllCookies();
But executing JavaScript without visiting a page is not allowed. So starting the browser at "about:blank" leads to an error.
So, how do I configure my phantomjs webdriver to clear the session?
I'm using phantomjs and webdriver because the selenium-grid services turned out to be not stable enough. So I start my phantomjs instance like that:
phantomjs --webdriver=1234
Upvotes: 8
Views: 11178
Reputation: 101
The version 2.0 of PhantomJS fix this issue. If you have a Linux Enviroment, you need clone the sources and compile, like this:
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 2.0
./build.sh
Upvotes: 0
Reputation: 11723
The fact that PhantomJS keeps sessions between tests is a known problem in GhostDriver, the Selenium Webdriver implementation in PhantomJS.
I suppose that this problem will be fixed with the PhantomJS 2 release. The bug is already fixed in GhostDriver 1.1.1, but there is no PhantomJS version which includes this GhostDriver version.
Upvotes: 7
Reputation: 29669
I know that Selenium Grid has a "cleanSession" option if you use GhostDriver. Also, I am pretty sure the regular WebDriver class has a option for this on a local WebDriver instance:
driver.manage().deleteAllCookies();
Upvotes: 2