How to create reusable test fragment in jmeter

Posted By : Nitin Kumar | 31-Oct-2018

How to create reusable test fragment in Jmeter


 

1.Introduction:

This blog explains how to create reusable test fragment in Jmeter. As we know that performance testing plays a vital role in the testing environment. Any application is comprised of multiple features and some of the features are dependent on each other. Let assume an application in which there login page which is two step process:

a)  Login

   User need to enter the credential i.e email and password etc.

b)  Secret key page

   Secret key is key through which user login into hyper ledger i.e private blockchain” system  Which is the part of the application .After enter the user credential it will redirect to secret key page in which user needs to enter the "secret key" to successfully get login into the system.

 

After the completion of the above steps, the user will successfully get logged in into the system. The next page is a dashboard page on which user will edit the profile. As you can see that these functionalities are dependent on its previous functionality. for eg If the member involved in login feature change it for any reason but the secret key and edit profile feature is dependent on the login then the tester need to update the login script everywhere in use.

In this blog, I am going to explain how you can overcome this issue by using a test fragment. This will make the working of every feature independent of each other.

 

In this case, you need to create modularize script where each module is independent. The logic of the feature will keep in a separate section.

 

To create modularize script  I am going to use test fragment, module controller and include controller in Jmeter.

 

a) Test fragment: In the test fragment, we will declare the logic of each step

b) Module controller: The logic which we have declared in test fragment will use in other feature in the same script. In the module controller we will give the reference of the logic which is to be used.

c) Include controller: This is something same as module controller only the difference that the invoking logic is from different script.

 

2.Requirements:

a)apache-jmeter-3.3

 

3.Steps to create jmeter script

a) Open your jmeter

b) Edit your test plan name

 


 

     c) Right click on test plan then Go to -> Add -> Test Fragment->Test Fragment to add test fragment as shown in below screenshot.                      

 

 

d)Steps to create reusable test fragment:

  1) Add “simple controller” to test fragment

  2) Add “Http request” to simple controller

  3) Add “Http header “to Http request


 

1)How to add simple controller to test fragment:

Right click on test fragment Go to Add-> Logic controller -> simple controller as given below:

 


 

2) How to add Http request in simple controller

 

Right click on simple controller  Go to Add ->Sampler->Http request as given below:

 



 

3.How to add Http  Header Manager in Http request

Right click on Http request .Go to Add-> Config element -> Http Header Manager

 


 

e)Next step is to reuse the logic defined in the test fragment, we need to create the separate thread group.
 



f)After adding thread group we need to add module controller in which we will use the pre-created test fragment.


 

g)Steps to add module controller:

 

1)Right click on thread group .Go to Add -> Logic controller->module controller


 

2)After add module controller we need to select the flow in test fragment which we will use module controller as shown in below screenshot.


 




 

h) In the same way, we will add include controller. Right click on thread group. Go to Add->Logic controller->Include controller in which you need to add the file name you want to use in include controller.


 

I)After these steps run your test script.


 

4)Simple diagram to show the working of test fragment reusability:

 

3

 

As in the above screenshot, you can see that there are three test 1, test 2 and test 3 the steps are also defined which will use to perform the individual test.

To perform test 2 we need step 2 and 3 of test 1.In the same way, to perform test 3 we need to use step 11,12,13 of test 2. So In this case test fragment will be used.



 

5.Conclusion :

 

Jmeter test fragment will reduce the time which will be utilized in Update the change feature logic everywhere in use. So it's less time-consuming.

 

Thanks and Regard































 

Related Tags

About Author

Author Image
Nitin Kumar

Nitin is a QA Engineer. He is adaptive and passionate to learn new technical skills.

Request for Proposal

Name is required

Comment is required

Sending message..