Jmeter从SampleResult中获取SamplerData的特定部分

huangapple go评论64阅读模式
英文:

Jmeter retrieve specific portion of SamplerData from SampleResult

问题

我正在尝试检索 SampleResultSamplerData 的特定部分。

以下是我的当前输出:

GET https://google.com/

GET 数据:
hello world

[无 cookies]

我想要的是在 GET 数据 部分内的特定 hello world

我有以下的 BackendListener 代码:

@Override
public void handleSampleResults(List<SampleResult> list, BackendListenerContext backendListenerContext) {
    StringBuilder stringBuilder = new StringBuilder();
    String fileName = "C:\\projects\\sampleResults.csv";
    try {
        list.forEach(sampleResult -> {
            stringBuilder.append(sampleResult.getSamplerData());
            stringBuilder.append("\n");
        });
        BufferedWriter out = new BufferedWriter(
                new FileWriter(fileName));
        out.write(stringBuilder.toString());
        out.close();
    } catch (IOException e ){

    }
}
英文:

I'm trying to retrieve a specific portion of the SamplerData from the SampleResult.

Here's my current output:

GET https://google.com/

GET data:
hello world

[no cookies]

What i want is specifically the hello world inside the GET data section.

I have the following BackendListener code:

@Override
public void handleSampleResults(List&lt;SampleResult&gt; list, BackendListenerContext backendListenerContext) {
    StringBuilder stringBuilder = new StringBuilder();
    String fileName = &quot;C:\\projects\\sampleResults.csv&quot;;
    try {
        list.forEach(sampleResult -&gt; {
            stringBuilder.append(sampleResult.getSamplerData());
            stringBuilder.append(&quot;\n&quot;);
        });
        BufferedWriter out = new BufferedWriter(
                new FileWriter(fileName));
        out.write(stringBuilder.toString());
        out.close();
    } catch (IOException e ){

    }
}

答案1

得分: 0

针对您的情况,似乎您正在尝试提取 HTTP 请求 采样器的主体数据,最简单的解决方案是使用 sampleResult.getQueryString() 函数。

演示:

Jmeter从SampleResult中获取SamplerData的特定部分

然而,我未能看出在这里实现自己的后端侦听器的必要性,您可以使用 Flexible File Writer 插件以更快、更简单的方式实现相同的效果。

英文:

For particular your case it seems that you're trying to extract the body data of the HTTP Request sampler the easiest solution would be going for sampleResult.getQueryString() function

Demo:

Jmeter从SampleResult中获取SamplerData的特定部分

However I fail to see the need of implementing your own Backend Listener here, you can achieve the same much faster and easier using Flexible File Writer plugin

huangapple
  • 本文由 发表于 2020年9月4日 21:26:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63742136.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定