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

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

Jmeter retrieve specific portion of SamplerData from SampleResult

问题

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

以下是我的当前输出:

  1. GET https://google.com/
  2. GET 数据:
  3. hello world
  4. [无 cookies]

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

我有以下的 BackendListener 代码:

  1. @Override
  2. public void handleSampleResults(List<SampleResult> list, BackendListenerContext backendListenerContext) {
  3. StringBuilder stringBuilder = new StringBuilder();
  4. String fileName = "C:\\projects\\sampleResults.csv";
  5. try {
  6. list.forEach(sampleResult -> {
  7. stringBuilder.append(sampleResult.getSamplerData());
  8. stringBuilder.append("\n");
  9. });
  10. BufferedWriter out = new BufferedWriter(
  11. new FileWriter(fileName));
  12. out.write(stringBuilder.toString());
  13. out.close();
  14. } catch (IOException e ){
  15. }
  16. }
英文:

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

Here's my current output:

  1. GET https://google.com/
  2. GET data:
  3. hello world
  4. [no cookies]

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

I have the following BackendListener code:

  1. @Override
  2. public void handleSampleResults(List&lt;SampleResult&gt; list, BackendListenerContext backendListenerContext) {
  3. StringBuilder stringBuilder = new StringBuilder();
  4. String fileName = &quot;C:\\projects\\sampleResults.csv&quot;;
  5. try {
  6. list.forEach(sampleResult -&gt; {
  7. stringBuilder.append(sampleResult.getSamplerData());
  8. stringBuilder.append(&quot;\n&quot;);
  9. });
  10. BufferedWriter out = new BufferedWriter(
  11. new FileWriter(fileName));
  12. out.write(stringBuilder.toString());
  13. out.close();
  14. } catch (IOException e ){
  15. }
  16. }

答案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:

确定