Website Cookie Testing & Test Cases for Testing Web Application Cookies

Introduction to cookies:

Primarily we will focus on what exactly cookies are and how they work. It would be easy for you to understand the test cases for testing cookies when you have a clear understanding of how cookies work? How cookies get stored on hard drive? and how can we edit cookie settings?

What You Will Learn:

What is a Cookie?

A cookie is a small information stored in a text file on user’s hard drive by a web server. This information is later used by the web browser to retrieve information from that machine. Generally, the cookie contains personalized user data or information that is used to communicate between different web pages.

Why Are Cookies used?

Cookies are nothing but the user’s identity and are used to track where the user navigated throughout the website pages. The communication between web browser and a web server is stateless.

Example:

If you are accessing domain “http://www.example.com/1.html” then the web browser will simply query to example.com web server for the page 1.html. Next time if you type page as “http://www.example.com/2.html” then new request is sent to example.com web server for sending 2.html page and the web server does not know anything about to whom the previous page 1.html served.

What if you want the previous history of this user communication with the web server? You need to maintain the user state and interaction between a web browser and web server somewhere. This is where cookie comes into the picture. Cookies serve the purpose of maintaining the user interactions with a web server.

How do cookies work?

The HTTP protocol used to exchange information files on the web is used to maintain the cookies.

There are two types of the HTTP protocol. Stateless HTTP and Stateful HTTP protocol. Stateless HTTP protocol does not keep any record of previously accessed web page history. While Stateful HTTP protocol does keep some history of previous web browser and web server interactions and this protocol is used by the cookies to maintain the user interactions.

Whenever a user visits a site or page that is using a cookie, the small code inside that HTML page (Generally a call to some language script to write the cookie like cookies in JAVAScript, PHP, Perl) writes a text file on users machine called a cookie.

Here is one example of the code that is used to write a cookie and can be placed on any HTML page:

Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME;

When a user visits the same page or domain later time this cookie is read from disk and used to identify the second visit of the same user on that domain. The expiration time is set while writing the cookie. This time is decided by the application that is going to use the cookie.

Generally, two types of cookies are written on the user machine

#1) Session cookies:

This cookie is active till the browser that invoked the cookie is open. When we close the browser this session cookie gets deleted. Some time session of say 20 minutes can be set to expire the cookie.

#2) Persistent cookies:

These are cookies that are written permanently on the user machine and lasts for months or years.

Where are cookies stored?

When any web page application writes a cookie it gets saved in a text file on user hard disk drive. The path where the cookies get stored depends upon the browser. Different browsers store a cookie in different paths.

The below-mentioned paths are examples where cookies are stored:

Internet Explorer: “C:\Users\username\AppData\Roaming\Microsoft\Windows\Cookies”.

Windows 7: “C:\Users\username\AppData\Roaming\Microsoft\Windows\Cookies\Low”.

Windows 8 and Windows 10: “C:\Users\username\AppData\Local\Microsoft\Windows\INetCookies”.

Here the “Default User” can be replaced by the current user you logged in as like “Administrator”, or username like “Vijay” etc.

The cookie path can be easily found by navigating through the browser options.

In Mozilla Firefox browser you can even see the cookies in the browser options itself. Open the Mozilla browser, press “Open menu” button? “Web Developer”? “Storage Inspector” or by pressing combination “Shift + F9”.

In Google Chrome browser you can find cookies by typing “chrome://settings/content/cookies” in your address bar. Cookies also can be accessed using browser console (F12 –> application –> storage –> cookies ->).

How are cookies stored?

Let’s take an example of cookie written by rediff.com on Mozilla Firefox browser. On Mozilla Firefox browser when you open the page rediff.com or login to your rediffmail account, a cookie will get written on your Hard disk. To view this cookie simply click on “Show cookies” button mentioned in the above path. Click on Rediff.com site under this cookie list.

You can see different cookies written by Rediff domain with different names.

Site: Rediff.com Cookie name: RMID

Name: RMID (Name of the cookie)

Content: 1d11c8ec44bf49e0… (Encrypted content)

Domain: .rediff.com

Path: / (Any path after the domain name)

Send For: Any type of connection

Expires: Thursday, December 31, 2020, 11:59:59 PM

Applications where cookies can be used:

#1) To implement shopping cart:

Cookies are used for maintaining online ordering system. Cookies remember what user wants to buy. What if the user adds some products to their shopping cart and if due to some reason the user doesn’t want to buy those products this time and closes the browser window?

In the above instance when next time the same user visits the purchase page he can see all the products he added to the shopping cart during his last visit.

#2) Personalized sites:

When a user visits a certain page, they are asked which pages they don’t want to visit or display. User options get stored in a cookie and till the user is online, those pages are not shown to him.

#3) User tracking: 

To track the number of unique visitors online at the particular time.

#4) Marketing:

Some companies use cookies to display advertisements on user machines. Cookies control these advertisements. When and which advertisement should be shown? What is the interest of the user? Which keywords do the search on the site? All these things can be maintained using cookies.

#5) User sessions:

Cookies can track user sessions to the particular domain using user ID and password.

Drawbacks of Cookies

#1) Even writing a Cookie is a great way to maintain user interaction, if the user has set browser options to warn before writing any cookie or disabled the cookies completely then site containing cookie will be completely disabled and it cannot perform any operation resulting in loss of site traffic. This can be disabled/enabled in browser setting.

For example for google chrome you need to go Setting->Advanced->Content Settings->Cookies. There you can apply a general rule for cookie policy, or set it for individual websites.



Additionally to browser settings, there are some changes in regulations in EU and US that force developers to warn a user that cookies are used on the website. Compliance with such new regulations should also be as part of tests scenarios for certain regions.

#2) Too many Cookies:

If you are writing too many cookies on every page navigation and if the user has turned on an option to warn before writing the cookie, this could even turn away user from your site.

#3) Security Issues:

Sometimes, users, personal information is stored in cookies and if someone hacks the cookie then a hacker can get access to your personal information. Even corrupted cookies can be read by different domains and lead to security issues.

#4) Sensitive Information:

Some sites may write and store your sensitive information in cookies, which should not be allowed due to privacy concerns. This should be enough to know what cookies are. If you want more cookie info see Cookie Central page.

Test Cases for Web Application Cookie Testing

The first obvious test case is to test if your application is writing cookies properly on disk. You can use the Cookie Tester application also if you don’t have any web application to test but you must understand the cookie concept for testing.

Some Major Test Cases for Web Application Cookie Testing:

#1) As a Cookie privacy policy make sure from your design documents that no personal or sensitive data is stored in the cookie.

#2) If you have no option than saving sensitive data in a cookie, then make sure that the data stored in a cookie is stored in an encrypted format.

#3) Make sure that there is no overuse of cookies on your site under test. Overuse of cookies will annoy users if the browser is prompting for cookies more often and this could result in loss of site traffic and eventually loss of business.

#4) Disable the cookies from your browser settings. If you are using cookies on your site, your sites major functionality will not work by disabling the cookies. Then try to access the website under test. Navigate to the site see if appropriate messages are displayed to the user like “For smooth functioning of this site make sure that cookies are enabled on your browser”. There should not be any page crash due to disabling the cookies. (Please make sure that you close all the browsers, delete all previously written cookies before performing this test)

#5) Accepts/Reject some cookies: The best way to check website functionality is, not to accept all cookies. If you are writing 10 cookies in your web application then randomly accept some cookies say accept 5 and reject 5 cookies.

For executing the above test case you can set browser options to prompt whenever the cookie is being written to disk. On this prompt window, you can either accept or reject the cookie. Try to access major functionality of the website and See if pages are getting crashed or data is getting corrupted.

#6) Delete cookie: Allow the site to write the cookies and then close all browsers and manually delete all cookies for a website under test. Access the web pages and check the behavior of the pages.

#7) Corrupt the cookies: Corrupting a cookie is easy. You know where cookies are stored. Manually edit the cookie in a notepad and change the parameters to some vague values. Like altering the cookie content, Name of the cookie or expiry date of the cookie and see the site functionality.

In some cases, corrupted cookies allow reading the data inside it for any other domain. This should not happen in case of your website cookies. Note if the cookies are written by one domain say rediff.com can’t be accessed by other domain say yahoo.com unless and until the cookies are corrupted and someone is trying to hack the cookie data.

#8 ) Checking the deletion of cookies from your web application page: Sometimes cookies written by domain say rediff.com may be deleted by same domain but by different page under that domain. This is the general case if you are testing some ‘action tracking’ web portal.

Action tracking or purchase tracking pixel is placed on the action web page and when any action or purchase occurs by a user the cookie written on disk get deleted to avoid multiple actions logging from the same cookie. Check if reaching to your action or purchase page deletes the cookie properly and no more invalid actions or purchase get logged from the same user.

#9) Cookie Testing on Multiple browsers: This is the most important case to check if your web application page is writing the cookies properly on different browsers as intended and site works properly using these cookies. You can test your web application on frequently used browsers like Internet Explorer (various versions), Mozilla Firefox, Netscape, Opera etc.

#10) If your web application is using cookies to maintain the logging state of any user then log in to your web application using some username and password.

In many cases, you can see the logged in user ID parameter directly in the browser address bar. Change this parameter to a different value say if the previous user ID is 100 then make it 101 and then press enter. The proper access message should be displayed to the user and the user should not be able to see other users account.

#11) Verify if cookies are persistent or not (according to requirements) by checking cookie type and expiration dates in cookie file or browser console

#12) Validate if an expiration date is set accordingly to requirements. In some cases, it is vital to check if cookie expiration date is updated working with an application (to refresh session for example). This can be checked in browser console or cookie file itself.

Please note that decoding cookie manually is not the best approach and it is easier to rely on browser data, but if required – this thread contains some answers on cookie file format

#13) If some cookies are user specific, it is important to ensure that they are deleted or simply ignored if another user logs into application unless it was said differently in a specification.

#14) Specific test For multi-environment sites: Check if same cookies are acceptable in all environments. Could be caused by the use of wildcards in cookie path (so-called supercookies). Or if this is requirements to allow it, some access issues can be caused because the different encryption key is used (for.Net it is machine key which usually is unique unless specified otherwise).

These are some of the major test cases to be considered while testing website cookies. You can write multiple test cases from these test cases by performing various combinations. If you have some different application scenario, you can mention your test cases in the comments below.

Conclusion

By now you got a clear understanding of how to perform Website Cookie Testing and how to write test Cases for Testing Web Application Cookies.

Please Share your comments/thoughts in the comment section below.