how to extract value from request in Jmeter

前端 未结 4 840
梦谈多话
梦谈多话 2021-01-19 11:14

Hi I am passing an email which is a time function like below

email = ${__time(MMddyy)}_${__time(HMS)}@yopmail.com

The value of this functi

相关标签:
4条回答
  • 2021-01-19 11:38
    1. Add a Beanshell PostProcessor as a child of the request which sends that POST request
    2. Put the following code into the PostProcessor's "Script" area

      import org.apache.jmeter.config.Argument;
      import org.apache.jmeter.config.Arguments;
      
      Arguments argz = ctx.getCurrentSampler().getArguments();
      for (int i = 0; i < argz.getArgumentCount(); i++) {
          Argument arg = argz.getArgument(i);
          if (arg.getName().equals("email")) {
              vars.put("EMAIL", arg.getValue());
              break;
          }
      }
      
    3. Refer generated value as ${EMAIL} where required.

    Clarification:

    • above code will extract the value of email request parameter (if any) and store it to EMAIL JMeter Variable
    • ctx - shorthand to JMeterContext class instance
    • vars = shorthand to JMeterVariables class instance
    • Arguments and Argument - you can figure that out from JMeterContext JavaDoc

    See How to use BeanShell: JMeter's favorite built-in component guide for more information on Beanshell scripting in JMeter.

    0 讨论(0)
  • 2021-01-19 11:47

    Is it HTTP Sampler? If so, just put into beanshell postprocessor:

    String prevQuery = prev.getQueryString(); //your request text
    System.out.println(prevQuery );
    

    Also works for any samplers:

    String prevQuery  = prev.getSamplerData();
    
    0 讨论(0)
  • 2021-01-19 11:52

    You can use Regular Expression extractor to extract the e-mail address from the request URL.

    Add Regular Expression Extractor as a child of sampler which sends the post request. In the Regular Expression Extractor select URL in Response Filed to check instead of Body.

    You should be able to extract e-mail id from the request in this way.

    0 讨论(0)
  • 2021-01-19 12:03

    Instead of the entire email, you can store the timestamp value in a variable and then use this timestamp variable to create email anywhere you want. This way you will can have same email every where.

    0 讨论(0)
提交回复
热议问题