Challenges with record and playback: Cookies and Sessions

The application was recorded in a particular state, even if you didn’t know it...

Many times, things are set in the browser that customize the users experience on a site. There are identifiers that uniquely recognize the user, and affect things on the site such as:

  • The current Login state
  • Notifications shown the first time you visit a site
  • Browser access to current location
  • Browser size during recording and play back

Technologies used here are: cookies and sessions. Either way what happens when you bring up the site and start recording is that it is already in some predefined state. When you play back, Selenium plays back in a state where cookies and other data are removed. So the site behaves differently than when you recorded

Software developers use cookies to store session information for a particular user on the site or between sessions on related sites. Now aside from being tasty, cookies are cool because once you’re on a website those cookies can be used to retrieve information about the user without having to store massive amounts of information in some back-end system. For automation purposes this causes a problem whenever we play back if we don’t have the correct cookies for our particular session

Another example are sites that allow the user to stay logged in between browser sessions. In this case when recording you might have already been logged in, so no login information was captured. But when you play back it goes to a login page and the test fails.

Elements show up on the page that didn't appear during recording. Many of these only show up the first time you visit the website. Some examples are:

  • The website notifications about the website's usage of cookies
  • An overlaid element that mentions some special deal or sale
  • Visit www.caesars.com while browser incognito to see an example

Here’s how to make that less painful

  • Record and playback in incognito/private mode.
    * Most recorder utilities can be set to launch in incognito/private mode. For example, in chrome you can go to the extension’s options and select allow in incognito mode.

  • Setting this will allow you to use the recording tool in incognito mode. When recording in incognito mode, cookies and profile information are removed allowing you to create a clean baseline for your recording.
    * Here is a great article that shows how to do this in other Browsers

  • From here, once you have created your test script you can then instruct it to play back in normal mode. However, there are certain cases where it may be beneficial to play back in incognito mode. An example of this would be a site that uses your current location to customize the experience on the page. This might break if it were to run from various locations. Playing back in incognito mode will prevent the browser from getting your current location. There are a few ways to instruct the playback to happen in incognito/ private mode. Here are some examples:

  • Using Chrome Options
    * options.addArguments("--incognito");

  • Using Other browsers

  • Set Specific cookies.
    * There’s a good forum post that outlines the process for capturing and setting specific cookies on playback. This might be useful if you require certain cookies to be in place to simplify your selenium test

Sign In or Register to comment.