0
votes

I am trying to use Jmeter for API automation testing.

But Jmeter hasn't provided any separate containers for global and environment variables similarly like SOAP-UI and Postman.

I tried to use property file which also shared among all the JSR223 throughout the project but property having many others keys too and I haven't got any option by which I can delete key which been initiated once. Moreover, I can update the value too which seems most preferable to use

Below code I am using to set and get the values

props.put("shubhamKey", "shubhamValue")

props.get("shubhamKey")

I can also update it using same key

props.put("shubhamKey", "shubhamNewValue") 

But as I said we can't delete key once initiated and it seems dangerous to delete from properties as it has many other keys too which may be required by Jmeter internally

After seeing too many things I have seen "User Defined Variables" where I can specify my key-value pairs. I am able to get the value using below code:

vars.get("shubhamLocalVariable")

But I am not able to set the value using below code:

vars.put("shubhamUserKeyagain","shubhamUservalue")

neither I got any option by which I further update it or delete it.

so Is there any feasible thing to store variables in Jmeter which can be easily created/deleted/updated using the code and can even call by other containers like HTTP Request.

Moreover I also want a container which preserve the values so the next iteration and next time (any time like other day) it will start with latest values

User Parameters

enter image description here

Jsr223

enter image description here

Any workaround will be helpful and appreciated in advance

2

2 Answers

0
votes

As for me, I'm using a JSR223 Sampler at the begining of every Thread. And for me it works:

vars.put("checksums_1","")
vars.put("checksums_2","")
vars.put("checksums_3","")
0
votes

Firstly you can delete properties by using:

props.remove("shubhamKey");

And if you use specific prefix/suffix it shouldn't effect JMeter internally.

User Defined Variables isn't the best way to handle dynamic values, it's used for static variables

Note that all the UDV elements in a test plan - no matter where they are - are processed at the start.

But you can set variable by string or variable or function, e.g:

For defining variables during a test run, see User Parameters which use similar assignments.