Menu

How to Handle a Website where Cookies are set via Javascript

Cookies are part of the HTTP spec that everyone has heard of thanks to dire warnings and misunderstandings about what they do since the late 1990s. They’ve been in use since 1994, and browsers just handle them automatically. Load Tester, too, handles all of the HTTP cookie specification automatically, responding to header directives for cookies just the same as any browser.

The one case where Load Tester does not handle cookies automatically is when you’re writing virtual user test cases, because in order to support generating millions of users, there’s not enough CPU or memory left to run a javascript interpreter for every virtual user.

The process instead is to locate where the cookie value is set in javascript, parse the value, and set the cookie value inside Load Tester’s cookie store. The new cookie value is then updated in every subsequent transaction.

Locate Cookie Value

The first step is to locate the cookie value. To do that find the first instance of where the cookie in question is used in the Headers Tab, double-click on the cookie line in the header to bring up the editor, and copy its value using control-C.

Select the entire test case by clicking on the top node in the test case editor, and then select the Search Tab. Paste the value into the search tab and click on the search button.

In this particular example the cookie value was found in transaction 66 of page 2.

Configure Cookie Extractor

Click on transaction 66 of page two and select the Actors Tab.  Select the Extractor tab at the bottom, and click on the plus sign to bring up the editor.

This example shows how to use a regular expression to parse the cookie value from javascript, but you can also use a simple string delimiter, or even write your own javascript.  The later can be used in complicated cases where the cookie values aren’t explicity set via a simple string.  The example shows the cookie value being parsed and then stored in the variable by the name “DWRSESSIONID”, which happens to be the name of the cookie.  This name could have been anything;  the cookie value was simply used for clarity.

Setting the Cookie

Once the cookie value has parsed into a user variable you can do anything with it.  In this case, we want to set the cookie value for the cookie “DWRSESSIONID” so that the cookie processor will use that new cookie value for the rest of the test case.  On the next transaction bring up the Processor Tab at the bottom of the Actors Tab.  The goal is to modify the existing DWRSESSIONID cookie before this and all subsequent requests are made.  The “name” should be the name of the cookie.

The next step is to configure the cookie value.  In this case the previously configured extractor stored the value in the user variable named “DWRSESSIONID” to make it easy to remember.  This name is then entered here, selecting “user variable” as the data source, and “DWRSESSIONID” as the variable name.

 

From now on the virtual users will configure the javascript controlled cookie DWRSESSIONID exactly as intended.

SaveSave

SaveSave

Add Your Comment

You must be logged in to post a comment.

Resources

Copyright © 2018 Web Performance, Inc.

A Durham web design company

×

(1) 919-845-7601 9AM-5PM EST

Just complete this form and we will get back to you as soon as possible with a quote. Please note: Technical support questions should be posted to our online support system.

About You
What you Need