Forum Discussion
28 Replies
- nmrao
Champion Level 1
What format? - avidCoderSuper Contributor
Hi Preeti,
I couldn't understand your use cases. How do you want to proceed after the date increment. This is what you can try. Download joda-time and put inside home/SmartBear/bin/ext folder. Restart ReadyAPI and then use this code:-
import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import javax.swing.text.html.HTML.Tag; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.ISODateTimeFormat; /*First figure out how many times you need to execute this. I have taken count as 5. You can set limit of the date creation based on the flag a/c to your choice. This will generate the date for next 5 days.*/ for(int i=0; i<5; i++) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); DateTimeFormatter parser = ISODateTimeFormat.date(); DateTime dt = parser.parseDateTime(dateFormat.format(date)); String nextDay = parser.print(dt.plusDays(i)); System.out.println(nextDay); //Store nextDay to testCase Property. testRunner.testCase.setPropertyValue("Date", nextDay); //Now in XML pass "Date" inside this tag - <Value>${#TestCase#Date}</value> //Then run the XML file, to generate the response based on the "Date" you provided in <Value> Tag. def tCase = testRunner.testCase.testSuite.testCases["Your testCase Name"] def tStep = tCase.testSteps["Your testStep name"] tStep.run(testRunner, context) }
Just try once, and let me know, if you face any issue.
Regards,
AvidCoder.
- Nancy2Occasional Contributor
From all the replies what I understood is that use case is not very clear. Let me explain my use case. However, I'll try all the given solutions and let you know my observation-
My application has a function that in one day only one record can be added in an account.
For e.g. I can rent a hotel but I cannot post same activity same day means I cannot rent same hotel same day two times. So, this validation message display "Duplicate activity on same day"
In my web method, I pass all other input parameters along with date using below syntax
(${=(new Date().format('yyyy-MM-dd'))}).
So first time when I run my test case, syntax works fine as it picks up today's date but running same test case same day will fail and give message as "Duplicate activity on same day" due to same date.
My requirement is to pass different date each time when I execute the test case.
Let me know if still more explianation is required for my use case.
Regards
- nmrao
Champion Level 1
Nancy2 ,
In your test case, place below a Groovy Script test step before the Request test step, so that it can generate the next date and also remembers the same for next time not to generate the duplicate date.
And in the request, use <element>${#TestCase#NEW_DATE}</element>
Here is the text of the above script
https://github.com/nmrao/soapUIGroovyScripts/blob/master/groovy/date/CreateNewDate.groovy
Doesn't require any additional libraries.