Jmeter Preprocessor to add Dynamic parameters

sub: one scenario need to capture the data from previous request and pass as a parameters in jmeter

Problem: but key and pair both are dynamic and very huge values. we can't handle each parameter as below




Note: Here Key and values both are dynamic

Solution : we need to capture all the respose data and segrigate and pass through JSR223Preprocessor. Here is the solution.

Step1:





Step 2: Modify the request






Add JSR223Preprocessor in the request

//int count=Integer.parseInt(vars.get(“paths_matchNr”))
//log.info “parameters count” + count
//vars.put("JsonResponse", prev.getResponseDataAsString());
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.text.*;
import java.util.*;

//Paths Data

List result= new ArrayList();
def count = Integer.parseInt(vars.get("ALLVALUES_matchNr"));
log.info("count=" + count);//83
//["#31:218","#62:1","#61:1","#63:1","#31:285"]
String prefix="";//paths[3][]
int m=0;
for(int i=1;i<=count;i++)
{
prefix="paths["+m+"][]";
log.info("path=" + prefix);
String response =vars.get("ALLVALUES_"+i);  //["#31:218","#62:1","#61:1","#63:1","#31:285"]
log.info("the first string alue is s1="+response);
String[] array=response.split(",");
log.info("the arraylengh="+array.length);
for(int j=0;j<array.length;j++)
{
String finalresponse= array[j].replaceAll("\"","");
finalresponse=finalresponse.replaceAll("\\]", "");
finalresponse=finalresponse.replaceAll("\\[", "");

//.replaceAll("\\[","").replaceAll("\\]","")
sampler.addArgument(prefix,finalresponse);
log.info("the final resulsyt is "+ prefix+":"+finalresponse);
}

m=m+1;
}

//Scopes Data


def count_scopes = Integer.parseInt(vars.get("AllScopes_matchNr"));

log.info("count of scopes"+count_scopes);

String keyscope="scope[]";
for (int x=1;x<=count_scopes;x++)
{
    String scopevalues= vars.get("AllScopes_"+x);
log.info("scope values:"+ scopevalues);
sampler.addArgument(keyscope,scopevalues)
log.info("the final resulsyt is "+ keyscope+":"+scopevalues);

}

//For Vertics

String keyvertics="vertices[]";

def vertics1= vars.get("vertics1");
sampler.addArgument(keyvertics,vertics1);
def count_vertices=Integer.parseInt(vars.get("verticesrest_matchNr"));

for(int z=1;z<=count_vertices;z++){
String verticesvalues= vars.get("verticesrest_"+z);
sampler.addArgument(keyvertics,verticesvalues);
log.info("the final resulsyt is "+ keyvertics+":"+verticesvalues);

}

Comments

Popular posts from this blog

Convert Swagger apis into jmeter script

Script for replace the data into the file content using groovy with jsr223