Showing posts with label Jmeter. Show all posts
Showing posts with label Jmeter. Show all posts

Sunday, March 16, 2014

Jmeter :To extract the response of an HTTP Sampler into a variable for later use

To extract the response of an HTTP Sampler into a variable for later use


To add regular expression extractor element to a test plan in JMeter:

1.   Right click the sampler element (request to the server from which the value needs to be extracted)

2. Select Add option à Post Processors à Regular expression extractor

-----------------------------------------------------------------------------------------------

Extracting Single string from the response

Consider an example, where a user Date displayed in a webpage Ex: Date:xxxxxxx

In order to extract the username, below R.E can be used:    

Reference Name:                   Date

Regular Expression:               Date\:(.+?)             

Template:                                 $1$

Match No. (0 for Random):    1

Default Value:                          match not found

Note:The special characters above mean:

(  ) encloses the portion of the match string to be returned

. ->  match for any character.    +  è one or more times.

?  stop when first match is found 

Without the ?, the .+ would continue until it finds the last possible match.

----------------------------------------------------------------------------------------------------

Extracting Multiple Strings from the response

Consider a scenario where the user wants to extract Date and Time.
(Ex:Date:xxxxxx Time:xxxxxxx) To extract both the ids, the below R.E can be used

                       Reference Name:                    Date_time

                       Regular Expression:    Date\: (.+?) Time\:(.+?)

                      Template:                                $1$$2$

                      Match No. (0 for Random):    1

                      Default Value:            match not found

Since we need to extract two values from the response, two groups are created. So the template has $1$$2$. The JMeter Regex Extractor saves the values of the groups in additional variables.

The following variables would be set as:

    Date_time-> xxxxxzzzz

    Date_time _g0 ->  Date:xxxx time:zzzz

    Date_time _g1 -> xxxx

    Date_time _g2 ->  zzzz

These variables can be later referred in the JMeter test plan, as ${Date_time _g1}, ${Date_time _g2}.

-------------------------------------------------------------------------------------------------------

Extracting only numbers from the String

Consider a case where we need to only extract the numbers, for example price=100$

To extract 100, the below R.E can be used

                      Reference Name:                    price

                      Regular Expression:    price= “(.+?)$”

                      Template:                                $1$

                      Match No. (0 for Random):    1

                      Default Value:            match not found

Wednesday, January 1, 2014

Jmeter : Easy Configuration

Jmeter : Easy Configuration

Open Jmeter :

  1. Make sure Jmeter is downloaded and JDK is configured in your system(Follow the link below:
  2. Goto folder where Jmeter is extracted. > Bin .
  3. Double click on Jmeterw.cmd (for windows ) , jmeter.sh (for Linux) 
  4. Optional : terminal > sh jmeter.sh

REST applications :

  1. Rt Click on Testplan > Add---> Thread Users ---> Thread Group.
  2. Thread Group >
    1. rt ck >Add >  Sampler> http request 
      1. name: any name
      2. Server : endpoint only
      3. port : port only
      4. request type : Eg- POST
      5. path : resource
      6. body Data: json
    2. rt ck > Add > Config > http Header Manager
      1. Add
      2. Name=Contenty-Type , Value= application/json
    3. rt ck > Add > Assertions >  Response Assertions
      1. Fields to Test = Response Code
      2. Patterns to Test > Add > 200
    4. rt ck > Add > Listener
      1. Summary Report >filename > path/summary.csv 
      2. Results Table >filename >  path/table.csv
      3. Results Tree
      4. Response Time 
      5. Aggregate Time >filename >  path/aggregate.csv
  3. Run the setup
    1. summary report , aggregate Graph  > ck on Save Table Data button
  4. You can also co to thread group add 
    1. Change Number of Threads
    2. Rampup period [Optional]

Performance parameters :

  • Results Table

    1. ThreadName = loopnumber - ThreadNumber
    2. Label :Request Name
    3. Sample Time : Request+Response
    4. Status : Assertions Pass or Fail
    5. Bytes : Bytes Received by Jmeter
    6. Sent Bytes : Bytes Sent To server
    7. Latency : Time Jmeter needs to wait after sending request till the response is received

  • Aggregate Graph

    1. Samples : Number for Requests 
    2. Averge : Average time request+Response
    3. Median
    4. 90% Line : Req + Response time for 90% of samples
    5. 95 % line : Req + Response time for 95% of samples
    6. 99% line : Req + Response time for 99% of samples
    7. Min : least Req+Response time 
    8. Max : highest Req+Response time 
    9. Error : Assertion Fails
    10. Throughput : number for requests made per second  by Jmeter

Performance Testing for UI testing Applications : 

Once Jmeter is opened 

  1. Rt Click on Testplan > Add---> Thread Users ---> Thread Group.
  2. Rt Click on Thread Group > Add --- > Logic Controller ---- >click on recording Controller
  3. Rt Click on Thread Group > Add --- >Config Controller --- >click on Http Cookie Manager
  4. Rt Click on Thread Group > Add --- >Config Controller --- >click on Http Request Defaults 
  5. Rt Click On work bench > Add --- > Non test Elemenets --- > click on  Http Test Script Recorder. 
  6.  Http Test Script Recorder >Port ="8080"


  1. Click On Http Request Defaults >Server name "http://in.yahoo.com/"
  2. Click on  Http Test Script Recorder > Https Domain "http://in.yahoo.com/"
    1. Http Sample Settings >Type > HttpClient4
    2. Url pattern to exclude > Click on add suggested excluded

  1. Open FireFox Browser.
  2. Goto Tools >options >Advanced >network>Click on Settings .
  3. Select Manual Configuration : Http Proxy ="localhost"    and port="8080"
  4. Click on OK



Now the Jmeter and Browser is Configured 

  1. Open Jmeter> Goto Https Test Script Recorder >Click on Start button.
  2. Open FireFox.
  3. Paste URL "http://in.yahoo.com/"
  4. Do any operations on the webpage .


You will see the transaction getting recorded.

Note :
While playing the recorded script make sure you add a "View Results Tree" Element to your Testplan not to your workbench.




If you do not see any recording please see the detail installation below :