All about Dates using QTP
Majority of applications have Calendars controls. Automating a calendar can be painful at times if the textbox is disabled, and it only works if you select the date from the calendar widget provided on your website/application.
I have been working on date controls for couple of months so thought about sharing all the findings with you people. So here i am summarizing some of the checks which can be handy working on date/Calendar controls.
''''''''''''Compare start and End date
I have been working on date controls for couple of months so thought about sharing all the findings with you people. So here i am summarizing some of the checks which can be handy working on date/Calendar controls.
''''''''''''Compare start and End date
For comparing end date validation, set today's date using Date function in start date textbox and set previous date in end date, and check if the validation is fired.
'''''startdate - set as todays date using 'date'
Browser("").Page("").WebEdit("").Set Date
'''''End date, set prev 5 days date
Browser("").Page("").WebEdit("").Set DateAdd("d",-5,Date)
Browser("").Page("").Image("").Click
'''''Check for validation occurrence
If (Browser("").Page("").WebElement("").Exist(1)) then
Print "Validation checked for End date must be after start date"
Reporter.ReportEvent micPass,"Found validation End date must be after start date",""
Browser("").Page("").WebEdit("").Set Date
'''''End date, set prev 5 days date
Browser("").Page("").WebEdit("").Set DateAdd("d",-5,Date)
Browser("").Page("").Image("").Click
'''''Check for validation occurrence
If (Browser("").Page("").WebElement("").Exist(1)) then
Print "Validation checked for End date must be after start date"
Reporter.ReportEvent micPass,"Found validation End date must be after start date",""
else
Print "Missing Validation for End date must be after start date"
Reporter.ReportEvent micFail,"Missing validation End date must be after start date",""
End If
''''''''''''Set date + time in date textbox
Print "Missing Validation for End date must be after start date"
Reporter.ReportEvent micFail,"Missing validation End date must be after start date",""
End If
''''''''''''Set date + time in date textbox
Add time along with the date by using the Now property of date, and see if the validation for invalid input has been placed.
Browser("").Page("").WebEdit("").Set DateAdd("m",-1,Now)
If (Browser("").Page("").WebElement("").Exist(1)) then
Print "Checked Invalid Date Validation"
else
Reporter.ReportEvent micFail,"Missing Invalid Date Validation",""
End If
''''''''''''Checking date format 0M / 0D / Year
''''''''''''Checking date format 0M / 0D / Year
To provide date in mm dd yyyy format use the code below. You can use your desired format for date separator. For example in the code below i have concatenated '/' with my date so the date that will be set in the date textbox will be "12/29/2011". you can use '-' or '.' or whatever your allowed input is.
''''''Gives 10 days previous date in two-digit day of month.
prev= right("0" &day(Date -10),2)
'''''Gives today's date in two-digit day of month.
cur= right("0" & day(Date()),2)
'''''Gives two-digit month.
m= right("0" & month(date()),2)
''''''Gives four digit year.
y= year(date())
Browser("").Page("").WebEdit("StartDate").Set m & "/" & prev & "/" &y'DateAdd ("d",-10,date)
Browser("").Page("").WebEdit("EndDate").Set m & "/" & cur & "/" &y
''''''''''''Add Weekday in date textfields
To add week's day with your date, use the function FormatDateTime. So when you will run your code it will pace "Thursday, December 29, 2011" in the date texbox.
Browser("").Page("").WebEdit("StartDate").Set FormatDateTime (date, 1)
Browser("").Page("").WebEdit("EndDate").Set FormatDateTime (date, 1)
Browser("").Page("").Image("").Click
''''''Assign variable for validation of date1, date2 and comparision
set reqval1= Browser("").Page("").WebElement("revDate")
set reqval2= Browser("").Page("").WebElement("revDate2")
set cmpval=Browser("").Page("").WebElement("cmpvDate")
If ((reqval1.Exist(1) and (reqval2.Exist(1) and (cmpval.Exist(1)))) = true) Then
set reqval2= Browser("").Page("").WebElement("revDate2")
set cmpval=Browser("").Page("").WebElement("cmpvDate")
If ((reqval1.Exist(1) and (reqval2.Exist(1) and (cmpval.Exist(1)))) = true) Then
Print "Found Date comparision validations all Working"
else
Print "Not Found all date comparision validations not working"
End If
''''''''''''Setting prev date
else
Print "Not Found all date comparision validations not working"
End If
''''''''''''Setting prev date
To set previous date use DateAdd function. Replace "d" ,"date" with "m" for month or "y" for year. Providing minus (-) sign will instruct QTP to subtract 10 days from today's date.
Browser("").Page("").WebEdit("StartDate").Set DateAdd("d",-10,date)
''''''''''''Setting date in disabled textbox
So the interesting part, to provide date in a disabled textbox use the object.innerText method we can set a date in a disabled textbox.
Browser("").Page("").WebEdit("").object.innerText = date
So that is all from my side, will update the thread if i came across some more date validation.
Beautiful, really helpful, thanks for posting
ReplyDelete"''''''''''''Setting date in disabled textbox" solved my big problem of multiple clicking to set the date.Thanks for sharing
ReplyDeletethank youuuuuuuuuuuuuuuuuuuuuuuuuuu
ReplyDelete