Jmeter如何在包含控制器中使用响应Assert

x4shl7ld  于 9个月前  发布在  其他
关注(0)|答案(2)|浏览(114)

我有一个大型/复杂的项目,我试图在Jmeter 3中设置。
API请求/响应在一个文件夹中,而在另一个文件夹中,我为API使用了一个包含控制器,并希望在其中放置一个Assert。这是一个测试片段,我希望将许多不同的响应放入自己的jmx中,然后从另一个jmx/测试计划调用它们(参见下表)。

|topdir
||API (literally just the requests)
|||api1
|||api2
||fragments (this contains the api requests via an include controller)
|||api1_1(with response assertions of abc)
|||api1_2(with response assertion of bca)
||tests
|||testplan A (include controller of fragment api_1)
|||testplan B (include controller of fragment api_2)
|||testplan C (include controller of fragment api_1 and 2)

字符串
我试图让我的生活在重用性方面更容易,因为我会在许多JMX文件中使用这个位很多。
我的问题是,无论我如何安排测试计划:

|TestPlan
|View results tree
||ThreadGroup
|||Include controller (to test fragment)


或者第一个测试片段:

|TestFragment
||simple controller (this can be removed without effect)
|||include controller (to wsdl API request)
|||response assertion


为什么响应Assert不拾取API响应?API文件是这样设置的:

|TestPlan
||TestFragment
|||HTTPRequest
|||XmlFormatter


请注意,我必须将此Assert放在中间测试片段中,因为为数千个测试重新构建每个响应Assert是不可行的
我还尝试在响应Assert的jmeterVariables部分使用prev.getResponseDataAsString(),但得到的结果是“response was null”。
我现在已经尝试在API jmx上设置一个变量,在第二个片段中打印变量(我试图在那里做Assert),变量是空的:(.这个抽象层似乎是问题所在-再次,为什么它不读取变量?当然它在作用域中(特别是如果我从其中删除简单的控制器?

twh00eeo

twh00eeo1#

我无法通过以下设置重现您的问题:

  • JMeter测试计划包含一个带有Dummy Sampler的测试片段,它只返回foo
  • 包括引用测试片段的控制器
  • 在Include控制器之后添加响应Assert

x1c 0d1x的数据
正如你所看到的,响应Assert“捕获”通过包含控制器加载的采样器的响应体,如果没有匹配-它将采样器标记为失败。
请注意,JMeterAssert应用于其范围内的所有采样器。
如果它没有反映您的设置,请提供minimal reproducible example并指出所需/预期的行为。

pn9klfpd

pn9klfpd2#

OK -我在测试片段中使用jsr 223Assert找到了一种解决方法:

if( vars.get('ResultDescription')!=vars.get('descSuccess')){
    prev.setSuccessful(false) // this will fail the step
    prev.setResponseMessage('Got: '+vars.get('ResultDescription')) // you will see this message in the failed sampler result
}

字符串
并通过xpath提取器直接从API设置该变量

相关问题