zoukankan      html  css  js  c++  java
  • Jmeter二次开发代码(1)

    package org.apache.jmeter.functions;

    import java.util.Collection;
    import java.util.LinkedList;
    import java.util.List;
    import org.apache.jmeter.engine.util.CompoundVariable;
    import org.apache.jmeter.samplers.SampleResult;
    import org.apache.jmeter.samplers.Sampler;
    import org.apache.jmeter.util.JMeterUtils;

    public class MyExcel extends AbstractFunction {

    private static final List<String> desc = new LinkedList<>();
    private static final String KEY = "__MyExcel"; // Function name //$NON-NLS-1$
    private Object[] values;

    //初始化
    public MyExcel() {
    }

    static {
    desc.add(JMeterUtils.getResString("EXCEL文件路径")); //文字说明
    desc.add(JMeterUtils.getResString("所要读取EXCEL文件的SHEET页")); //文字说明
    desc.add(JMeterUtils.getResString("读取的起始行")); //文字说明
    desc.add(JMeterUtils.getResString("读取的起始列")); //文字说明
    }

    @Override
    public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {

    String myExcelValue = "";
    // 定义Jmeter传参
    String excelFilePath = (((CompoundVariable) values[0]).execute()).toString();
    String sheetName = (((CompoundVariable) values[1]).execute()).toString();
    int rowNum = new Integer(((CompoundVariable) values[2]).execute().trim());
    int columnNum = new Integer(((CompoundVariable) values[3]).execute().trim());

    myExcelValue = MyExcelRead.getColumn(excelFilePath, sheetName, rowNum, columnNum);

    return myExcelValue;
    }

    @Override
    public void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException {
    //检查参数个数
    checkParameterCount(parameters, 4);
    values = parameters.toArray();

    MyExcelRead.clearAll();
    }

    /** {@inheritDoc} */
    @Override
    public String getReferenceKey() {
    return KEY;
    }

    /** {@inheritDoc} */
    @Override
    public List<String> getArgumentDesc() {
    return desc;
    }

    }

  • 相关阅读:
    把CentOS改成中文
    String,StringBuffer,StringBuilder三者性能对比
    在Linux上部署安装C/C++开发环境
    Kali Linux安装ssh服务
    Kali VirtualBox安装增强功能
    CentOS安装docker
    CentOS安装jdk11
    Java基本数据类型
    奥卡姆剃刀定律在Java代码中的体现——记一次LeetCode刷题心得
    Java 实现简易登录注册功能
  • 原文地址:https://www.cnblogs.com/xxsl/p/9023690.html
Copyright © 2011-2022 走看看