如何在断言中添加“或"条件 [英] How to add 'Or' condition in assertion

查看:133
本文介绍了如何在断言中添加“或"条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果响应包含已完成"或正在处理,将需要一些时间来处理",我希望在两种情况下都可以通过请求.

I want the request to pass in both the cases if response contains "Completed" or "Progress, Will take time to process".

但是,如果我在响应断言中同时包含这两个断言,则会将其视为和".只有双方都满意时,它才会通过. 在这里,任何一项就足够了.请提出建议.

But if I include both this assertions in response assertion, it will take it as 'and'. It will pass only if both are satisfied. Here any one of this is sufficient. Please suggest.

推荐答案

您将需要一个支持脚本的断言,即

You will need to go for an assertion which supports scripting, i.e. Beanshell Assertion

  1. 将Beanshell断言添加为请求的子项,该请求将返回已完成"或正在进行"消息
  2. 将以下代码放入脚本"区域:

  1. Add Beanshell Assertion as a child of the request which returns either "Completed" or "Progress" messages
  2. Put the following code into "Script" area:

String response = new String(ResponseData);

Failure = !(response.contains("Completed") || response.contains("Progress, Will take time to process"));

位置:

  • ResponseData-保留父采样器响应的字节数组
  • Failure-布尔值,指示父采样器是否应该失败.
  • ResponseData - byte array which holds parent sampler response
  • Failure - boolean which indicates whether parent sampler should be failed or not.

请参见如何使用BeanShell:JMeter最喜欢的内置组件指南.

这篇关于如何在断言中添加“或"条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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