0
点赞
收藏
分享

微信扫一扫

UFT 小飞机测试

梯梯笔记 2022-04-02 阅读 50

1.1 新建GUI测试

image-20220401233617660

image-20220401233638138

1.2 录制

点击小红点或者菜单上的录制,任选一个

image-20220401233803434

image-20220401234005633

找到小飞机的文件地址,选择小飞机(地址可以参考我的目录)

image-20220401234040626

之后就点击确定

image-20220401234655701

之后的每一步都要亲自用鼠标进行点击录制,包括下拉框的选择,选择好后点击Insert Order

image-20220401235154189

image-20220401235125278

1.3 添加录制不了的进入对象库

点击右上角的这个图标

image-20220401235403512

点击添加图标按钮,注意小飞机窗口不要关闭

image-20220401235623657

点击要录制的Total对象,它就会录制进去,之后点击添加按钮就行

image-20220401235837658

image-20220402000433094

image-20220402000602502

1.4 编写循环脚本并写入EXCEL表中

具体操作请仔细看注释

 filepath = "D:\res.xlsx"
 sheetname = "flight4a"
 
'创建EXCEL程序,打开工作簿,设置当前活动sheet
 Dim excelApp,excelBook,excelSheet
 
 '创建excel对象
 set excelApp = CreateObject("Excel.Application")
 excelApp.Visible = True 
 
 'xls的对应(工作簿)
 set excelBook = excelApp.WorkBooks.Open(filepath)
 set excelSheet = excelBook.WorkSheets(sheetname)
 
 
 ' 开始时间
 timeBegin = time()
 

'登录
Dialog("Login").WinEdit("Agent Name:").Set "Colzry"
Dialog("Login").WinEdit("Password:").SetSecure "623ab027ca2430bf064663d8fb7e936eb8bdd688"
Dialog("Login").WinButton("OK").Click

'订票
Window("Flight Reservation").WinButton("Button").Click
dateFly = date + Int((7*Rnd) + 36)
dateFlyCstr = Right("0"&Month(dateFly),2)&Right("0"&Day(dateFly),2)&right(Year(dateFly),2)
Window("Flight Reservation").ActiveX("MaskEdBox").Type dateFlyCstr

'获得所有出发地的集合
FlyFrom_Count = Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount

'用例编号
count = 0
'行的编号
row = 2

'遍历出发地
For i = 0 To FlyFrom_Count - 1 step 1
	If i > 0 Then
		Window("Flight Reservation").WinButton("Button").Click
		Window("Flight Reservation").ActiveX("MaskEdBox").Type dateFlyCstr
	End If
	'根据出发地,获取到达地的集合
	Window("Flight Reservation").WinComboBox("Fly From:").Select i
	FlyTo_Count = Window("Flight Reservation").WinComboBox("Fly To:").GetItemsCount
	
	'遍历到达地
	For j = 0 To FlyTo_Count - 1 step 1
		If j > 0 Then
			Window("Flight Reservation").WinButton("Button").Click
			dateFly = date + Int((7*Rnd) + 36)
			dateFlyCstr = Right("0"&Month(dateFly),2)&Right("0"&Day(dateFly),2)&right(Year(dateFly),2)
			Window("Flight Reservation").ActiveX("MaskEdBox").Type dateFlyCstr
			Window("Flight Reservation").WinComboBox("Fly From:").Select i
		End If
		'选择到达地,并点击确认按钮
		Window("Flight Reservation").WinComboBox("Fly To:").Select j
		Window("Flight Reservation").WinButton("FLIGHT").Click
		
		'遍历当前出发地--到达地之间的航班
		Flight_Count = Window("Flight Reservation").Dialog("Flights Table").WinList("From").GetItemsCount
		For k = 0 To Flight_Count - 1 step 1
			If k > 0 Then
				Window("Flight Reservation").WinButton("Button").Click
				Window("Flight Reservation").ActiveX("MaskEdBox").Type dateFlyCstr
				Window("Flight Reservation").WinComboBox("Fly From:").Select i
				Window("Flight Reservation").WinComboBox("Fly To:").Select j
				Window("Flight Reservation").WinButton("FLIGHT").Click
			   '代码End	
			End If			   
		    '选择当前航班			
		    Window("Flight Reservation").Dialog("Flights Table" ).WinList("From").Select k
			excelSheet.Cells(row,5).Value = Window("Flight Reservation").Dialog("Flights Table").WinList("From").GetSelection()		    
		    Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
		   
		    '设置订票人
		    orderMan = "Colzry-"&(Int(36*Rnd))
		    Window("Flight Reservation").WinEdit("Name:").Set(orderMan)
		 
		    '生成票数的随机值   产生1 - 6的随机票数'
			'Window("Flight Reservation").WinEdit("Tickets:").SetSelection 0,1
			tickets = Int((6 * Rnd ) + 1)
			Window("Flight Reservation").WinEdit("Tickets:").Set tickets
			
			' 产生1 - 3的随机数'
			num = Int((3 * Rnd) + 1)
			Select Case num
			'选择舱位   头等舱'
				Case 1
				Window("Flight Reservation").WinRadioButton("First").Set
				classFight = "First"
				'商务舱'
				Case 2
				Window("Flight Reservation").WinRadioButton("Business").Set
				classFight = "Business"
				'经济舱'
				Case 3
				Window("Flight Reservation").WinRadioButton("Economy").Set
				classFight = "Economy"
			End Select
			
			excelSheet.Cells(row,1).Value = "Flight4a-"& count+1
			excelSheet.Cells(row,2).Value = right(Year(dateFly),2)&"/"&Right("0"&Month(dateFly),2)&"/"&Right("0"&Day(dateFly),2)
			excelSheet.Cells(row,3).Value = Window("Flight Reservation").WinComboBox("Fly From:").GetSelection()
			excelSheet.Cells(row,4).Value = Window("Flight Reservation").WinComboBox("Fly To:").GetSelection()
			excelSheet.Cells(row,6).Value = orderMan
			excelSheet.Cells(row,7).Value = tickets
			excelSheet.Cells(row,8).Value = classFight
			excelSheet.Cells(row,9).Value = Window("Flight Reservation").WinEdit("Total:").GetVisibleText
			
			
             '生成订单,不想插入数据库,插入太慢了,直接否了
            'Window("Flight Reservation").WinButton("Insert Order").Click
            Window("Flight Reservation").WinButton("Button").Click
			Window("Flight Reservation").Dialog("Flight Reservations").WinButton("否(N)").Click

            count = count + 1
            row = row + 1
		Next
	Next
Next

' 结束时间
timeEnd = time()
' 运行时间
timeDural = DateDiff("n", Trim(timeBegin), Trim(timeEnd))

count = count + 2
excelSheet.cells(count, 2).Value = "开始时间:"&timeBegin
excelSheet.cells(count, 4).Value = "结束时间:"&timeEnd
excelSheet.cells(count, 5).Value = "程序一共运行:"&timeDural&" 分钟"
 
 ' 关闭表格并保存
excelApp.DisplayAlerts=False 
excelSheet.SaveAs ("D:\res.xlsx")
excelBook.Close(True)  
excelApp.Quit 
Set  excelSheet = Nothing 
Set excelBook = Nothing  
Set excelApp = Nothing
举报

相关推荐

0 条评论