'JMeter timeshift issue

I've been working with timeshift, but it seems that timeshift does not do what I expect it should do. When I input a DateTime into TimeShift to work with it always uses the Current DateTime, but when I only input the Date it works?

long timeStamp = ${__timeShift(,,P2D,,)};
${__timeShift(yyyy-MM-dd'T'hh:mm:ss'Z',,P2D,,timeStampFrom)};
log.info("timeStamp: " + timeStamp);
log.info("timeStampFrom: " + ${timeStampFrom});

long timeStampTo = ${__timeShift(,${timeStampFrom},P2H,,)};
log.info("timeStamp: " + timeStampTo);

The function is called timeShift, but why doesn't let it me work with the datetime I input in?

Thanks

UPDATE:

JSR223 Sampler

BeanShell Sampler

I've been playing around with it... and yes when you are using it in the header of the JSR223 Sampler it works great. The moment you use the same code inside Sampler it doesn't... It always goes wrong with the following message:

Time Stamp Issue

Another update:

So when using this in the User Defined Variables:

User Defined Variables

This works without any issues, but using it in Groovy itself it doesn't work at all... getting errors. Using it in the name of a sampler works also outstanding. From my point of view it is an issue in the way how jMeter works.



Solution 1:[1]

  1. Don't inline JMeter Functions or Variables into Groovy scripts, either use "Parameters" section for this.

  2. There is one more thing connected with using functions and variables in Groovy scripts: they're being compiled and cached hence if you run your test with 2 or more iterations only first value will be used everywhere.

  3. Correct expression for adding 2 hours is PT2H

  4. And last but not the least, your code is not a valid Groovy code so it won't compile, you can check jmeter.log file yourself and you will see the error.

Assuming all above I don't think you need any Groovy scripting at all, you can do everything using JMeter's built-in test elements as functions can be used anywhere in the script:

enter image description here

More information on JMeter Functions concept: Apache JMeter Functions - An Introduction

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dmitri T