Forum Discussion
13 Replies
- JennyH11Frequent Contributor
Thanks for the replies.
I think I might understand this a bit better now..
We use this spreadsheet for entering dates in the UI of the AUT. The dates are calculated by formulas in the spreadsheet, therefore, without opening the spreadsheet first the dates cannot be calculated. If the spreadsheet is not opened first the test will input the dates as stored at the last time of opening the spreadsheet.
With this in mind, I'm not sure there is a way to use this spreadsheet without opening it first. A quick google suggests that there is no way to update the data in a spreadsheet without opening it first but maybe there is a way to use the data without opening that allows TestComplete to access it?
Any thoughts? Ideas?
- tristaanogreEsteemed Contributor
What are the date forumulas used by the spreadsheet? You could, rather than pulling the dates from the sheet, use various aqDateTime functions to generate the required dates and aqConvert.DateTimeToFormatStr to format the resulting date into the desired string format. Might be a LOT easier than having to open and close the spreadsheet each time.
- cunderwCommunity Hero
I would second tristaanogre, if you are just needing calculated dates for input, using a built in / more native way of date manipulation would be a much better solution.
- cunderwCommunity Hero
No, this should not be needed. See https://support.smartbear.com/testcomplete/docs/testing-with/data-driven/excel-storages.html
- tristaanogreEsteemed Contributor
The only reason why your tasks may need to be running as they are would be if you need to write to the Excel file... but if all you're doing is reading, then you shouldn't need those opening steps.
- JennyH11Frequent Contributor
Some examples of the dates we're calculating are: Today, Today +1, Today + 2 weeks, Next Monday, Next April, Next Monday.
If we can do this in TestComplete that would be great.
Thanks!
- cunderwCommunity Hero
That can absolutely be done in Test Complete with aqDateTime and the addTime method.
https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/index.html
function ChangingTime() { var Time1, Time2, Time3, Time4, Time5, Time6, Time7; Time1 = aqDateTime.Now(); Time2 = aqDateTime.AddDays(Time1, 5); Time3 = aqDateTime.AddHours(Time1, 7); Time4 = aqDateTime.AddMinutes(Time1, 24); Time5 = aqDateTime.AddMonths(Time1, 2); Time6 = aqDateTime.AddSeconds(Time1, 15); Time7 = aqDateTime.AddTime(Time1, 9, 3, 24, 51); Log.Message(aqConvert.DateTimeToStr(Time1)); Log.Message(aqConvert.DateTimeToStr(Time2)); Log.Message(aqConvert.DateTimeToStr(Time3)); Log.Message(aqConvert.DateTimeToStr(Time4)); Log.Message(aqConvert.DateTimeToStr(Time5)); Log.Message(aqConvert.DateTimeToStr(Time6)); Log.Message(aqConvert.DateTimeToStr(Time7)); }
- tristaanogreEsteemed Contributor
Today -> aqConvert.DateTimeToFormatStr(aqDateTime.Today(), '%m/%d/%y') -> '06/12/2018'
Today + 1 -> aqConvert.DateTimetoFormatStr(aqDateTime.AddDays(aqDateTime.Today(), 1), '%m/%d%Y') -> '06/13/2018'
Today + 2 -> aqConvert.DateTimetoFormatStr(aqDateTime.AddDays(aqDateTime.Today(), 2), '%m/%d%Y') -> '06/14/2018'
Getting "next Monday" or "next April" is going to be a bit trickier... I'm sure I could work it out given the time... I'm guessing that it will take some sort of switch statement to take the current date, determine day of week, and then depending on that result do another "AddDays" to get the following Monday... same thing with Month to get the current month, calculate then how many months to add and use aqDateTime.AddMonths to get to the "next April" date.
But yes... it should be possible to use aqDateTime methods (https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/methods.html) to do exactly what you want without needing the spreadsheet to do the calculations
- AdamUKOccasional Contributor
I've used Excel spreadsheets in my test easily enough, you create a variable and map it to the spreadsheet. But that was only for data driven testing where it would use a different / the next row for each iteration of the loop.
But yeah, don't see why you couldn't just call today and then add a unit per loop. Not sure of the code but should be fairly easy to find.
- JennyH11Frequent Contributor
Thanks everyone for the responses on this.
I'll look into it a bit more & try it out. The information you've given is amazingly helpful! Thank you :)
- JennyH11Frequent ContributorI'm struggling with getting a spreadsheet \ variable working so thought it might be a good time to give this a go.One issue though - and this might be a really silly question - how do I tell the keyword test to enter the date calculated by the aqdatetime \ aqconvert methods? I'd assume it's using Keys or SetText at some point but am not sure how to do this.I'm starting off small with trying to do today + 1. Also, what should the "Input Date" be if I want it to be dynamic & adjust to whatever "today" is depending when the test is run.Thanks,Jenny
- tristaanogreEsteemed Contributor
The Keys or SetText method has a parameter that is the value to be entered.
When you edit that operation, you have an option to select the "Mode" for that parameter. Set it to "Code Expression". This way, you can enter a short bit of code that will be evaluated and then entered using the method.
You want to enter today's date + 1. That would be as follows:
aqConvert.DateTimeToFormatStr(aqDateTime.AddDays(aqDateTime.Today(), 1), '%m/%d/%Y')
Relevant help topics:
https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/adddays.html
https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/today.html
- JennyH11Frequent Contributor
Thank you very much Robert!
For info I couldn't get it to enter correctly at first as the field I'm entering into has a hard coded / in between the m & y, so once I removed those from what you gave me it entered perfectly!
It looked like this: aqConvert.DateTimeToFormatStr(aqDateTime.AddDays(aqDateTime.Today(), 1), '%m%d%Y')
Thank you very much again, as always you have been very helpful!