Tuesday, January 7, 2014

Jmeter : Clean up and Counter initialization

Jmeter : Clean up and Counter initialization


Problem :
Every time the loop started to execute it used to take the value left behind by the previous thread  inside the variable "page".Though the "page" has been initialized to "1" at the start.

Therefore initialization was necessary every time a thread executes.But I later found out that usual initialization done using UserDefined variables in Config elements did not work.

The solution was by using BeanShell Sampler 

Pre-Processor Problem : You will go no where , as for every sampler getting executed once in the loop pre-processor will execute.

Post-Processor Problem : Same here , you will go no where as after each time sampler gets executed  in the loop post-processor will get executed.

Syntax :
vars.put("variable name","data");

Example :
vars.put("page","1");


Initialize to 1





Increament By 1 

Notepad++ : Regular Expression

 

 Regular Expression Notepad++


 Finding Empty lines using RegEx :
  1. notepad++
  2. Ctrl-H
  3. Select Regular Expression
  4. Enter ^[ \t]*$\r?\n into find what, leave replace empty. This will match all lines starting with white space and ending with carriage return (in this case a windows crlf)
  5. Click the Find Next button to see for yourself how it matches only empty lines.
Or
 Use "EditPad pro"

  1. At the bottom click at the bottom.
  2. Enter "\n"
  3. Click on search

 --------------------------------------
\r\n - New line
\r$ - End Line
\r   - To Consider the following character as a RegEx Command

.    - Any single digit or a numeric
*   - Any number of times
.* - Any Char
\d - Any Single Digit
[a-z] - Any Single Digit Between a to z
x[a-z]*_\d_\d\r\n  - matches xa_1_1(new line )
-------------------------------------------------

Wednesday, January 1, 2014

Jmeter :Sampler Vs PreProcessor Vs Post Processor Vs Function

Jmeter : Sampler Vs PreProcessor Vs Post Processor Vs Function


JMeter provides following components:

  • Sampler – a standalone Sampler
  • PreProcessor – a Pre Processor to another Sampler which is executed before Sampler and can be used for pre-requisites setup, i.e. to generate some input 
  • PostProcessor –  a Post Processor which is executed after Sampler and can be used for recovery or clean up
  • Assertion – an advanced Assertion with full access to JMeter API .Java conditional logic can be used to set assertion result
  • __Beanshell function – a JMeter Function which allows  the execution of custom Beanshell code during a Sampler run
Refer For More Details : 

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 :







Jmeter : Dynamic Transaction Names and Loop Counter

Jmeter : Dynamic Transaction Names and Loop Counter



  1. Declare a Variable in the Recording Controller and Initialize it  (E.g. val = 0  , as shown in the pic}
  2. Inside the Loop controller , insert a BSF Sampler> Language = Javascript
    1. Inside the script put the following code "${__intSum(${val},1,val)}"
  3. Inside the transaction controller which ever u want to see an incremental change  , append "${val}" after the variable name. 

Note : You can also use BeanShell Sampler , instead of BSF Sampler. If you use BeanShell sample then you can directly give the code "${__intSum(${val},1,val)}"  in the script field.

https://drive.google.com/file/d/0Bw7unBxciTUFQW9Nc3I4bGNoSVE/edit?usp=sharing