从jmeter的中心调用自定义断言消息

时间:2018-02-08 08:37:47

标签: jmeter beanshell

我是jmeter的新手,想知道是否可以从中心位置调用自定义断言消息。

Thread group 1
http sample
 xpath extraction
 custom assertion message

Thread group 2
http sample 1
 xpath extraction
 custom assertion message
http sample 2
 xpath extraction
 custom assertion message

自定义消息使用xpath提取来获取响应代码,如果返回成功消息代码,则忽略自定义消息。

如果响应代码不是成功响应,我们将提取实际响应代码并在自定义断言消息中使用。

我想从一个中心位置调用自定义消息。

自定义断言如下:

       if (!"SuccessResponseCode".equals(vars.get("xpathResponseCode"))  && prev_result !=  null){

AssertionResult.setFailure(true);
AssertionResult.setFailureMessage("The response code is "+vars.get("xpathextractionResponseCode").toString()+" and the expected is expectedResponseCode"+ctx.getThreadGroup().getName()+" test case.");

}

所以我想调用外部自定义消息

自定义断言

线程组2     http样本1      xpath提取      JS232 - 调用自定义消息     http样本2      xpath提取      JS232 - 调用自定义消息

1 个答案:

答案 0 :(得分:0)

只需将您的断言置于与Thread Groups相同的级别。

断言遵循JMeter Scoping Rules,所以这样一个断言将应用于其范围内的所有采样器:

JMeter Assertion Scoping Rules

相关问题