Certified Selenium Professiona Learning Resources Cookie management

Learning Resources
 

Cookie management


There are many selenese commands used for cookie management and which are -

createCookie ( nameValuePair,optionsString )
Create a new cookie whose path and domain are same with those of current page under test, unless you specified a path for this cookie explicitly.

Arguments:

  • nameValuePair - name and value of the cookie in a format "name=value"
  • optionsString - options for the cookie. Currently supported options include 'path', 'max_age' and 'domain'. the optionsString's format is "path=/path/, max_age=60, domain=.foo.com". The order of options are irrelevant, the unit of the value of 'max_age' is second. Note that specifying a domain that isn't a subset of the current domain will usually fail.
deleteAllVisibleCookies ( )
Calls deleteCookie with recurse=true on all cookies visible to the current page. As noted on the documentation for deleteCookie, recurse=true can be much slower than simply deleting the cookies using a known domain/path.

deleteCookie ( name,optionsString )
Delete a named cookie with specified path and domain. Be careful; to delete a cookie, you need to delete it using the exact same path and domain that were used to create the cookie. If the path is wrong, or the domain is wrong, the cookie simply won't be deleted. Also note that specifying a domain that isn't a subset of the current domain will usually fail. Since there's no way to discover at runtime the original path and domain of a given cookie, we've added an option called 'recurse' to try all sub-domains of the current domain with all paths that are a subset of the current path. Beware; this option can be slow. In big-O notation, it operates in O(n*m) time, where n is the number of dots in the domain name and m is the number of slashes in the path.

Arguments:

  • name - the name of the cookie to be deleted
  • optionsString - options for the cookie. Currently supported options include 'path', 'domain' and 'recurse.' The optionsString's format is "path=/path/, domain=.foo.com, recurse=true". The order of options are irrelevant. Note that specifying a domain that isn't a subset of the current domain will usually fail.
storeCookie ( variableName )
Return all cookies of the current page under test.

 

Returns:
all cookies of the current page under test

Related Assertions, automatically generated:

storeCookieByName ( name, variableName )
Returns the value of the cookie with the specified name, or throws an error if the cookie is not present.

Arguments:

  • name - the name of the cookie
  • variableName - the name of a variable in which the result is to be stored.

 

Returns:
the value of the cookie

Related Assertions, automatically generated:

  • assertCookieByName ( name, pattern )
  • assertNotCookieByName ( name, pattern )
  • verifyCookieByName ( name, pattern )
  • verifyNotCookieByName ( name, pattern )
  • waitForCookieByName ( name, pattern )
  • waitForNotCookieByName ( name, pattern )
storeCookiePresent ( name, variableName )
Returns true if a cookie with the specified name is present, or false otherwise.

Arguments:

  • name - the name of the cookie
  • variableName - the name of a variable in which the result is to be stored.

 

Returns:
true if a cookie with the specified name is present, or false otherwise.

Related Assertions, automatically generated:

  • assertCookiePresent ( name )
  • assertCookieNotPresent ( name )
  • verifyCookiePresent ( name )
  • verifyCookieNotPresent ( name )
  • waitForCookiePresent ( name )
  • waitForCookieNotPresent ( name )

 

 

 For Support