1
votes

I have test case in my csv file. The request URL has a custom variable.

Sample URL : .../abc/$id

I need to replace this id by the id that we get in response from the previous request. I used json extractor to fetch the id from the response. Now I need to update this id in the next test case request. Fetched the Request URL from jmeter context using below code:

String path = ctx.getCurrentSampler().toString(); 
path.replaceAll("$id", id);

I am not able to set this updated URL in jmeter context (ctx)

2

2 Answers

4
votes
  1. You need to assign new path value to path variable
  2. You need to set sampler path to the new value using sampler.setPath() method

So you need to amend your code like:

String path = ctx.getCurrentSampler().toString();
path = path.replaceAll("$id", id);
sampler.setPath(path);

Demo:

JSR223 PreProcessor change path


Also consider switching to JSR223 PreProcessor and Groovy language as Groovy performance is much higher, it better supports new Java features and provides some extra "syntax sugar" on top. See Groovy is the New Black article for details.

2
votes

Try to avoid the pre / post processors if possible. Your requirement is very simple and straight forward.

Directly use this in the path - assuming id is the name of variable which has the value.

/abc/${id}