Sunday, December 18, 2011

Parameterization Using User Variables

Now we will learn how to parameterize the values using User Variables.
For this parameterization also we will use a public site as an example i.e. www.redbus.in.
Follow the following steps :
To Parameterize the Booking scenario, first record the Booking scenario.
1] Add Thread Group Recording Controller and HTTP Request.
            In HTTP Request > Server Name or IP : Enter http://www.redbus.in
2] Add a HTTP Proxy Server for the Workbench
3] Start the Proxy Server and open Mozilla Firefox and go to http://www.redbus.in.
4] After recording a few transactions, close the browser and stop the Proxy server in Jmeter. U get the below recordings.
5] Here we have seen the tickets from Mumbai to Goa on 07-Dec-2011
6] Now we will parameterize the values of fromCityName and toCityName using User Parameters.

For this do the following steps:

7] After recording the script first save it.
8] Create a new file in “text document” form in bin folder.
9] Enter the values for each thread or user in separate rows with fields separated by commas as shown in the screen shot.
10] Save the file as (file => save as) uservar.csv file in the same bin folder.
11] Now in the Apache_Jmeter   window go to Options > Function Helper Dialog
12] Create new function with function type __CSVRead.
13] In the values column for CSV file to get values from give the file name (i.e. uservar.csv) from where values are retrieved. Give the complete path incase the file is not created in bin folder. In Column number of CSV file give 0 as user ids are stored in first column and count will be started from “0”.
14] Then click on generate option to generate a function. Then copy the function string generated.

15] Now again goto Apache_Jmeter window.
Right click on thread group.
Then click on Add > Pre Processor > User Parameters to create a new userparameter.
16] The following window will be opened. Click on Add Variable tab to add a new variable.

17] Now in the name column give the name of the variable you want to replace (fromCityName) as “A” in this example and in the user_1 column paste the function string that was copied previously from the function helper window i.e., (${__CSVRead (uservar.csv, 0)}).

18] To parameterize more than one more variable then click on Add Variable. For parameterizing toCityName filed in Name field enter “B” and in User_1 column paste the generated function but change the column number to 1 i.e.,(${__CSVRead (uservar.csv,1)}).

19] After entering all the values that are to be parameterized click on Add Variable and in Name field enter “next” and in the User_1 column paste the function string and replace 0 in the string with next i.e.(${__CSVRead (testdoc.csv, next)}).
20] Find and replace the variable values that are to be parameterized with function strings.

In this example find fromCityName value and replace it with the function string that is ${A} and find toCityName value and replace It with function string ${B}.
21] Save the script and Run the Test.
22] See and Check the results with new modifications.

43 comments:

  1. I am not getting all the recordings, can you please tell me everything step by step

    ReplyDelete
    Replies
    1. I have explained all the recordings step by step with screen shots so that you can compare with yours and get the point where you are stuck.
      If you still not get it then let me know at which point you didn't get it.

      Delete
    2. HI Mahesh,

      Could you pls let me know how do i pass variable if the URL is dynamic based on your search value? for ex: http://aa.bb.com/bikes/activa
      http://aa.bb.com/bikes/yamaha

      now the value after bikes is dynamic based on my search results and corresponding page is displayed. How do i parameterize this in Jmeter?

      Delete
    3. hi ihave paramaterize many a times but after parametrization it is not taking any value of from and to city name , it shows blank space there

      Delete
  2. Hi Mahesh, very nice explanation but am unable to parameterise like that what you have explained above
    my problem is am trying to parameterise login scenario, first thing is if I saved data file as .csv extension its being saved as tab separated values not comma separated as like what you have explained above.
    second thing request is not taking 2nd row of data.I have followed all the steps as you mentioned above

    ReplyDelete
    Replies
    1. Hi Manu,

      Please edit the csv file using notepad and make sure that the data appear coma separated.

      Its always better to edit the csv file using a notepad before making a test run.

      Hope this will solve your issues

      Regards,

      Faisel Hussain

      Delete
  3. May I know as to what is the need of Step No. 19

    19] After entering all the values that are to be parameterized click on Add Variable and in Name field enter “next” and in the User_1 column paste the function string and replace 0 in the string with next i.e.(${__CSVRead (testdoc.csv, next)}).

    We already added the parameters that we need as A and B.

    @Manu, have you tried using Update once per iteration and see if it picks up second row from csv file.

    ReplyDelete
    Replies
    1. Hi,

      I have tried the above steps but when I am using user and password as the variable name and parametrizing these two variable I cannot see the values being reflected in Request tab after running the application.
      And the values are as following.

      user ADMIN false true
      hidRequired user false true
      hidInputBoxName user false true
      label User Name true true
      password 6474113d763f7b6f2561be711ec114e2806e3535b0d5a9418b72a59a1cc38e2165349b7a6847db2c0946891f9d1fa7c6ddd657fd014ccdeee06f3731b16610832fff828af80cd72cd8e5de77575164e47fb3ae9bba0b84d44eee1757c7c4dda682ebbbfb26dbfdcc0a1eb800000 false true
      hidRequired false true
      hidInputBoxName password false true
      label Password false true
      isSkip false false true
      bt_Login Submit false true
      conId false true
      newCon true false true
      browserType IE false true
      applicationType BuildNPlay false true
      screenHeight 1024 false true
      isFromAlternate true false true
      tmpChk cd3fed8af7c70312d5abc60589e435e29c1b6e768fcd300106d26fd8c9db4b3f false true

      I was using user and password as the variable name.

      Delete
  4. I was able to do the parametrized, BUT the problem is that its NOT picking up the data row wise, also its mixing up the data, I have 2 values in single row, each row is set of data, here the data sets are getting mixed up..why?

    ReplyDelete
  5. There are easier ways to do this.
    1- Create data file (txt or CSV) , include values only (have each column separeted by coma)
    2- Add Configuration Element - CSV data set config
    3- In file name enter file path (including filename and extension)
    4- In variable names add the variables you will use (one for each column, separate with coma)
    5- replace the data to parametrize using ${variable name}

    ReplyDelete
  6. nice article..

    Im unable to parameterise the values in csv files.
    It is not picking the values in csv files instead of that it is taking the recored value.

    ReplyDelete
  7. Hi,
    I am a newb following using Jmeter...I tried the steps mentioned above but invein...View results tree does not display anything ...added response to check the error but nothing helped...I see
    INFO - jmeter.protocol.http.sampler.HTTPJavaImpl: Error Response Code: 302, Server sent no Errorpage
    2013/12/31 13:00:07
    ERROR - jmeter.protocol.http.sampler.HTTPJavaImpl: readResponse: java.io.EOFException
    2013/12/31 13:00:07
    INFO - jmeter.protocol.http.sampler.HTTPJavaImpl: Error Response Code: 302, Server sent no Errorpage
    2013/12/31 13:00:08 ERROR - jmeter.protocol.http.sampler.HTTPJavaImpl: readResponse: java.io.EOFException
    2013/12/31 13:00:08 in logs

    Can anyone put some light as what is the cause behind the same.

    ReplyDelete
    Replies
    1. Hey hi Mahesh,very good explanation but i am not able to add HTTP proxy server as in my J meter it shows test script recorder,Can you please help me with it.Thanks in advance.

      Delete
  8. Iam unable to see the different values using search parametrisization

    ReplyDelete
  9. HI,
    I am new in Jmeter. My application is .net application. I need to perform performance test on this application. I am facing two problem while running the script. While running the recorded script my script is getting failed. It shows Response code: 401 and internal server error: 500. On the other hand my parameterization is not working. It is only taking recorded one.
    Please help me in this regard
    Thanks

    ReplyDelete
  10. Hi,
    So how can I pass "xyz@gmail.com","12345", these two inputs as a single parameter in ${body} using csv file in jmeter

    ${body}="xyz@gmail.com","12345"

    ReplyDelete
  11. Hi,
    So how can I pass "xyz@gmail.com","12345", these two inputs as a single parameter in ${body} using csv file in jmeter

    ${body}="xyz@gmail.com","12345"

    ReplyDelete
  12. Find nice information about csv data set confirm - Paramaterazation http://www.testingjournals.com/csv-data-set-config/

    ReplyDelete
  13. Good one to understand how parameterization works.

    ReplyDelete
  14. Hello,

    can you please guide me how can I parameterize the URL ?
    i would like to change particular value in URL dynamically.

    ReplyDelete
  15. rajguru Bus rental service amritsar provides you comfortable journey to different places within affordable charges.

    ReplyDelete
  16. Hi,
    I am running the test plan for multiple user login's and i am reading the values from .csv. I want to get the user login also for the thread group in results so that i can identify which login is taking so much time.i am using the listeners but there is no options for customized user parameters to set in the results.

    can you please help me on this.

    ReplyDelete

  17. https://farakhanjazb.appengine.google.com/url?sa=i& url=https://bklaw.attorney/Top-Factors-Influencing-Bankruptcy-in-Fairfax-Virginia.html

    https://bklaw.attorney/Top-Factors-Influencing-Bankruptcy-in-Fairfax-Virginia.html

    ReplyDelete
  18. 꽁 머니 1 만 연리보: 머꽁 머니 1 꽁 머니 1 꽁 머니 1 꽁 머니 1 꽁 머연리보: 머꽁 머꽁 머리보: 머꽁 머니 1 꽁 머연리보: 머꽁 머연리보: 머꽁 머연리보: 머꽁 � 메리트카지노총판 메리트카지노총판 sbobet ทางเข้า sbobet ทางเข้า 950Play Online Betting: Online Betting at the Best Odds in

    ReplyDelete
  19. Harrah's Casino Atlantic City to undergo mandatory COVID vaccination
    Harrah's Atlantic 의정부 출장샵 City's temporary COVID vaccination program will 당진 출장안마 include masks, 태백 출장마사지 gloves and sanitary napkins. This change 포천 출장안마 will also come as a 포천 출장마사지

    ReplyDelete