- getafix
- Posts : 3
Join date : 2009-09-10
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
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
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
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
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
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
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
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
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
Mon Sep 06, 2010 7:18 am
Do we know how to do this kind of batch file in linux?
- metmanAmateur
- Posts : 58
Join date : 2010-04-02
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.
- hmohamed
- Posts : 2
Join date : 2010-10-06
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")
(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
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_);
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_);
- How to delete history and caches in selenium ide?
- Selenium RC with C#: How to Delete or edit particular item?
- HOW TO RUN SERVER AUTOMATICALLY IN ECLIPSE USING SELENIUM RC
- Can I have Selenium re-log into a page if I've been automatically logged out?
- Can anyone help me to resolve the cache error in selenium webdriver?
Permissions in this forum:
You cannot reply to topics in this forum