Reputation: 13753
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
)
Upvotes: 1
Views: 2986
Reputation: 15370
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}
Upvotes: 2
Reputation: 168002
path
variableSo you need to amend your code like:
String path = ctx.getCurrentSampler().toString();
path = path.replaceAll("$id", id);
sampler.setPath(path);
Demo:
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.
Upvotes: 4