Selenium RC - disabling browser cookie

痴心易碎 提交于 2019-12-24 08:23:58

问题


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.



来源:https://stackoverflow.com/questions/1126282/selenium-rc-disabling-browser-cookie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!