Saturday, July 16, 2011

Working with cookies in QTP

Cookies are temporary internet files which were created by Web Server in users Harddisk. When we make a request to a website, the Web Server looks for the

cookie in our Harddisk, and uses the stored information(if it finds), or creates a new cookie file in our system.
Only the webserver can understand the cookie information properly, we cannot understand the content of the cookie properly.
Cookies can be long-term, short term.
Long term cookies, can be saved as per the configured number of days(may be months or year)
Short term cookies get deleted once you visited the site and close the browser.
We can access the cookies information by Start->Run ->cookies and enter

We can test these cookies using QTP.

In QTP there is utility called "WebUtil" which was supported completely upto QTP 6.0. Later it was not supported fully. It is there only for backward

compatability.
We have couple of methods related to cookies like:
WebUtil.Addcookie
WebUtil.Deletecookie
WebUtil.Deletecookies 'deletes all cookies in the system
WebUtil.Getcookies

There is otherway around to delete cookies using Windows shell object:
SysUserName=Environment.Value("UserName")
Set ShellObj=CreateObject("WScript.shell")
ShellObj.run("cmd /C cd C:\Documents and Settings\" & SysUserName & "\Cookies & del *.txt")
Set ShellObj=nothing

The above two methods works with IE not with other browsers.

1 comment:

QPT said...

Hi Uday,

First of all want to Thank You for your useful post.

This Software Testing article is very useful for me. I would like to introduce another good site which is having Software testing and QTP resource site, Have a
look on QTPbook