Using IF--ELSE Structure in a Load Test | Loadium

Using IF — ELSE Structure in a Load Test

Performance test scenarios are not like the automated test scenarios!

Using IF — ELSE Structure in a Load Test

Performance test scenarios are not like the automated test scenarios!

Performance test scenarios are not like the automated test scenarios. While automated test scripts focus on a few functionalities, performance test scenarios might be focused on more functionalities.

There might be some unexpected conditions in your scenarios and you have to take the necessary actions. To deal with them effectively it is advised that you add decision points in your scripts.

Apache JMeter allows you to create decision points in your test scripts.

First of all, you need to analyze the response and take an action to it.

  • Create an HTTP request sampler
  • Attach a response extractor as a child element to the sampler. This response extractor might be any extractor.

This in this example, we have used a CSS Extractor. It will fetch values in your HTML via [data-name=’brand’] expression. Then it will find this web element’s data-href attribute and assign it to the brandLink variable. In case there are no results, the variable will be set to noBrand.

  • Add If Controller to your Test Plan
  • Condition field accepts Javascript so add “${brandLink}” == “noBrand” or “${brandLink}” != “noBrand” depending on your preference. This is our decision point. This usage might differ in JMeter versions.

performance test

  • Then add a new HTTP sampler as a child element to this IfController. The request will be executed according to the decision point.

Now you have a test plan as follows. In case If Brand Controller returns True, a new request will be executed. If it’s set to False, it won’t make any more requests.

performance test

By having an If-Else condition you will enrich your test plans.

Please feel free to ask questions if you have any.

Happy load testing…

Originally published at loadium.com on February 13, 2018.

Latest articles

All Articles →

Craft Powerful Performance Tests with Ease Loadium Script Builder

Craft Powerful Performance Tests with Ease Loadium Script Builder

What Is Shift Left Testing

What Is Shift Left Testing

Swagger vs Postman What Are the Differences

Swagger vs Postman What Are the Differences