Yes, you need this when you are trying to run you test cases one after another and you don't want to restart the browser as well as you want to avoid creating new profile to run new test case. Restarting browser and creating a new brand profile is slow and time consuming. There are multiple solution for this.
* Create a batch file and call in you code before you start your test case. For more information here.
* Write a javascipt to clear the cache. Go here.
* Use Selenium.deleteCookie ( name,optionsString )
* Use Selenium.deleteAllVisibleCookies()
I am using selenium.delete and selenium.deleteAllVisibleCookies method provided by selenium RC.
deleteCookie ( name,optionsString )
Delete a named cookie with specified path and domain. Be careful; to delete a cookie, you need to delete it using the exact same path and domain that were used to create the cookie. If the path is wrong, or the domain is wrong, the cookie simply won't be deleted. Also note that specifying a domain that isn't a subset of the current domain will usually fail. Since there's no way to discover at runtime the original path and domain of a given cookie, we've added an option called 'recurse' to try all sub-domains of the current domain with all paths that are a subset of the current path. Beware; this option can be slow. In big-O notation, it operates in O(n*m) time, where n is the number of dots in the domain name and m is the number of slashes in the path.
Arguments:
· name - the name of the cookie to be deleted
· optionsString - options for the cookie. Currently supported options include 'path', 'domain' and 'recurse.' The optionsString's format is "path=/path/, domain=.foo.com, recurse=true". The order of options are irrelevant. Note that specifying a domain that isn't a subset of the current domain will usually fail.
For my test case I am not using “recurse” parameter. In result my deletion of cache is prety fast. As I have droped “recurse” so “domain”. So Example is here.
selenium.deleteCookie(“JSESSIONID”,”path=/console”);
You can see cookies name and path in your browser(FF). Tools -> Options -> Privacy -> remove individual cookie -> and type the url in search.
Now when you use “recurse” your optionsString will change slightly.
optionsString = “path=/console/”, domain=”.bbtest.net”, “recurse=true”)
Note: Extra / at the end of path. Dot(.) before the domain name.
Selenium.deleteAllVisibleCookies() , It does not have any parameters. It is like calling selenium.deleteCookie with “recurse=true”
Hope this will help you.