Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

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

How to delete cache automatically in selenium Empty How to delete cache automatically in selenium

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
Advisor
Advisor
------------------------
------------------------
Posts : 387
Join date : 2009-07-30
Location : India
https://seleniumforum.forumotion.net

How to delete cache automatically in selenium Empty Re: How to delete cache automatically in selenium

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
avatar
getafix
Posts : 3
Join date : 2009-09-10

How to delete cache automatically in selenium Empty Re: How to delete cache automatically in selenium

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
Advisor
Advisor
------------------------
------------------------
Posts : 387
Join date : 2009-07-30
Location : India
https://seleniumforum.forumotion.net

How to delete cache automatically in selenium Empty Re: How to delete cache automatically in selenium

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
avatar
getafix
Posts : 3
Join date : 2009-09-10

How to delete cache automatically in selenium Empty Re: How to delete cache automatically in selenium

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

How to delete cache automatically in selenium Empty Re: How to delete cache automatically in selenium

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

How to delete cache automatically in selenium Empty Re: How to delete cache automatically in selenium

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.
avatar
hmohamed
Posts : 2
Join date : 2010-10-06

How to delete cache automatically in selenium Empty Re: How to delete cache automatically in selenium

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



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

How to delete cache automatically in selenium Empty Re: How to delete cache automatically in selenium

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

How to delete cache automatically in selenium Empty Re: How to delete cache automatically in selenium

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