Using QTP DataTable to Generate a Date Value

837 views
Skip to first unread message

qtpaut...@gmail.com

unread,
Apr 2, 2007, 12:55:23 AM4/2/07
to QTP AUTOMATION

Problem:
Need to generate a current date in a specific format and pass the date
to the application date field.
Solution One - Date String has no Special Characters:
Use the QTP DataTable to generate the date value and pass the date to
the application date field.

Option A - Pass myDateToday to the application date field:
'In Global Data Sheet create column "dateToday" with cell value
=text(today(),"ddmmmyy") to generate the current system date in the
same format as the application that is being tested (i.e. string
"11Apr03).

Dim myDateToday
myDateToday = DataTable ("dateToday", dtGlobalSheet)

'Pass myDateToday to the application date field.
JavaWindow("TIMI010 - MATERIAL").JavaList("ICDateField").Select
myDateToday

Option B - Pass DataTable ("dateToday", dtGlobalSheet) to the
application date field:
In Global Data Sheet create column "dateToday" with cell value
=text(today(),"ddmmmyy") to generate the current system date in the
same format as the application that is being tested (i.e. string
"11Apr03).

'Pass DataTable ("dateToday", dtGlobalSheet) to the application date
field.
JavaWindow("TIMI010 - MATERIAL").JavaList("ICDateField").Select
DataTable ("dateToday", dtGlobalSheet)

Extension:
To set the date forward (e.g. add 10 days) simply modify the DataTable
cell value:
Column "dateToday" = text(today() + 10,"ddmmmyy")

Solution Two - Date String includes Special Characters:
The date string that is passed from QTP to the application is "mm/dd/
yy" (e.g. "04/11/03"); however, a run error occurs, as this string
includes the special character '/', which may not be a valid method
argument. Use the QTP DataTable to generate separate date value
components for month, day and year, concatenate these date components
with literalized forward slashes and pass the date to the application
date field as a string.

In Global DataTable create:
· Column "mm" with cell value =text(today(),"mm") to generate the
current system date month.
· Column "dd" with cell value =text(today(),"dd") to generate the
current system date day.
· Column "yy" with cell value =text(today(),"yy") to generate the
current system date year.

Dim myDateToday
myDateToday = DataTable ("mm", dtGlobalSheet) & "\/" & DataTable
("dd", dtGlobalSheet) & "\/" & DataTable ("yy", dtGlobalSheet)
'Pass myDateToday to the application date field.
JavaWindow("TIMI010 - MATERIAL").JavaList("ICDateField").Select
myToday

'To check the run time date value use msgbox.
msgbox myDateToday
'This will display "04\/11\/03" which is a date string with
literalized forward slashes

Note: adding '\' to a DataTable cell function (e.g. Column "dateToday"
= text(today(),"dd\/mm\/yy")) does not literalize the special
characters when passing the date string to the test application. The
string that is passed would be "mm/dd/yy" (e.g. "04/11/03"), which
would include invalid method arguments '/'.

Extension:
To set the date forward (e.g. add 10 days) simply modify the DataTable
date components for cell values:
· Column "mm" with cell value =text(today() + 10,"mm") to generate the
current system date month; compensated for the additional 10 days.
· Column "dd" with cell value =text(today() + 10,"dd") to generate the
current system date day; compensated for the additional 10 days.
· Column "yy" with cell value =text(today()+ 10,"yy") to generate the
current system date year; compensated for the additional 10 days.

Note: the date adjustment must be applied equally to all date
components.

Reply all
Reply to author
Forward
0 new messages