0
votes

I am scripting for a scenario where I have to book slots for an appointment and the slots are of 15 minutes duration. Suppose if I want to book an appointment from 17:00 to 17:15, then the requests in jmeter comes like this->

StartHour-17 StartMIn-00 EndHour-17 EndMinute-15

The slots can be selected by using csv config but I want to automate using beanshell/groovy in jmeter because csv is time taking while preparing test data. So is it possible to write in beanshell so that every iteration the slots get automatically incremented by 15 minutes ie the next slot that would be selected is 17:15-17:30 and the request in jmeter would be: StartHour-17 StartMIn-15 EndHour-17 EndMinute-30

I tried in beanshell but unable to get the desired results as the requests are taking in terms of start hour start min end hour and end minute.

2
You say 15 minute increments but all of your examples are 30 minute increments.doelleri
Sorry it's increment of 15 minutes ie StartTime-17:00 StartMin-17:15 EndHour-17:00 EndMin-17:30. Sorry for the inconvenience..manmaya swain

2 Answers

0
votes

In Groovy you can use TimeCategory API in order to manipulate date and time.

Example code to add 15 minutes to current time would be something like:

def now = new Date()
log.info('Before: ' + now.format('HH:mm'))
use(groovy.time.TimeCategory) {
    def nowPlus15Mins = now + 15.minutes
    log.info('After: ' + nowPlus15Mins.format('HH:mm'))
}

JMeter Groovy add 15 minutes to current time

You can access previous value(s) from JMeter Variables and store result into them using vars shorthand which stands for JMeterVariables class instance and provides read/write access to all JMeter Variables.

See Apache Groovy - Why and How You Should Use It for more details on using Groovy scripting in JMeter.

0
votes

You can do something like this:

def startDate = new Date()
startDate.set(hourOfDay: 17, minute: 0)
use (groovy.time.TimeCategory) {
    5.times {
        def start = startDate.format("'StartHour-'HH' StartMin-'mm")
        def endDate = startDate + 15.minutes
        def end = endDate.format("'EndHour-'HH' EndMin-'mm")
        println "$start $end"
        startDate = endDate
    }
}

which gives you:

StartHour-17 StartMin-00 EndHour-17 EndMin-15
StartHour-17 StartMin-15 EndHour-17 EndMin-30
StartHour-17 StartMin-30 EndHour-17 EndMin-45
StartHour-17 StartMin-45 EndHour-18 EndMin-00
StartHour-18 StartMin-00 EndHour-18 EndMin-15