PhantomJS and Selenium Webdriver - How to Clear a Session

I use Selenium Webdriver (Java) and PhantomJS to test a complex JS managed website. My problem is that the PhantomJS browser maintains a session between the two tests, which leads to errors in the test setup.

If I run tests with Firefox, everything works fine because Firefox uses a clean session for each test case.

My first attempt to solve the problem was to simply clear the local storage using JS injection. Cookies are deleted using the Selenium API driver.manage().deleteAllCookies();

But running JavaScript without visiting the page is prohibited. Therefore, starting the browser with "about: empty" leads to an error.

So how to configure my phantomjs webdriver to clean up the session?

I use phantomjs and webdriver because selenium grid services were not stable enough. Therefore, I run my phantomjs example as follows:

 phantomjs --webdriver=1234 
+8
java selenium testing phantomjs ghostdriver
source share
3 answers

The fact that PhantomJS conducts sessions between tests is a known issue in GhostDriver, an implementation of Selenium Webdriver in PhantomJS.

I believe this problem will be fixed with the release of PhantomJS 2. The error is already installed in GhostDriver 1.1.1, but there is no version of PhantomJS that includes this version of GhostDriver.

+7
source share

I know that Selenium Grid has a "cleanSession" parameter if you use GhostDriver . In addition, I'm sure that the regular WebDriver class has an option for this in the local WebDriver instance:

 driver.manage().deleteAllCookies(); 
+2
source share

PhantomJS version 2.0 fixes this problem. If you have Linux Enviroment, you need to clone the sources and compile, for example:

 git clone git://github.com/ariya/phantomjs.git cd phantomjs git checkout 2.0 ./build.sh 

More info here

0
source share

All Articles