简体   繁体   English

Selenium RC - 禁用浏览器cookie

[英]Selenium RC - disabling browser cookie

Is it possible to disable a browser cookie using selenium, RC specifically? 是否可以使用selenium,RC专门禁用浏览器cookie? If so, what is the api call or sequence of calls to make this happen. 如果是这样,api调用或调用序列是什么来实现这一点。 There is a feature being tested where theres a need to verify the behavior when cookies are enabled or disabled. 正在测试一项功能,即在启用或禁用cookie时需要验证行为。 Thanks 谢谢

There's an easier way with using only a default profile, if on Selenium 2.x. 如果在Selenium 2.x上,只使用默认配置文件有一种更简单的方法。

FirefoxProfile profile=new FirefoxProfile();
profile.setPreference("network.cookie.cookieBehavior",2);

As specified in the comment. 如评论中所述。 If you are using FF, you could specify the profile to be used. 如果使用FF,则可以指定要使用的配置文件。

The way to do it it so specify the browserStartCommand (3rd argument of the DefaultSelenium constructor) to something similar to: 这样做的方法是将browserStartCommand( DefaultSelenium构造函数的第三个参数)指定为类似于:

*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. 此配置文件可以禁用cookie。

If you are going to be using Firefox there is a specific command to access the firefox template. 如果您要使用Firefox,则有一个特定的命令来访问firefox模板。 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. 我会使用不同的配置文件开启和关闭cookie,因为你可以更好地控制它。

Another idea (I haven't tried that) would be to use a special proxy between the Selenium RC client and the tested web application. 另一个想法(我没有尝试过)将是在Selenium RC客户端和测试的Web应用程序之间使用特殊代理 The proxy would be able to filter the cookies when asked to. 代理人可以在被要求时过滤cookie。

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. 我很确定你能找到一个具有阻止cookie的功能。

EDIT: This solution has the advantage of being browser-independent. 编辑:此解决方案具有独立于浏览器的优势。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM