【问题标题】:Jmeter beanshell Post ProcessorJmeter beanshell 后处理器
【发布时间】:2014-10-24 09:17:29
【问题描述】:

如何使用 beanshell 后处理器来分析每个请求的数据? 我需要分析请求,如果请求通过 - 写入文件,如果请求失败 - 写入其他文件。 任何人都可以为这种情况编写简单的示例脚本吗?

【问题讨论】:

    标签: jmeter beanshell


    【解决方案1】:

    如果要将通过和失败的请求保存在不同的文件中,可以使用 View Results Tree 监听器元素,不需要 beanshell 后处理器和 beanshell 脚本。将两个 View results tree() 元素添加到线程组。要保存通过的请求,请在仅记录/显示选项下勾选成功。还提供用于保存这些请求的文件路径。要存储失败的请求,请在第二个视图结果树元素和文件路径中检查 错误,如图所示。您可以在配置按钮下决定要存储的内容。

    注意:这会消耗更多内存,不应用于大负载。

    【讨论】:

      【解决方案2】:
      SampleResult res = ctx.getPreviousResult();
      
      if(res.isSuccessful()) {
          String DirPath = FileServer.getFileServer().getBaseDir();
      
          // write into jmeter.log file under Jmeter/bin directory
          RandomAccessFile f = new RandomAccessFile(DirPath + File.separator + "SuccessFile"+"."+ fileSize, "rw");
          f.writeUTF(DirPath.toString());
          f.writeUTF("test.txt");
      } else {
       // do same thing to create a file for failure.
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-20
        相关资源
        最近更新 更多