Canoo Webtest WebTest Canoo

Core Step storeCookie


Provides the ability to store an HTTP Cookie value for later checking.


Required? yes
The name of the cookie of interest. If the property name is not specified, the cookie name is used as key to store the value found.
Required? no
The description of this test step.
Required? no
The name of the property in which to store the retrieved value.
Required? no, default is the "defaultPropertyType" as specified in the "config" element is used.
The type of the property in which to store the retrieve value. Either "ant" or "dynamic".


Suppose that we have created a JSP called visitCount.jsp which increments a cookie called VISITCOUNT each time we visit the page. The following test code can test the cookie usage of this JSP:

storeCookie Example1
<webtest name="cookie: visit count test example">
    <config ...>
        <invoke description="reset in case someone else has used this page"
        <invoke description="expect cookie-based counter to be 0url="visitCount.jsp"/>
        <verifyTitle description="confirm correct pageregex="truetext="Visit Counter.*" />
        <storeCookie name="JSESSIONIDproperty="sessid" />
        <verifyCookie name="VISITCOUNTtext="1" />
        <invoke description="session id shouldn't change, cookie-based counter should increment"
        <verifyCookie name="JSESSIONIDtext="#{sessid}" />
        <verifyCookie name="VISITCOUNTtext="2" />

Cookie usage is as follows:

The JSESSIONID cookie is used by Java web servers to manage user sessions and should be unique between visitors.
The VISITCOUNT cookie is used to track unique hits to the site and should increment after each invoke.

Browsers store cookie values away persistently (except for transient cookies - but that is another story). Canoo WebTest doesn't support persistence of cookies (although you could simulate that using ANT functionality). What is possible however without further ANT tasks is the ability to set an initial cookie value. This lets you partially simulate a persistent cookie. This is done by using the header nested element within the config section of your test. Here is an example using verifyCookie and an initial cookie value for the above example.

storeCookie Example2
<webtest name="cookie: visit count test example">
    <config ...>
        <header name="Cookievalue="visitCount=100"/>
        <invoke description="expect cookie-based counter to be 100url="visitCount.jsp"/>
        <verifyTitle description="confirm correct pageregex="truetext="Visit Counter.*" />
        <verifyCookie description="cookie-based counter should have been incremented from preset value"
            name="visitCounttext="101" />

See also: the verifyCookie step.


Latest build: development
Posted: 19-Jul-2016 17:36

WebTest 3.0 released, featuring upgrades to Java 5, Groovy 1.6, and HtmlUnit 2.4.
The release includes support for maven integration, IDE-integration like for unit tests, capturing of background JavaScript errors, new steps for mouseOver and mouseOut events, better parallel execution of tests and - as usual - lots of handling improvements.
Posted: 5 March 2009

WebTest @ JavaOne
Dierk König presented "Functional testing of web applications: scaling with Java" on Wed May 7, 13:30 at JavaOne 2008 in the Tools and Scripting Languages track.
Posted: 8 May 2008

New WebTest screencast available:
Data Driven WebTest
Posted: 13 November 2007

First WebTest screencast available:
Creating a first Webtest Project

Extend WebTest with Groovy! Groovy in Action is available in every good bookstore.
Groovy in Action
Posted: 29 January 2007