Afamee
Afamee

Reputation: 5320

Selenium RC - disabling browser cookie

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

Upvotes: 1

Views: 3720

Answers (4)

Anatolii
Anatolii

Reputation: 14680

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);

Upvotes: 2

Grzegorz Oledzki
Grzegorz Oledzki

Reputation: 24291

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.

Upvotes: 0

AutomatedTester
AutomatedTester

Reputation: 22438

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.

Upvotes: 1

Grzegorz Oledzki
Grzegorz Oledzki

Reputation: 24291

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.

Upvotes: 1

Related Questions