I am new to jmeter and i am stuck in a condition . I am running jmeter http sample using a csv file where i am using a pre-processor script in which doing the following-
- setting http.method as per request like POST , GET , PUT ,PATCH
- setting http.path as "/restpath"
- setting request body.json
For Path i am using a "http.path" and passed the same in http sampler like ${http.path}. All above is working fine until i have dependent HTTP request like below use case -
Step 1 - Hit HTTP Request on path "/restpath" . After successful submission , i got a serverId in response and save the same in json extractor variable "serverID".
Step 2- Now i have to hit http request on path "/rest/${serverID}" . when i am trying to pass the same from csv file then the same is not replacing with captured variable in step 1 . Whatever i passed in csv file in http.path got passed and submit.
Expectation - In Sheet --> http.path == "/restpath/${serverID}" In HTTP Request submission --> "/restpath/4894rh89r"
Actual - In Sheet --> http.path == "/restpath/${serverID}" In HTTP Request submission --> "/restpath/${serverID}"
import org.apache.jmeter.engine.util.CompoundVariable;
import org.apache.jmeter.protocol.http.util.HTTPArgument;
//test input parameters
def httpMethod = vars.get("http.method");
//change the http method as per the data sheet
sampler.setMethod(httpMethod);
//set the HTTP Path
//URL url = new URL(vars.get('http.path'));
//vars.put('http.path',url.getPath());
//set the HTTP request body
if(!vars.get("input.json").equals("")){
def dataToBePosted = new CompoundVariable(new File(vars.get("jmeter.test.home") + vars.get("input.json")).text).execute();
def arg= new HTTPArgument("", dataToBePosted, null, true);
arg.setAlwaysEncoded(false);
sampler.getArguments().addArgument(arg);
//HTTP Body is set to
log.info(dataToBePosted);
}
Tried couple of hit n trial using __V() functions but no luck :(
