Reputation: 25
I have two time values captured via Regular Expressions. They are of the format given below:
Stop_Time Start_Time
11:05 11:08
11:05 11:08
Now, the difference between these values are to be calculated and written to a file. I need to present the file in a below fashion:
Stop_Time Start_Time Duration
11:05 11:08 3 mins
11:05 11:08 3 mins
Please help.
Regards, Ajith
Upvotes: 0
Views: 917
Reputation: 168082
You can calculate the difference and store the result into a JMeter Variable using the following Groovy code:
def sdf = new java.text.SimpleDateFormat('HH:mm', Locale.ENGLISH)
def start = sdf.parse(vars.get('Start_Time'))
def end = sdf.parse(vars.get('Stop_Time'))
def delta = (end.getTime() - start.getTime()) / 1000 / 60
vars.put('Duration', delta as String)
Demo:
Then you can add the next line to user.properties file:
sample_variables=Start_Time,Stop_Time,Duration
this way the variable values will be added to the .jtl results file. If you want to store the values in a separate file - take a look at Flexible File Writer
More information: Sample Variables
Upvotes: 1