Jmeter - timestamp of the future

im trying to create a parameter in Jmeter that gives the current timestamp + 5 minutes. Does anyone know how to do this? To create the current timestamp, I have the following: $ {__ time (HH: mm: ss, TIMESTAMP)}

+4
source share
4 answers

I am afraid that the __ time () function does not provide sufficient flexibility. You will need to calculate this date value through a Beanshell Sampler or a Beanshell Preprocessor

The corresponding Beanshell code will look like

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

Date now = new Date(); // get current time
Calendar c = Calendar.getInstance(); // get Java Calendar instance
c.setTime(now); // set Calendar time to now
c.add(Calendar.MINUTE, 5); // add 5 minutes to current time
Date now_plus_5_minutes = c.getTime(); // get Date value for amended time
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); // create a formatter for date       
String mydate = sdf.format(now_plus_5_minutes); // format date as string
vars.put("mydate",mydate); // save date to JMeter variable named "mydate"

You can specify this value mydateas

  • $ {MyDate}
  • $ {__ In (MyDate)}

At this point you will need to provide an updated date.

, .

+9

, :

    import java.text.SimpleDateFormat; 
    import java.util.Date; 

    Date date = new Date(); 
    date.setDate(date.getDate()+5); 
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); 
    // or: SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy"); 
    String formattedDate = df.format(date); 
    vars.put("myFutureDate",formattedDate); 

BeanShellPreprocessor: enter image description here

-

${myFutureDate} 
+5

__javaScript http://jmeter.apache.org/usermanual/functions.html#__javaScript. .

${__javaScript( Math.floor( ( Date.now() + ( 5 * 60 * 1000 ) ) / 1000 ) )}

Using __javaScript as parameter

JMeter Test JMX

+4

, :

${__groovy(use(groovy.time.TimeCategory) { (new Date() + 5.minutes).format('yyyyMMddHHmmssSSS') })}

Groovy TimeCategory http://docs.groovy-lang.org/latest/html/api/groovy/time/TimeCategory.html (, 5.minutes 1.day ).

, , - ( JMeter script).

JavaScript JMeter: http://jmeter.apache.org/usermanual/functions.html#__javaScript

Groovy ( TimeCategory) .

JMeter 3.2

0

Source: https://habr.com/ru/post/1527438/


All Articles