Pages

Friday 21 April 2017

Apache Jmeter- Steps to Record Scripts

Performance Optimizer-Apache Jmeter-Recording
Below are steps to record Jmeter Script for HTTP/HTTPs protocol:

1. Launch Jmeter in GUI mode:
      Go to <Jmeter_Home>/Bin folder and click on jmeter.bat


2. Right Click on Test Plan  and Select  Add ->  Threads(users) -> Thread Group (see Below image) 

Performance Optimizer-Apache Jmeter-Recording
Thread Group is used to provide details of No of Concurrent users, Ramp Up, Loop count and Scheduling

3. Right click on ThreadGroup and Select Add -> Logic Controller ->  Recording Controller (see below image)

Performance Optimizer-Apache Jmeter-Recording
All Recorded samples are kept inside Recording Controller

4. Right click on Thread Group and Select Add -> Config Elements -> User Defined Variables (see below image)
Performance Optimizer-Apache Jmeter-Recording

5. In User Define Variables you need to include all static data. For example: Server Name, Port,etc.


Apart from static data you should also add user input data. For example: If you are recording flow of any application and which require ID and Password then you should add ID and password in user defined variables along with other input fields like Name, PhoneNo, etc.  



Note: Benefit of adding static data and user input data in user define variable is that you don't need to replace it explicitly, it will be replaced as a jmeter variable directly. You will understand it better by the time you complete reading this blog. 


6. Right Click on workBench and Select Add-> Non-Test Elements -> HTTP(S) Test Script Recorder (see below image)
Performance Optimizer-Apache Jmeter-Recording
HTTP(s) Test Script recorder are used for start and stop recording, Test Plan Creation and for Applying basic Excludes

7. Add View Result Tree inside Test Script Recorder. Right click on Test Script Recorder -> Add->Listner-> View Results Tree (see below Image)
Performance Optimizer-Apache Jmeter-Recording
View Result tree is used to see Request Response of Recorded samples

8. Launch your browser(Chrome/FireFox/IE) and change proxy setting like below

      Address: LocalHost or IP address of your machine
      Port : 8080

Chrome:
1. Go to Settings
2. Click on change Proxy Settings
3. Click on LAN settings
4. Click checkbox of use Proxy server and give input as per below images 
Performance Optimizer-Apache Jmeter-Recording


Performance Optimizer-Apache Jmeter-Recording
Firefox:
1. Go to Setting -> Options
2. Go to Advanced
3. Go to Network tab
4. click on Settings
5. set up manual proxy as per below image 
Performance Optimizer-Apache Jmeter-Recording




Performance Optimizer-Apache Jmeter-Recording
Performance Optimizer-Apache Jmeter-Recording
9. Go to HTTP(s) script recorder and click "Start"

Note: If you are getting below error, for now you can ignore it and Click "OK" to continue Jmeter scripting.



Performance Optimizer-Apache Jmeter-Recording

10.  Right Click on Recording Controller and Select Add->Logic Controller -> Transaction controller (See image below)

Performance Optimizer-Apache Jmeter-Recording
Change the name of Transaction Controller as per your Transaction steps. For Example: if you are going to Login into application give the transaction Controller name as Login. (see image below)
Performance Optimizer-Apache Jmeter-Recording

11. Go to HTTP(s) Test Script Recorder and select Target Controller as your Test Plan -> Thread Group -> Recording Controller -> Login (see image below)


12. Now go to browser and Login into Application and Come back to Jmeter instance. You can see below that "Server", "Port", "UserID" and "Password" are already as jmeter variable as we have defined it inside User Defined Variables.



13. Almost every application create session id, token id, etc after login and which remain constant for entire session of users. So after login check whether session id or token id is created or not and make Regular expression of it. In general term we have to find dynamic values which are coming from server and which needs to be correlated. 

How to apply Regular Expression?
A. Go to View result tree 



B. Find Sample which contains Token Id or Session Id and make regular Expression of it.

For Example: In above screenshot, "var tokenValue_p="JROM-NkbY-5RKt-l5Pf-0Een-ULLk"" is our TokenID 

Go to that sample in Transaction Controller and apply Regular Expression as below  and keep original value in comment section of Regular Expression as shown below 

(How to Add Regular Expression? Right click on Sample, Select Add -> Post Processors -> Regular Expression Extractor) 


14. Go to User Define Variables and Add one more variable as Token_ID, It's original Value and Description as Correlated, just as shown below


15.  Now Once again create new new Transaction controller for next transaction same as Point 10
Performance Optimizer-Apache Jmeter-Recording

16. Change the Target Controller same as Point 11

17. Record Next transaction and come back to jmeter. You will see that Server, Port, UserID, Password and Token_ID is auto replaced by jmeter (see below image)
Performance Optimizer-Apache Jmeter-Recording
18. Once again check for any other Dynamic values coming from server and create regular expression of it and add those variables in User Defined Variables, same as Point 13 and 14

19. Repeat Point 11,12,13 and 14 until end of your traversal flow

20. Click on "Stop" button in Test Script Recorded after completion of your flow

21. After end of script recording you don't need to do Any Correlation and parameterization as it is already handled in above steps

22. *Very Important Step* Go to User Define Variables. 
 a. variables which has correlation comment as description, please delete those variables from User Define Variables 
b. Variables which don't have any comment as description, either keep those variable as it is or create CSV data set config as per your requirement 


Performance Optimizer-Apache Jmeter-Recording


Upcoming Topic: Regular Expression Extractor 

No comments:

Post a Comment