JMeter-如何从已从base64解码并存储在变量中的响应中提取值?全部在同一采样器下 [英] JMeter - How to extract values from a response which has been decoded from base64 and stored in a variable? All under the same sampler

查看:679
本文介绍了JMeter-如何从已从base64解码并存储在变量中的响应中提取值?全部在同一采样器下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试测试Web服务的性能,并且在使用和传递变量方面存在一些问题.有多个顺序请求,这取决于来自先前响应的某些数据.在将所有请求发送到端点之前,需要将所有请求编码为base64并放置在SOAP信封名称空间中.它返回并编码了响应,需要对其进行解码以查看需要用于下一个请求的xml值.到目前为止,我所做的是:

I am trying to test a webservice's performance, and having a few issues with using and passing variables. There are multiple sequential requests, which depend on some data coming from a previous response. All requests need to be encoded to base64 and placed in a SOAP envelope namespace before sending it to the endpoint. It returns and encoded response which needs to be decoded to see the xml values which need to be used for the next request. What I have done so far is:

1)Beanshell预处理器添加到第一个样本中,以对从文件中调用的有效负载进行编码. 2)正则表达式从整个响应中拉出编码后的响应位. 3)Beanshell后处理器解码响应并写入文件(以防万一).我已将解码后的响应存储在变量输出"中,并且由于将响应正确地写入文件,因此我知道这是可行的. 4)之后,我添加了4个正则表达式提取器,并尝试了各种操作,例如应用于不同的部分,检查不同的字段,检查JMeter变量等.但是,这似乎不起作用.

1) Beanshell preprocessor added to first sample to encode the payload which is called from a file. 2) Regex to pull the encoded response bit from whole response. 3) Beanshell post processor to decode the response and write to a file (just in case). I have stored the decoded response in a variable 'Output' and I know this works since it writes the response to file correctly. 4) After this, I have added 4 regex extractors and tried various things such as apply to different parts, check different fields, check JMeter variable etc. However, it doesn't seem to work.

这就是我的树的样子.

JMeter树

我正在像这样存储对'Output'变量的解码响应,由于它已正确写入文件,因此它可以正常工作:

I am storing the decoded response to 'Output' variable like this and it works since it's writing to file properly:

import org.apache.commons.io.FileUtils;
import org.apache.commons.codec.binary.Base64;

String Createresponse= vars.get("Createregex");
vars.put("response",new String(Base64.decodeBase64(Createresponse.getBytes("UTF-8"))));

Output = vars.get("response");

f = new FileOutputStream("filepath/Createresponse.txt");
p = new PrintStream(f); 
this.interpreter.setOut(p); 
print(Output);
f.close();

这是我之后使用Regex的方式,我尝试了不同的选择:

And this is how I using Regex after that, I have tried different options:

正则表达式设置

不幸的是,正则表达式没有从'Output'变量中获取这些值.我基本上需要保存它们,以便可以在有效负载文件中使用$ {docID}进行下一个请求.

Unfortunately though, the regex is not picking up these values from 'Output' variable. I basically need them saved so i can use ${docID} in the payload file for next request.

对此有任何帮助,我们深表感谢!如果需要,也很乐意提供更多详细信息.

Any help on this is appreciated! Also happy to provide more detail if needed.

我有一个后续问题.我正在尝试与多个用户一起运行.我的有效负载xml文件中有一个$ {searchuser}字段,在此处的预处理器中调用.

I had a follow up question. I am trying to run this with multiple users. I have a field ${searchuser} in my payload xml file called in the pre-processor here.

上方的CSV数据集如下:

The CSV Data set above it looks like this:

但是,它没有从CSV中获取值并替换为有效负载文件.任何帮助表示赞赏!

However, it is not picking up the values from CSV and substituting in the payload file. Any help is appreciated!

推荐答案

正则表达式提取器配置有两个问题:

You have 2 problems with your Regular Expression Extractor configuration:

  1. 适用于:必须为response
  2. 要检查的字段:必须为BodyBody as a Document用于二进制文件格式符,例如PDF或Word.
  1. Apply to: needs to be response
  2. Field to check: needs to be Body, Body as a Document is being used for binary file formants like PDF or Word.


顺便说一句,您可以使用插件管理器


By the way, you can do Base64 decoding and encoding using __base64Decode() and __base64Encode() functions available via JMeter Plugins. The plugins in their turn can be installed in one click using Plugin Manager

这篇关于JMeter-如何从已从base64解码并存储在变量中的响应中提取值?全部在同一采样器下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆