5

For a certain date (this is a hard coded date), I want to increment through the time for LastModifiedTimeFrom and LastModifiedTimeTo by 10 minutes each time.

I have tried the below but it is not performing the increment and I am not sure why?

Date d = Date.parse("HH:mm:ss", "00:00:00")
Calendar c = Calendar.getInstance()
c.setTime(d)

c.add(MINUTE, 10)
assert c.time == "00:10:00"

c.add(MINUTE, 10)
assert c.time == "00:20:00"

c.add(MINUTE, 10)
assert c.time == "00:30:00"
BruceyBandit
  • 3,978
  • 19
  • 72
  • 144
  • check this out and see - http://mrhaki.blogspot.in/2009/09/groovy-goodness-date-and-time-durations.html – Rao Feb 03 '17 at 10:19
  • What is your use case? not clear from the question. – Rao Feb 03 '17 at 10:52
  • @Rao - hi Rao, so virtually we are testing an interface to ensure it completes searches of bookings witihin given time frames which are the lastmodfieldtimefrom and to. We are incrementing in 10 minutes values so for one test it will perform what you see above but then when it hits the loop test, it will add 10 minutes on both times add run the test again automatically. It will continue to do this until we hit the final specified time. Simply its one click and it loops through all the steps to fill in all the times in 10 minute increments – BruceyBandit Feb 03 '17 at 11:00
  • I was trying time category before but was getting error null+null when tries to include 10 minutes increment for both from and to time. Proably the way I have implemented it is incorrect – BruceyBandit Feb 03 '17 at 11:02
  • Can you what you tried with category? also you should be to get 10 min in the script without having to store in the properties, right? Could not get you. – Rao Feb 03 '17 at 12:03
  • I'll see if i can figure it out and if not will explain it better to you – BruceyBandit Feb 03 '17 at 13:15
  • Looks like I will need help with this one Rao. Can you show me the way you'll implement it please. – BruceyBandit Feb 07 '17 at 06:27
  • Can show some screen shot how actually the times is used? I could not imagine where 10 min delay is required. Is the test step should wait for such time? test case structure. By the way, you haven't replied on other question too regarding endpoint? – Rao Feb 07 '17 at 06:35
  • do you execute the test in loop? I mean a data driven test? Also request you to update the earlier comments too. – Rao Feb 07 '17 at 15:05
  • @Rao - Yes that's correct, this is a data driven test where it is executed in a loop. Previously i had 4 steps - 'Read Data' which reads a CSV file and starts on the first row, 'Set properties' would take out the values from the given row, 'Get bookings' would perform the request and then 'Conclude Test' is the looping where it will check if the csv file is on the last row, if not then move to next row and loop back to 'Set properties' and it will go again... – BruceyBandit Feb 08 '17 at 06:25
  • ...Now I don't need to put the time in CSV file as It would make more sense to hard code the time and then increment by 10 minutes per loop until it hits the criteria I mentioned in my question. I updated the question so you can see how it currently with the CSV – BruceyBandit Feb 08 '17 at 06:25
  • For the other question in regards to endpoints, we have decided to instead just show all the url endpoint of the steps per test case instead in the report. So it's pretty much grab all the rest request test step names and their endpoints per test case. Will this be possible to select rest request test steps in general and can you update your answer accordingly to match please? – BruceyBandit Feb 08 '17 at 06:35
  • 1
    This is a very confused question. Can't you state in one sentence what your core issue or goal is? Do you want to wait ten minutes in real time? Or do you just want to inclement a date-time value by ten minutes repeatedly? One of the points of confusion: You state you want to increment by ten minutes between the "from" and "to" times, yet your example data, "00:00:00" & "00:10:00", shows only ten minutes delta between them, so there is only one increment possible. – Basil Bourque Feb 09 '17 at 03:58
  • @Basil I want to increment a date-time value by ten minutes per loop of my test case steps (Test case steps goes - Set Properties > Request > Conclude Test (these are the name of my steps and the code for each step is above) and stop at the given criteria.Like I said I doen't want to call from a csv file anymore and start from a fixed hard coded value – BruceyBandit Feb 09 '17 at 06:55
  • @BruceyBandit, can show how the request consumes the dates? what is the date format required? – Rao Feb 10 '17 at 01:55
  • The format for the dates is yyyyMMdd so like 20160724 when it is entered in the request. – BruceyBandit Feb 10 '17 at 11:13
  • If that is the case where is the need for 10 min interval? Do not you need the time to seconds precision in the request? – Rao Feb 12 '17 at 03:48
  • @Rao The need for 10 minute increments is because we had a bug previously where if we look for bookings within a 10 minute timeframe, it threw an exception error. That's why we specifically check for time ranges in a range of 10 minutes for the whole day. – BruceyBandit Feb 12 '17 at 19:18
  • Do you send the same date in the request again and again? Very confusing. – Rao Feb 13 '17 at 08:08
  • Yes it is the same date but different times by 10 minute range. – BruceyBandit Feb 13 '17 at 10:27

1 Answers1

2

I would recommend a combo approach of using some Groovy syntactic sugar and the verbose, but ever-reliable Java Calendar. With the code below, you should be able to parse in a date and start adding 10 minutes to it, checking it as you go along.

import java.util.Calendar
import static java.util.Calendar.*

Date d = Date.parse("HH:mm:ss", "00:00:00")
Calendar c = Calendar.getInstance()
c.setTime(d)

c.add(MINUTE, 10)
assert c.time.format("HH:mm:ss") == "00:10:00"

c.add(MINUTE, 10)
assert c.time.format("HH:mm:ss") == "00:20:00"

c.add(MINUTE, 10)
assert c.time.format("HH:mm:ss") == "00:30:00"
rockympls
  • 321
  • 2
  • 3
  • does that mean though I have to make a huge list of 10 minute increment? – BruceyBandit Feb 09 '17 at 06:50
  • My thinking was that you could do the c.add(MINUTE, 10) as part of a loop, terminated by the condition you mentioned above (it becomes 00:00:00 or exceeds a certain threshold) – rockympls Feb 09 '17 at 15:09
  • Ok, I get your logic in theory, is it ok if you provide the full implementation so I can apply it to mine to test and can see how it works for future reference? – BruceyBandit Feb 09 '17 at 21:26