Share
Go down
getafix
Posts : 3
Join date : 2009-09-10

How to delete cache automatically in selenium

on Thu Feb 11, 2010 6:12 pm
Hi All

I want to automatically delete cache and cookies in selenium

How can i do this in selenium-java

Can anyone exemplify


Second problem

Often i get the Internet explorer script error pop-up while running my tests .Not in all pages but in certain screens!
why is this coming
Is this something to do with proxy settings or ??
If so please let me know how to overcome this

Thanks very much in advance
avatar
Advisor
------------------------
------------------------
Posts : 387
Join date : 2009-07-30
Location : India
http://seleniumforum.forumotion.net

Re: How to delete cache automatically in selenium

on Sat Feb 20, 2010 2:01 pm
hi,

HOW WE'RE DELETING COOKIES: : By java you can directly do this.

protected void deleteCookie(String cookieName)
{
String cookieDomain =
CTPropertiesManager.getProperty("site.properties",

"site.cookie.domain");

try
{
//get all cookies
Cookie cookies[] = request.getCookies();

Cookie ctCookie=null;
if (cookies !=null)
{
for(int i=0; i<cookies.length; i++)
{
ctCookie=cookies[i];
if (ctCookie.getName().trim().equals(cookieName))
{
if ( cookieDomain != null )
{
ctCookie.setDomain(cookieDomain);
}

ctCookie.setPath("/ct");
ctCookie.setMaxAge(0);
response.addCookie(ctCookie);
}
}//end for
}//end if cookie
}//end try
catch(Exception e){
CTLogManager.log(e);
}
}//end deleteCookie()



For deleting cache
You can create one bat file which clear your browser or application cache before test start. after creating bat file just call in your code before test start.

Hope this will help you little bit. Best of luck.

Bye
getafix
Posts : 3
Join date : 2009-09-10

Re: How to delete cache automatically in selenium

on Mon Feb 22, 2010 5:28 am
Hello Administrator

Thanks very much for your illustrated reply !

I managed to overcome the cookies

I am
Can you please give the example code to delete cache using bat file as well in firefox /IE8

I am using testNG framework
Please excuse me as i am new to java/selenium

Very much appreciated

Thanks
avatar
Advisor
------------------------
------------------------
Posts : 387
Join date : 2009-07-30
Location : India
http://seleniumforum.forumotion.net

Re: How to delete cache automatically in selenium

on Mon Feb 22, 2010 12:20 pm
For deleting cache with the help of bat file, check out this link:

http://www.hardwarehell.com/articles/bootclean.shtml

Best of luck
getafix
Posts : 3
Join date : 2009-09-10

Re: How to delete cache automatically in selenium

on Mon Feb 22, 2010 12:45 pm
Thanks very much for your quick reply !!
vemu
Posts : 2
Join date : 2010-09-06

Re: How to delete cache automatically in selenium

on Mon Sep 06, 2010 7:18 am
Do we know how to do this kind of batch file in linux?
metman
Amateur
Amateur
Posts : 58
Join date : 2010-04-02

Re: How to delete cache automatically in selenium

on Wed Sep 08, 2010 12:07 am
While this will work if you need to delete cookies/cache mid-test, if all you want to do is start a test with cookies and cache cleared, you can etiher rely on Selenium to start with a clean profile (fairly certain that is the default behavior) or use a custom generated completely clean user profile as an argument when launching SeleniumRC. I know that works for FF in the least.
hmohamed
Posts : 2
Join date : 2010-10-06

Re: How to delete cache automatically in selenium

on Wed Oct 06, 2010 12:53 am
Here's how to delete the browser cache without having restart the browser, or creating a brand new profile:
(1) Delete cookies, refresh browser
(2) Delete browser cache via javascript

public void clearBrowserCache() {
webDriver.manage().deleteAllCookies();
selenium.refresh();
webDriver.navigate().to("file:///c:/tmp/ClearCacheFirefox.html");
}

Contents of ClearCacheFirefox.html




Response.Cache.SetExpires(DateTime.Parse(DateTime.Now.ToString()))
Response.Cache.SetCacheability(HttpCacheability.Private)
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")



hmohamed
Posts : 2
Join date : 2010-10-06

Re: How to delete cache automatically in selenium

on Wed Oct 06, 2010 6:50 am
Oh yeah, you can call the javascript directly without putting in an html doc:

String jScript_ = "" +
"Response.Cache.SetExpires(DateTime.Parse(DateTime.Now.ToString()))\n" +
"Response.Cache.SetCacheability(HttpCacheability.Private)\n" +
"Response.Cache.SetNoStore()\n" +
"Response.AppendHeader("Pragma", "no-cache")";

selenium.getEval(jScript_);
Sponsored content

Re: How to delete cache automatically in selenium

Back to top
Permissions in this forum:
You cannot reply to topics in this forum