|
2#
楼主 |
发表于 2008-6-19 15:59:15
|
只看该作者
现在把我所编写的Flight按钮功能正确检测方法的代码贴在下面,纯手工编写,注释不多,大家包含一下。
'@Description 将非标准格式的日期转换成VBScript标准格式日期
'@Documentation 将非标准格式的日期转换成VBScript标准格式日期
Public Function GenerateDate(ByRef strOriginalFormatDate)
Dim retVal '返回值
retVal = Left(strOriginalFormatDate,2) & "-" & Mid (strOriginalFormatDate, 3,2) & "-" & Right(strOriginalFormatDate,2)
GenerateDate = CDate(retVal)
End Function
'@Description 获取日期所在星期数(英文格式)
Private Function GetWeekDayEn(ByRef theDate)
Select Case WeekDay(theDate)
Case 2
GetWeekDayEn = "Monday"
Case 3
GetWeekDayEn = "Tuesday"
Case 4
GetWeekDayEn = "Wednesday"
Case 5
GetWeekDayEn = "Thursday"
Case 6
GetWeekDayEn = "Friday"
Case 7
GetWeekDayEn = "Saturday"
Case 1
GetWeekDayEn = "Sunday"
end select
End Function
'判断表格中日期是否晚于当前日期
If GenerateDate(DataTable("DateOfFlight", "FlightsButtonTest")) <= Date Then
Msgbox "输入的日期不正确,执行下一条记录"
Reporter.ReportEvent micWarning, "测试数据失效", "DateOfFlight晚于当前日期"
ExitActionIteration
End If
'填写日期,出发地,目的地,并点击Flights按钮。
Window("Flight Reservation").WinObject("ctrlDateOfFlight").Type Datatable("DateOfFlight", "FlightsButtonTest")
Window("Flight Reservation").WinComboBox("cmboxFlyFrom").Select Datatable("FlyFrom", "FlightsButtonTest")
Window("Flight Reservation").WinComboBox("cmboxFlyTo").Select DataTable("FlyTo","FlightsButtonTest")
Window("Flight Reservation").WinButton("btnFLIGHT").Click
'根据Datatable中输入的数据,从数据库中查询数据。
Dim conn,appPath
appPath = Environment("roductDir") & "\samples\flight\app"
set conn = CreateObject("adodb.connection")
conn.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & appPath & "\flight32.mdb;"
Set rs = CreateObject("ADODB.RecordSet")
sqlstr = "Select * from Flights WHERE Departure = '" & Datatable("FlyFrom", "FlightsButtonTest") &_
"' and Arrival = '" & Datatable("FlyTo", "FlightsButtonTest") & "' and Day_Of_Week = '" &_
GetWeekDayEn(GenerateDate(DataTable("DateOfFlight", "FlightsButtonTest"))) & "'"
rs.Open sqlstr,conn,1,1
rs.MoveFirst
'判断Flights按钮功能的正确性。
If Window("Flight Reservation").Dialog("Flights Table").WinList("lstFrom").GetItemsCount <> rs.RecordCount Then
Reporter.ReportEvent micFail, "Flights按钮功能检测", "Flights查询所得结果不正确(记录数量不匹配)!"
else
Dim currentRow, result
currentRow = 0
'比较WinList和上面的查询结果中每行的内容是否本部相同
result = true
While rs.EOF <> true
content=rs.Fields("Flight_Number") & " " & rs.Fields("Departure_Initials") & " " & rs.Fields("Departure_Time")_
& " " & rs.Fields("Arrival_Initials") & " " & rs.Fields("Arrival_Time") & " " & rs.Fields("AirLines") & " $"_
& FormatNumber(rs.Fields("Ticket_Price"),2)
If Window("Flight Reservation").Dialog("Flights Table").WinList("lstFrom").GetItem(currentRow) <> content Then
Reporter.ReportEvent micFail, "Flights按钮功能检测", "Flights所查询结果于第" & currentRow & "行处值不正确!"
result = false
Else
Reporter.ReportEvent micPass, "Flights按钮功能检测", "Flights所查询结果于第" & currentRow & "行处值正确!"
End If
rs.MoveNext
currentRow = currentRow + 1
Wend
If result = true Then
Reporter.ReportEvent micPass, "Flights按钮功能检测", "Flights按钮功能完全正确"
Else
Reporter.ReportEvent micFail, "Flights按钮功能检测", "Flights按钮功能不正确"
End If
End If
Window("Flight Reservation").Dialog("Flights Table").WinButton("btnCancel").Click
Window("Flight Reservation").WinButton("tlbNew").Click |
|