JMeter and Jenkins configuration


1. Load test configuration for HTTP request type sampler.

Please follow the steps to create load test for HTTP requests.

1. Run JMeter on your system in GUI mode. You can simply run this by hitting "jmeter.bat" on windows and "sh jmeter.sh" from terminal on linux system.
2. Once opened, Give your Test Plan name.

3. Right click on Test Plan and Add-> Threads (Users)-> Thread Group
Please use Thread Properties variable name as shown in above screen to configure on Jenkins and pass value while running your Job on Jenkins. (You'll have to make your Job as parametrized to take these values at run time)

When You will run test on your local system then You can pass values as shown in below screen. Default value of these variable will be 1 if you don't pass+. -

4. Add CSV Data set Config to your Thread Group, If you have to take data from outside of your test at run time.

5. Add Once only Controller (Thread Group -> Add -> Logic Controller-> Once Only Controller), If you need execute any thread before each Thread.
Please add Thread to your Once Only Controller which you want to execute before each Thread in your Main Thread Group.  If You have not added this You can jump to Step 7.

6. Add Thread to your Once Only Controller(Once Only Controller-> Add -> Sampler->HTTP Request), That you want to execute before each Thread in your Thread Group.

Add HTTP Header Manager(Right Click on Thread(Get SSO Token in our example)-> Add -> Config Element-> HTTP Header Manager) If your request requires headers.

Add Reg Ex (Right Click on Thread(Get SSO Token in our example)-> Add -> Post Processor -> Regular Expression Extractor) , If you need to extract some value and have to use further in diff Thread.


You can add one or more in same way, or you just click on Req Ex (xst_regex in our example) and click on Duplicate , it will create one more Reg Ex in your thread and then You can modify the Reg Ex as per requirement.

Add Response Assertion(Right Click on Thread(Get SSO Token in our example)-> Add ->
Assertions -> Response Assertion)

You can add one or more in same way, or you just click on Req Ex (Response Assertion in our example) and click on Duplicate , it will create one more Response Assertion in your thread and then You can modify the Response Assertion as per requirement.

7. After creating Thread Group, Now Let's add 3 types of HTTP request and required elements for HTTP request.

A.) GET REQUEST - > Add Thread to your Thread Group(Thread Group-> Add -> Sampler->HTTP Request), That you want to execute in your Thread Group.

Add HTTP Header Manager(Right Click on Thread(Get_Account_Details in our example)-> Add -> Config Element-> HTTP Header Manager) If your request requires headers.

Add Reg Ex (Right Click on Thread(Get_Account_Details in our example)-> Add -> Post Processor -> Regular Expression Extractor) , If you need to extract some value and have to use further in diff Thread.

You can add one or more in same way, or you just click on Req Ex (title in our example) and click on Duplicate , it will create one more Reg Ex in your thread and then You can modify the Reg Ex as per requirement.

Add Response Assertion(Right Click on Thread(Get_Account_Details in our example)-> Add ->
Assertions -> Response Assertion)

You can add one or more in same way, or you just click on Req Ex (Response Assertion in our example) and click on Duplicate , it will create one more Response Assertion in your thread and then You can modify the Response Assertion as per requirement.

B. POST REQUEST->Add Thread to your Thread Group(Thread Group-> Add -> Sampler->HTTP Request), That you want to execute in your Thread Group.

Add HTTP Header Manager(Right Click on Thread(Add_Bank in our example)-> Add -> Config Element-> HTTP Header Manager) If your request requires headers.

Add Response Assertion(Right Click on Thread(Add_Bank in our example)-> Add ->
Assertions -> Response Assertion)

C. DELETE REQUEST->Add Thread to your Thread Group(Thread Group-> Add -> Sampler->HTTP Request), That you want to execute in your Thread Group.



You can add HTTP Header Manager and Response Assertions as explained in above requests(GET, POST)


2. Jenkins Configuration

1. Add New Item , With Freestyle project type.

2. You can add description of your job in General Tab item.

3. Make your job as Parameterized by selecting (This project is parameterized)

Add 3 parameter with String Parameter type, With name "USER_COUNT", "RAMPUP_PERIOD", "LOOP_COUNT" with default value as 1.

4. You can select GIT as a Source Code Mana gement by configuring git URL of your project and details.

5. Add Execute Windows batch command in Build Step run your load test.
You can write the command as per OS requirement where Jenkins is installed.
Run the test in non GUI mode and save the report as csv or jtl format.
Windows:
Syntax for running the Script in Command prompt:
jmeter -n -t [path to test JMX file] -l [path to result file]
-n  : This specifies JMeter is to run in non-gui mode
-t   : name of JMX file that contains the Test Plan
-l   : name of JTL file to log sample results to.
Example:
jmeter -n -t C:\jmeter\gen-report.jmx -l C:\jmeter\gen-report.jtl
Unix (MacOS, Linux, etc.):
./jmeter.sh -n -t [path to test JMX file] -l [path to result file]
Example:
./jmeter.sh -n -t /Users/user/jmeter/gen-report.jmx -l /Users/user/jmeter/gen-report.jtl


Example for Windows Jenkins -

"jmeter.bat file path" -Jjmeter.save.saveservice.output_format=xml -n -t ".jmx file path(You'll have saved your test with .jmx extension)" -l "load test name.jtl" or load test name.csv" -Jthreadgroup.count=%USER_COUNT% -Jthreadgroup.rampup=%RAMPUP_PERIOD% -Jthreadgroup.loopcount=%LOOP_COUNT%


6. Add Execute Windows batch command in Build Step to generate html report.
Use the following command to generate report from an existing sample CSV/JTL result file as above.
Windows:
jmeter -g [path to result file] -o [path to report output folder]
-g  : [path to CSV file] generate report dashboard only
-o : output folder where to generate the report dashboard after load test. Folder must not exist or be empty
Example:
jmeter -g C:\jmeter\gen-report.jtl -o C:\jmeter\report
Unix (MacOS, Linux, etc.):
./jmeter.sh -g [path to result file] -o [path to report output folder]
Example:
./jmeter.sh -g /Users/user/jmeter/gen-report.jtl -o /Users/user/jmeter/report

Example in Windows Jenkins.

"jmeter.bat file path" -g "test report.csv file path" -o "path to put html report"

7. Add Publish HTML reports to your Post-build report

Give your HTML report directory path in "HTML directory to archive" field.

Give html file name in Index page[s] field.

Give Report title as "HTML Report"

8. Add Publish Performance test result report

Give "load test name.jtl" in Source data files (autodetects format)

Comments

Popular posts from this blog

API Automation using Rest Assured

Security Testing

Manage Jenkins