JMeter - 为什么我的变量在我的测试中途被重新评估?

时间:2015-07-08 21:33:36

标签: jmeter

我最初以更复杂的方式发布了这个问题,但我现在更简单地复制了这个问题,所以我在广泛编辑我的帖子。

我有一个简单的测试计划来运行API。

Test Plan tree

它首先要做的是创建一个简单HTTP POST的会话。然后,我们使用JSON Path Extractor插件从响应中提取会话ID:

JSON Path Extractor

这会将新创建的会话ID读入名为id_JSON的变量中,后续PUT个请求会在其路径中使用会话ID,即/api/sessions/${id_JSON}/account

这通常效果很好,但我注意到,id_JSON会间歇性地突然出现默认值NOT_FOUND。样本将失败,当我查看请求时,我可以看到它尝试点击/api/sessions/NOT_FOUND/account而不是有效ID。我现在真正困惑的是,这将在请求已成功引用${id_JSON}并生成有效路径后发生。看起来这应该是不可能的,除非动态检查或重复查找id_JSON的值 - 否则如何从一个请求到下一个请求产生不同的值?

似乎任何Sample因任何原因失败,同一线程迭代中的后续请求都会失败,id_JSON具有默认值NOT_FOUND

我是否需要以任何特殊方式声明或管理变量id_JSON,以确保它获取会话ID的值并在整个线程迭代中保留它,直到下一次迭代用下一次迭代覆盖它会话ID?

2 个答案:

答案 0 :(得分:1)

The Extractor is a Post Processor, meaning it is applied after each sampler. So in you case it will run on the First Get and the 4 Puts.

So what you are noticing is absolutely regular, and if a Sampler fails, the extractor will fail to extract the ID and put NOT_FOUND in value.

If you are sure it does not change, then just put the Post Processor as a child of the first HTTP Request called "Create Session", it will then only run for it and the variable will not change anymore.

You can read more on this at:

答案 1 :(得分:0)

“转到下一个循环迭代”在线程组级别上运行。

使用任何嵌套循环控制器不会增加全局迭代计数器。您可以使用以下任一方法对其进行测试:

因此,如果您在线程组级别移动“循环”并删除nester Loop Controller(或将其循环计数设置为1),则您的方法应该按预期工作。