Is it possible to disable a browser cookie using selenium, RC specifically? If so, what is the api call or sequence of calls to make this happen. There is a feature being tested where theres a need to verify the behavior when cookies are enabled or disabled. Thanks
问题:
回答1:
As specified in the comment. If you are using FF, you could specify the profile to be used.
The way to do it it so specify the browserStartCommand (3rd argument of the DefaultSelenium
constructor) to something similar to:
*custom "C:/Program Files/Mozilla Firefox/firefox.exe" -no-remote -profile "C:/Some/Path/To/Mozilla/Firefox/Profiles/selenium"
And this profile you could have the cookies disabled.
回答2:
There's an easier way with using only a default profile, if on Selenium 2.x.
FirefoxProfile profile=new FirefoxProfile();
profile.setPreference("network.cookie.cookieBehavior",2);
回答3:
If you are going to be using Firefox there is a specific command to access the firefox template. You use
-firefoxProfileTemplate "path to the profile"
as described here. I would use the different profiles for cookies on and off as that way you can control it a lot better.
回答4:
Another idea (I haven't tried that) would be to use a special proxy between the Selenium RC client and the tested web application. The proxy would be able to filter the cookies when asked to.
There are some proxy implementations intended for development, debugging and tracing roles. I am pretty sure you can find one with the feature to block cookies.
EDIT: This solution has the advantage of being browser-independent.