Tuesday, 25 August 2009

Working with Cookies and caches Using WATiN 2.0

Release of WATiN 2.0 having work around with cookies and caches like
1. Clear cookies /caches
2. Get and set cookies

1. Clear cookies/caches
This functionality/method we can call any time during the live instance of an IE.
We need to call this method just after creating new instance of an IE.
Example: below code would clear cookies/caches just after creating new instance of an IE.

using(IE ie = new IE())
{
ie.ClearCache;
ie.ClearCookies;
ie.GoTo(“http://jawedmblogspot.com”);
}
Caution: if we call this method at later moment then the open instance of an IE still might have cached items in memory. To avoid this situation we need to use new IE.ReOpen() method. This method would close the previous open Instance and reopens new IE instances which solve our problem.

2. Get and set cookies
To manipulate Cookies and/or to read cookie information, IE.GetCookie() and IE.SetCookie are added.
using(IE ie = new IE("http://jawedm.blogspot.com"))
{
string setvalue = "test-cookie=abc; expires=Wed, 01-Jan-2020 00:00:00 GMT";
ie.SetCookie("http://1.watin.com/", setvalue);
string getvalue = ie.GetCookie("http://1.watin.com/", "test-cookie");
Assert.AreEqual("test-cookie=abc", getvalue);
}

for more information you can visit below website
http://watin.sourceforge.net/releasenotes-1-2-0-4000.html
Thanks!!!!