我们可以在Jmeter中使用什么容器来进行全局和环境变量的API测试 [英] what container we can use for global and environment variables in Jmeter for API testing

查看:167
本文介绍了我们可以在Jmeter中使用什么容器来进行全局和环境变量的API测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Jmeter进行API自动化测试.

I am trying to use Jmeter for API automation testing.

但是Jmeter并未像SOAP-UI和Postman一样为全局变量和环境变量提供任何单独的容器.

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

我尝试使用属性文件,该属性文件在整个项目中也与所有JSR223共享,但是属性也具有许多其他键,因此我没有任何选择可以删除一次启动的键.而且,我也可以更新似乎更可取的值

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

但是正如我说的那样,一旦启动我们就无法删除密钥,从属性中删除似乎很危险,因为它也有许多其他密钥,这可能是Jmeter内部需要的

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.

所以在Jmeter中存储变量是否可行,可以使用代码轻松创建/删除/更新这些变量,甚至可以通过HTTP Request等其他容器进行调用.

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

用户参数

Jsr223

任何变通办法都将有所帮助,并提前得到赞赏

Any workaround will be helpful and appreciated in advance

推荐答案

首先,您可以使用以下方法删除属性:

Firstly you can delete properties by using:

props.remove("shubhamKey");

如果您使用特定的前缀/后缀,则不应在内部影响JMeter.

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

请注意,测试计划中的所有UDV元素-无论它们在何处-都将在开始时进行处理.

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.

这篇关于我们可以在Jmeter中使用什么容器来进行全局和环境变量的API测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆