beanshell - in jmeter variable value is not incrementing correctly in http request -


in jmeter> bean shell preprocessor wrote code increment date , date variable have passed http request. while debugging first date fetching .incremented date not passing variable

calendar cal = calendar.getinstance(); (int = 0; < 100; i++) {     cal.add(calendar.second, 1);     simpledateformat sdfdate = new simpledateformat("yyyy-mm-dd          kk:mm:ss"); //dd/mm/yyyy     date = new date();     string strdate = sdfdate.format(cal.gettime());     vars.put("timer", strdate);     log.info("date" + strdate); } 

this 'timer' variable not incrementing http request 'n' request'

your code returns one future timestamp (100 seconds ahead of current time) , saves ${timer} variable.

depending on trying achieve, there several options:

  1. change vars.put("timer", strdate); line vars.put("timer_" + i, strdate);, way following variables:

    timer_0=current time + 1 second timer_1=current time + 2 seconds ... timer_99=current time + 100 seconds 
  2. remove loop not required overwriting ${timer} variable 100 times

also aware using beanshell not best scripting option, according jmeter best practices should avoid scripting possible. instance in particular case can achieve same functionality using __time() , __longsum() functions combination. check out apache jmeter functions - introduction familiarized jmeter functions concept.

if have go scripting consider using performing language groovy (you can use jsr223 test elements)


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -