• jmeter中beanshell断言的使用


    简单使用beanshell的内容,进行测试内容的判断 

    这里通过断言内容,修改if的条件,达到发送警报邮件的功能 

    beanshell 代码如下:     SampleResult 等效于 prev 

    log.error(vars.get("ReqStatus"));

    int count=Integer.parseInt(vars.get("errorcount").trim());

    vars.put("result", SampleResult.getResponseDataAsString());

    if (SampleResult.getResponseDataAsString().indexOf("sessionId")!= -1)
    {
    String code =SampleResult.getResponseCode();
    String msg = SampleResult.getResponseMessage();
    String data = SampleResult.getResponseDataAsString();

    log.error("------return code "+ code);

    vars.put("responsecode", code);
    vars.put("responsedata",data);
    vars.put("responsemsg",msg);

    count = count + 1;
    vars.put("errorcount", count.toString());

    if((count%1)==0)
    {
    vars.put("sendmail","yes");
    }
    else{
    vars.put("sendmail","no");
    }

    SampleResult.setSuccessful(true);
    }


    else
    {
    String code =SampleResult.getResponseCode();
    String msg = SampleResult.getResponseMessage();
    String data = SampleResult.getResponseDataAsString();

    log.error("------return code "+ code);

    vars.put("responsecode", code);
    vars.put("responsedata",data);
    vars.put("responsemsg",msg);

    SampleResult.setSuccessful(true);

    }

    设置系统的变量如下:

    附件顺便加上beanshell的用法汇总:

    http://www.cnblogs.com/xxyBlogs/p/5966194.html

  • 相关阅读:
    Ubuntu vi命令
    Aria2 使用
    axel 参数 文件下载地址
    序列化模块、加密模块
    项目开发规范、time模块、日志
    递归函数(了解)
    模块
    函数进阶四(装饰器、内置函数)
    函数进阶三(生成器、生成器表达式、匿名函数)
    函数进阶二(函数名运用,闭包,迭代器)
  • 原文地址:https://www.cnblogs.com/yingchen/p/6483849.html
Copyright © 2020-2023  润新知