Site icon Vinsguru

Test Fragment In JMeter

Overview:

In this tutorial, I would like to demo Test Fragment In JMeter to show how to create reusable and modular test scripts.

Need For Test Fragment:

My application has few business critical processes from which we could come up with different business workflows. When I was trying to come up with performance test script in JMeter, I needed to find some approach for creating a reusable / modular test scripts. So that I could reuse the scripts for different workflows.

For Ex:

Lets consider a sample application which has below functionalities.

Using above functionalities, I could come up with different workflows as shown here.

Since I had too many combinations, I wanted to find a proper way to design my JMeter test scripts. In this article, I will explain how I achieved that using below JMeter elements.

  1. Test Fragment
  2. Module Controller
  3. Parameterized Controller
  4. Include Controller

Test Fragment In JMeter:

Test Fragment element is a special controller which can be added directly under JMeter test plan like Thread Group. But It does nothing except holding other elements inside!! It gets executed only when it is referenced by a Module/Include controller from other Thread Groups. It acts like a library of reusable of scripts.

Module Controller:

Module Controller in JMeter is useful in referencing any of the logic controller in the JMeter Test Plan.

For Example, I have 5 thread groups as given below in my test.

  1. New User Registration
  2. User Login & Order Creation
  3. User Login & Product View
  4. Existing Order Edit/Cancel
  5. User Search

Some functionalities could be common for these thread groups. For example, User has to login to crate orders / to view the existing products.

In the above example, you can see, Both thread groups have to have the login functionality. Whenever the login functionality changes, I need to ensure that I update the script in both thread groups.

So, instead of having duplicate simple controllers for login in both thread groups, I can add a Test Fragment & move the ‘User Login’ Simple Controller under the Test Fragment. So that it can be referenced by a Module Controller. [It does not have to be a Simple Controller always. It can be any controller].

Now, If the script for login changes, I have to just update the ‘User Login’ under the Test Fragment. Both thread groups will work just fine.

Parameterized Controller:

One ‘User Login’ is being accessed by more than 1 Thread Group in the above example. Sometimes, these Thread Groups might want to use these Simple / Transaction controllers under the Test Fragment like a function so that they can pass different data & they expect the controllers to perform the actions based on the data passed to it.

For example, My requirement is to use VISA credit card while ordering a new product & to use MasterCard while editing/upgrading the existing order. [Sorry if it is a stupid example. :)]
I can use a Parameterized Controller for this purpose.

I add the Parameterized Controller first. Then I add the Module Controller under the Parameterized Controller. Now the Module Controller calls the ‘Checkout’ & passes the test data to be used in the ‘Checkout’.

Checkout controller will use test data passed to it while performing the requests.

Include Controller:

As a Module controller is used to call a logic controller in the Test Plan, Include Controller is used to reference an existing .jmx file itself.

For Example,  The application is very complex & 2 engineers are involved in script creation.
Developer A is creating a test script for Login & Searching for the Products functionality of the application.
Developer B is creating a test script for Checkout.

Both engineers come up with a different .jmx files for the different modules of the application.

Now we create the final JMeter test plan which will reference these external ‘.jmx’ files as given below.

I can have different jmx files for Login, Order Product, Product Search, User Search, View Product, Edit Order, Cancel Order

Now I can create any business flow I want by referencing the external jmx files. [Add the User Defined Variables, Cookie Manager etc in the final JMeter Test. Not in the included files. ]

Login -> Order Product -> View Product
Login -> Order Product -> Edit Order
Login -> Product Search -> Order Product
Login -> Order Product -> Product Search -> Cancel Order

Summary:

We were bale to successfully demonstrate how to create reusable test script using Test Fragment In JMeter. By designing my JMeter test scripts as shown above, I could create different thread groups for different business workflows. Whenever the application changes, I had to update the script only in one place. All the workflows will remain unchanged!

Read more about JMeter.

Happy learning 🙂

Share This:

Exit mobile version