Simulating shopper abandonment in JMeter

It is unrealistic to generate traffic to a website for load testing without taking into consideration the ongoing experience of the virtual shopper. For example, if pages took 30 seconds to load on a site, how likely would you be to continue shopping on the site? Probably not likely. However, many tests simply plow through pages and keep making requests, even when no human being would ever do so.

In JMeter, shopper behavior can be configured by setting connect and response timeout for a page. For example, in the screen shot below, if the user doesn’t get a response in five seconds, the next iteration of the thread is entered. This effectively simulates abandonment.

However, this is somewhat “sledgehammerish”. Many times, I will tolerate one or even two slow pages, depending on how badly I want the product.

To get even more sophisticated, you could write a BeanShell script that would calculate previous response times and dynamically change the tolerable wait for subsequent page requests.

For example, if you waited eight seconds for a given page, you may click one more time. However, if you waited eight seconds for a page, and eight more on that next click, you probably wouldn’t be as patient with the third request, if you even issued it.

To set this up, simply create a BeanShell assertion with the following code:

if (vars.get("lst") != null) {
  int i = (System.currentTimeMillis() - Long.parseLong(vars.get("lst")))/ 1000;
  if (i > 3) {
    java.util.Random r = new java.util.Random();
    Double d = r.nextDouble();
    if (d > .5) {
      Failure = true;
    }
  }
}
else {
  System.out.println("initial request for thread");	
}
vars.put("lst",Long.toString(System.currentTimeMillis()));

What is above will simply plow through requests, and if it has been more than three seconds since the end of the previous request, we exit this session 50% of the time. That is pretty arbitrary, but you get the idea. You can make the logic as complex as you like.

You can then place the BeanShell assertion as a parent to all requests, and it will be invoked for each one.

Make sure you configure the Thread Group to start the next thread loop after a sampler error, and as soon as the assertion does not pass, the shopper abandons the session.

This allows you to be far more granular than just setting a response timeout.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.