1
votes

I need to extract the dynamic value "BSS1,DS1,HYS1,MS1,PTS1,QS1,USG1,YS1,RT10086,RT10081,RT10084,RT10082,OT10076,RT10083,UT10081,RT10085,"
from the string response "ACCOUNT_DETAIL_ACCOUNT_PRODUCT_SERVICES_EDIT_UPDATE_NameSpace.grid.setSelectedKeys(["BSS1","DS1","HYS1","MS1","PTS1","QS1","USG1","YS1","RT10086","RT10081","RT10084","RT10082","OT10076","RT10083","UT10081","RT10085"]);"

I have tried using the regular expression extractor :

Regular Expression :Keys\(\[\"(.+?)\",\"(.+?)\",\"(.+?)\",\"(.+?)\",\"(.+?)\",\"(.+?)\",\"(.+?)\",\"(.+?)\",\"(.+?)\",\"(.+?)\",\"(.+?)\",\"(.+?)\",\"(.+?)\",\"(.+?)\",\"(.+?)\",\"(.+?)\"]\)

template : $1$$2$$3$$4$$5$$6$$7$$8$$9$$10$$11$$12$$13$$14$$15$$16$

But the above regular expression works only if there are 16 values in the response. If the response contains less number of values, for example, "ACCOUNT_DETAIL_ACCOUNT_PRODUCT_SERVICES_EDIT_UPDATE_NameSpace.grid.setSelectedKeys(["BSS1","DS1"]);" then the above regular expression doesn't work.

How can I extract the values in the response if the total count is unknown? Also the double quotes in the response need to be omitted.

Is there any post processor using which dynamic values can be extracted?

Any help is greatly appreciated.

1

1 Answers

0
votes

I believe it will be easier with some scripting.

  1. Add Beanshell PostProcessor as a child of the request which returns aforementioned response
  2. Put the following code into the PostProcessor's "Script" area:

    String response = new String(data);
    
    String rawKeys = response.substring(response.indexOf("[") + 1, response.indexOf("]")); // get the data inside square brackets
    String keysWithoutQuotes = rawKeys.replaceAll("\"", "");          // remove quotes
    String[] keyData = keysWithoutQuotes.split("\\,");                // get array of keys
    
    for (int i = 0; i < keyData.length; i++) {                       // store array of keys into JMeter variables like
    
      vars.put("Keys_" + (i +1), keyData[i]);                        // Keys_1=BSS1, Keys_2=DS1, etc.
    }
    
    vars.put("Keys_matchNr", String.valueOf(keyData.length));       // set Keys_matchNr variable
    

Where:

  • data is byte array containing parent sampler's response data
  • vars is a shorthand to JMeterVariables class which provides read/write access to JMeter Variables.

As a result you'll have variables like:

Keys_1=BSS1
Keys_2=DS1
..
Keys_matchNr=X

See How to Use BeanShell: JMeter's Favorite Built-in Component guide for additional information on Beanshell scripting in JMeter and some more examples