0
votes

I am new to Jmeter. I am trying to test a functionality of my application by setting multiple threads, using stepping thread group. I somehow, managed to get the folder creation like sample-1, sample-2 and so on where 1,2.. are the numbers of threads.One of the HTTP Requests requires body data which has file path as a json parameter.Is there any way to access the threadNum function inside the post body data or any other way in which i can change the filepath parameter for every thread without changing it manually?

My body data looks like: [{"filePath":"sample-1/file-1.txt", "id":123},{"filePath":"sample-2/file-2.txt", "id":124}....}]

1
show us what you've triedjohnny 5

1 Answers

1
votes

You can do it directly in the request or set it up as a variable in a pre or post processor in the plan.

[{"filePath":"sample-${__threadNum}/file-${__threadNum}.txt", "id":123},{"filePath":"sample-${__javaScript(${threadNum}+1)}/file-${__javaScript(${threadNum}+1)}.txt", "id":124}....}]

This works as well:

[{"filePath":"sample-${__BeanShell(ctx.getThreadNum())}/file-${__BeanShell(ctx.getThreadNum())}.txt", "id":123},{"filePath":"sample-${__BeanShell(ctx.getThreadNum()+1)}/file-${__BeanShell(ctx.getThreadNum()+1)}.txt", "id":124}....}]

Doing this though you would be better to store the thread number in a variable at the begining of the test plan and call it as you would any other jMeter variable.

In a post processor in a previous request you would do something like:

var threadNum = ctx.getThreadNum()
var path = 'sample-'+threadNum+'/file-'+threadNum+'.txt'
vars.put('path', path)
vars.put('threadID', threadNum.toString()) 

Keep in mind that getThreadNum() is 0 based, while ${threadNum} is 1 based.