I am unable to clear cookies using watir-webdriver and browser.cookies.clear Are there any other alternatives ?

有帮助吗?

解决方案

This is as far as I know a browser based limitation, due to concerns of security and privacy.

Webdriver is interacting with the browser by javascript, and javascript is not allowed to clear all cookies (think how nasty that could be on a malicious site). In the non testing env, most JS that is executing came from the server of the site you are accessing. So the most it is allowed to do is clear the cookies for the 'current domain' e.g. the cookies belonging to the current URL. So if a web page wants to clear all its own cookies, that is OK, but it is not allowed to clear cookies belonging to other domains.

So if you want all your tests to start with fresh cookies, you will need something in the 'Before' section in env.rb that goes to the root of the site in question, and then clears the cookies

BTW the same limitation applies to setting cookies, if you want to create cookies for a specific site, you need to navigate to that site before trying to create them, or nothing gets created.

其他提示

This is not an answer, but FYI only.

Suppose chrome is the chosen browser, when cucumber is running, from the output of ps -ef | grep chrome we'll be able to find the customized user data directory which is something like below.

--user-data-dir=/tmp/.org.chromium.Chromium.G2DgPo

And inside that directory, we'll be able to find the Cookies file stored under the Default folder.

Not sure directly deleting that database file could fulfill the needs or not. Cause in a normal browser session, such runtime data are stored at

~/.config/google-chrome/Default/Cookies
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top