how to increment date for each test run
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
how to increment date for each test run
Hi,
In my test step I need to pass new date in each test run. How can I do that?
Regards,
Preeti
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
YYYY-MM-DD
e.g. 2019-02-09
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
new Date().format('yyyy-MM-dd')
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is not working as I can give direct date in the <Value> tag
e.g.
<Value><2019-02-02></value>
For below, getting error- String was not recognized as a valid DateTime.
<Value>${=(new Date().format("yyy-MM-dd")}</Value>
Requirement is originally I am giving date as <2019-02-02> and for the second time date should be passed as <2019-02-03> and so on..
Regards
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
${= new Date().format('yyyy-MM-dd HH-mm-ss')}
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Nancy2
I think you're missing a parenthesis character and a 'y' character in the string
I use the following
${=(new Date().format('dd-MM-yyyy'))}
you are using
${=(new Date().format("yyy-MM-dd")}
I don't know if wrapping the format pattern value in double quote marks makes a difference - but as I say - the above that I use works all the time,
you want dates in the format '2019-02-02', so I think the string you want is as follows:
${=(new Date().format('yyyy-MM-dd'))}
hope I've been clear - I tend to ramble!
Cheers,
richie
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
