1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这里就不再赘述

2,代码如下:

 package com.mytest.functions;

 import org.apache.jmeter.engine.util.CompoundVariable;

 import org.apache.jmeter.functions.AbstractFunction;

 import org.apache.jmeter.functions.InvalidVariableException;

 import org.apache.jmeter.samplers.SampleResult;

 import org.apache.jmeter.samplers.Sampler;

 import org.apache.jmeter.threads.JMeterVariables;

 import java.util.Collection;

 import java.util.LinkedList;

 import java.util.List;

 public class If extends AbstractFunction {

     private static final List<String> desc = new LinkedList<String>();

     private static final String KEY = "__if";

     static {

         desc.add("Actual value");

         desc.add("Expected value");

         desc.add("Result if actual == expected");

         desc.add("Result if actual != expected");

         desc.add("Name of variable in which to store the result (optional)");

     }

     private Object[] values;

     public If() {

     }

     @Override

     public synchronized String execute(SampleResult previousResult, Sampler currentSampler)

             throws InvalidVariableException {

         String actual = getParameter(0);

         String expected = getParameter(1);

         String result = null;

         if (actual.equals(expected)) {

             result = getParameter(2).toString();

         } else {

             result = getParameter(3).toString();

         }

         JMeterVariables vars = getVariables();

         if (vars != null && values.length > 4) {

             String varName = getParameter(4).trim();

             vars.put(varName, result);

         }

         return result;

     }

     @Override

     public synchronized void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException {

         checkMinParameterCount(parameters, 4);

         values = parameters.toArray();

     }

     @Override

     public String getReferenceKey() {

         return KEY;

     }

     @Override

     public List<String> getArgumentDesc() {

         return desc;

     }

     private String getParameter(int i) {

         return ((CompoundVariable) values[i]).execute();

     }

 }

jmeter添加自定义扩展函数之if判断的更多相关文章

  1. jmeter添加自定义扩展函数之图片base64编码

    打开eclipse,新建maven工程,在pom中引入jmeter核心jar包: <!-- https://mvnrepository.com/artifact/org.apache.jmete ...

  2. jmeter添加自定义扩展函数之DoubleSum

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  3. jmeter添加自定义扩展函数之小写转换大写

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  4. jmeter添加自定义扩展函数之大写转换小写

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  5. jmeter添加自定义扩展函数之MD5加密

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  6. jmeter添加自定义扩展函数之Strng---base64解密

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  7. jmeter添加自定义扩展函数之String---base64加密

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  8. jmeter添加自定义扩展函数之图片base64

    原文连接:---------https://www.cnblogs.com/qiaoyeye/p/7218770.html----------- 打开eclipse,新建maven工程,在pom中引用 ...

  9. Jmeter入门4 添加断言 判断响应数据是否符合预期

    发出请求之后,通过添加断言可以判断响应数据是否是我们的预期结果. 1 在Jmeter中发送一个登录的http请求(参数故意输入错误).结果肯定是登陆失败啦. 但结果树中http请求的图标显示‘绿色’表 ...

随机推荐

  1. Spring学习(七)--Spring MVC的高级技术

    一.Spring MVC配置的替代方案 我们已经了解如何通过AbstractAnnotationConfigDispatcherServlet- Initializer快速搭建了Spring MVC环 ...

  2. android项目的目录结构讲解

    参考书籍:<第一行代码Android> 一:android项目的目录结构讲解 1..gradle和.idea         这两个目录下放置的都是Android Studio自动生成的一 ...

  3. 水题(三角形与扇形面积计算sin()应用)

    J - Sincerely Gym - 101350J Physics cat likes to draw shapes and figure out their area. He starts by ...

  4. HTTP中ip地址伪造的问题以及解决办法

    在真实环境下,php获取客户端ip地址的方法通常有以下几种: (1):通过$_SERVER[ "HTTP_CLIENT_IP" ] (2):通过$_SERVER[ "HT ...

  5. django的配置

    1.django的默认配置 import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) # 获取 ...

  6. Centos7防火墙常用命令

    有些人安装的linux的系统默认防火墙不是iptables,而是firewall,那就得使用以下方式关闭防火墙了. >>>关闭防火墙 systemctl stop firewalld ...

  7. NGUI的输入框的校验(input filed script)

    一,我们制作一个输入框,右键添加Sprite ,给Sprite添加一个child的label,然后给Sprite添加一个box collider,接着添加input filed script,将lab ...

  8. 道路模型--linear-parabolic model

    读过很多道路追踪的论文,经常都需要道路模型的建模.我不知道是不是因为自己太笨还是怎样,好多人建的模型我实在无法理解他的用意何在,而且我真的深刻怀疑他们那些模型的参数是不是真的可以求出来.就比如这篇文章 ...

  9. 创建一个java项目并部署到weblogic服务器

    转自:https://blog.csdn.net/krystal_sl/article/details/52847953 新建一个项目的步骤 打开eclipse,右键点击new–>java pr ...

  10. 20180119-文件操作open用法

    官方文档 open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, open ...