what container we can use for global and environment variables in Jmeter for API testing

和自甴很熟 提交于 2019-12-11 17:36:46

问题


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

Jsr223

Any workaround will be helpful and appreciated in advance


回答1:


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","")



回答2:


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.



来源:https://stackoverflow.com/questions/48443621/what-container-we-can-use-for-global-and-environment-variables-in-jmeter-for-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!