开发者

JMeter - using substring on a user variable

Using jmeter, I have a variable passed from CSV file (using CSV Data Set Config), and I'd like to use a substring of it in an http request.

i.e. variable TIME=23:40, request paramaters are hour and minute, so I want to extrac开发者_运维百科t appropriate parts, in the HTTP Request.

I read you could use javascript, so for the hour, I tried ${TIME}.substring(0,2) , which didn't look as though it would work, and sure enough it didn't.

How do I do this?


You can do that by calling javascript function inline http://jmeter.apache.org/usermanual/functions.html

Ex :

${__javaScript('${TIME}'.substring(0\,2))}

Or

  1. create user defined variables sample
  2. create variable called myTime(or anything you want)
  3. create beanshell sampler, choose beanshell as language in it then:

    String tempTime = vars.get("myTime");
    String newTime = tempTime.substring(0,2);     
    vars.put("newTime", newTime);
    

use ${newTime} variable in your request

Edited according to the other answer. Comma needs to be quoted.


You can do it without calling Javascript interpreter (Rhino) with substring function from JMeter plugins:

${__substring(${TIME}, 0, 2)}


Make sure you escape commas in javascript functions:

${__javaScript('${TIME}'.substring(0\,2))}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜