How can I clear cookies for each tests in my PhantomJS + GhostDriver + Selenium WebDriver + WebDriver Client system?
My test process looks like this:
When I use firefox browser instead of phantomjs all tests passed ok. But when I switch to using phantomjs as browser all tests that checked registration failed because cookies already set after first test execution. Can I clear all cookies on every test start up? Or I should to restart phantomjs process on every separate test (as this is with firefox and selenium webdriver in not hub role)?
Maybe some offtopic, cause author marked that he uses php to run test.
But if you came from google and interested in C# solution to clear all cookies, look below:
// driver is fully initialized PhantomJS instance
driver.Manage().Cookies.DeleteAllCookies();
Requires NuGetPackages:
PhantomJS 2.0.0
Selenium.Support 2.48.2
Selenium.WebDriver 2.48.2
Tested with .NETFramework v4.5.2
You can delete specific cookie using:
webDriver.manage().deleteCookieNamed("smSession");
And to delete all the cookies using:
webDriver.manage().deleteAllCookies();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With