• Home
  • Testing
  • SAP
  • Web
  • Must Learn!
  • Big Data
  • Live Projects
  • AI
  • Blog

What is Cookie?

Cookie is a small piece of information that is stored in text file on user's (client) hard drive by web server. This piece of information is then sent back to server each time the browser request a page from the server. Usually cookie contains personalized user data or information that is used to communicate between different web pages. The screen-shot below show cookies for different websites.

Cookie Testing Tutorial with Sample Test Cases

In other words cookies are nothing but user's identity and used to track where the user navigated throughout the pages of the website. The purpose of cookie is to make rapid interaction between users and web-sites. Applications where cookies can be used is to implement a shopping cart, personalized web experience, user tracking, marketing, user sessions etc.

In this tutorial we will learn

What is Content of Cookie?

The cookie consists of mainly three things

  1. The name of the server the cookie was sent from
  2. Cookies Lifetime
  3. A value. This is usually a randomly generated unique number

Types of Cookies

Cookie Testing Tutorial with Sample Test Cases

Usually there are two types of cookies written on user machines

  • Session Cookies: These cookies are active till the browser that trigger the cookie is open. When we close the browser this session cookie gets deleted
  • Persistent Cookies: These cookies are written permanently on the user machine and it lasts for months or years

Where Cookies are stored?

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

For example, in Mozilla Firefox browser you can see the cookies in browser options. To view this click on Tools -> Options -> Privacy and then click on "Remove Individual Cookies".

Cookie Testing Tutorial with Sample Test Cases

While in Internet Explorer browser it store cookies on path "C:\Documents and Settings\Default User\Cookies"

How to test Cookies – Sample Test Cases

Following are important test cases to check cookies

  1. Disabling cookies: Disable all cookies and attempt to use the site's major functions
  2. Corrupting cookies: Manually edit the cookie in notepad and change the parameters with some random values
  3. Cookies encryption: Sensitive information like passwords and usernames should be encrypted before it is sent to our computer
  4. Cookie testing with multiple browser: Check your website page is writing the cookies properly on different browser as expected
  5. Checking the deletion from your web application page:
  6. Selectively rejecting cookies: Delete all the cookies for the websites and see how the website reacts to it
  7. Access to cookies: Cookies written by one website should not be accessible by others
  8. No overuse of cookies: If the application under test is a public website, there should not be overuse of cookies
  9. Testing with different setting: Testing should be done properly to check that website is working well with different cookie setting
  10. Categorize cookies separately: Cookies should not be kept in the same category of the viruses, spam or spyware

Plugins for Cookie Test

Modern browsers allows viewing/editing of the cookies in the browser itself. There are plugins for Mozilla and Google Chrome both.

  1. For Mozilla Firefox browser: Mozilla Advance Cookie Manager

Cookie Testing Tutorial with Sample Test Cases

  1. For Google Chrome browser: Edit This Cookie

Cookie Testing Tutorial with Sample Test Cases

Cookie Modification in Action

We will use edit the cookie plugin for Chrome.

Step 1)

Enter the usedid & password to login into the Guru99 bank.

Cookie Testing Tutorial with Sample Test Cases

Step 2)

Click on the plugin icon Cookie Testing Tutorial with Sample Test Cases and it will open another window as shown below

Cookie Testing Tutorial with Sample Test Cases

Step 3)

Change the value of cookie to "guru99" and then click on Cookie Testing Tutorial with Sample Test Cases to save the changes

Cookie Testing Tutorial with Sample Test Cases

Difference between Cookie and Session


  • Cookies are client-side files that contain user information
  • Sessions are server side files which contains user information
  • Cookie ends depending on the life time you set for it
  • Session ends when user close his browser
  • You don't need to start cookie as it is stored in your local machine
  • In PHP, before using $_SESSION, you have to write session_start(); Likewise for other languages
  • The official maximum cookie size is 4KB
  • Within session you can store as much data as you like. The only limits you can reach is the maximum memory a script can consume at one time, which is 128MB by default
  • Cookie is not dependent on Session
  • Session is dependent on Cookie
  • There is no function named unsetcookie()
  • Session_destroy(); is used to destroy all registered data or to unset some