UFT12(QTP)自动化测试 -相关练习


结构化:

Dim str,i
i=4
str=”123″
do while isystemutil.Run “D:Downloadflightappflight4b.exe”
str=str&i
Dialog(“Login”).WinEdit(“Agent Name:”).Set str
wait 1
Dialog(“Login”).WinEdit(“Password:”).SetSecure “5b081dd06174ee3f2423c425a337715e7796b92f”     ‘密码:mercury
Dialog(“Login”).WinButton(“OK”).Click
Window(“Flight Reservation_2”).Close
i=i+1
loop

2、使用结构化脚本订购明天、后天、大后天的机票,随机地点、时间随机

Dim i,v_date,v_year,v_month,v_day,str,count,v_rnd
str=””
For i = 1 To 3

msgbox i
v_date=date+1

v_year=mid(year(v_date),3)
 
v_month=month(v_date)
If v_month v_month=”0″&v_month
End If

    v_day=day(v_date)
If v_day v_day=”0″&v_day
End If


str=v_month&v_day&v_year
msgbox str
    wait 1
   
Window(“Flight Reservation”).ActiveX(“MaskEdBox”).Type str

count=Window(“Flight Reservation”).WinComboBox(“Fly From:”).getitemscount
v_rnd=randomnumber.Value(0,count)
Window(“Flight Reservation”).WinComboBox(“Fly From:”).Select v_rnd

count=Window(“Flight Reservation”).WinComboBox(“Fly To:”).getitemscount
v_rnd=randomnumber.Value(0,count)
Window(“Flight Reservation”).WinComboBox(“Fly To:”).Select v_rnd

Window(“Flight Reservation”).WinButton(“FLIGHT”).Click
Window(“Flight Reservation”).Dialog(“Flights Table”).WinButton(“OK”).Click
Window(“Flight Reservation”).WinEdit(“Name:”).Set i
Window(“Flight Reservation”).WinButton(“Insert Order”).Click
Window(“Flight Reservation”).WinMenu(“Menu”).Select “File;New Order”     

Next

3、在上一题的基础,每天添加订购人,订购人为Jim,LiLy,Lucy每人各2、3、4张票

Dim i,v_date,v_year,v_month,v_day,str,count,v_rnd,v_name
str=””
For i = 2 To 4

msgbox i
v_date=date+1

v_year=mid(year(v_date),3)
 
v_month=month(v_date)
If v_month v_month=”0″&v_month
End If

    v_day=day(v_date)
If v_day v_day=”0″&v_day
End If


str=v_month&v_day&v_year
msgbox str
    wait 1
   
Window(“Flight Reservation”).ActiveX(“MaskEdBox”).Type str

count=Window(“Flight Reservation”).WinComboBox(“Fly From:”).getitemscount
v_rnd=randomnumber.Value(0,count)
Window(“Flight Reservation”).WinComboBox(“Fly From:”).Select v_rnd

count=Window(“Flight Reservation”).WinComboBox(“Fly To:”).getitemscount
v_rnd=randomnumber.Value(0,count)
Window(“Flight Reservation”).WinComboBox(“Fly To:”).Select v_rnd

Window(“Flight Reservation”).WinButton(“FLIGHT”).Click
Window(“Flight Reservation”).Dialog(“Flights Table”).WinButton(“OK”).Click

select case(i)
Case 2
 v_name=”Jim”
Case 3
 v_name=”LiLy”
Case 4
 v_name=”Lucy”
Case else
 v_name=”other”
End select 

Window(“Flight Reservation”).WinEdit(“Name:”).Set v_name

    Window(“Flight Reservation”).WinEdit(“Tickets:”).Set i

Window(“Flight Reservation”).WinButton(“Insert Order”).Click
Window(“Flight Reservation”).WinMenu(“Menu”).Select “File;New Order”     

Next

4、在上一题的基础上,添加分别购买头等舱、经济舱、商务舱

Dim i,v_date,v_year,v_month,v_day,str,count,v_rnd,v_name
str=””
For i = 2 To 4

msgbox i
v_date=date+1

v_year=mid(year(v_date),3)
 
v_month=month(v_date)
If v_month v_month=”0″&v_month
End If

    v_day=day(v_date)
If v_day v_day=”0″&v_day
End If


str=v_month&v_day&v_year
msgbox str
    wait 1
   
Window(“Flight Reservation”).ActiveX(“MaskEdBox”).Type str

count=Window(“Flight Reservation”).WinComboBox(“Fly From:”).getitemscount
v_rnd=randomnumber.Value(0,count)
Window(“Flight Reservation”).WinComboBox(“Fly From:”).Select v_rnd

count=Window(“Flight Reservation”).WinComboBox(“Fly To:”).getitemscount
v_rnd=randomnumber.Value(0,count)
Window(“Flight Reservation”).WinComboBox(“Fly To:”).Select v_rnd

Window(“Flight Reservation”).WinButton(“FLIGHT”).Click
Window(“Flight Reservation”).Dialog(“Flights Table”).WinButton(“OK”).Click

select case(i)
Case 2
 v_name=”Jim”
Case 3
 v_name=”LiLy”
Case 4
 v_name=”Lucy”
Case else
 v_name=”other”
End select 

Window(“Flight Reservation”).WinEdit(“Name:”).Set v_name
wait 1

    Window(“Flight Reservation”).WinEdit(“Tickets:”).Set i

select case(i)
Case 2
 Window(“Flight Reservation”).WinRadioButton(“First”).Set
Case 3
 Window(“Flight Reservation”).WinRadioButton(“Business”).Set
Case 4
 Window(“Flight Reservation”).WinRadioButton(“Economy”).Set
Case else
 
End select 
    
wait 1
Window(“Flight Reservation”).WinButton(“Insert Order”).Click
Window(“Flight Reservation”).WinMenu(“Menu”).Select “File;New Order”     

Next

视频下载地址:https://download.csdn.net/download/u010746293/10438669

ps:QTP语法大部分可以参考VB但不是全部   

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2018年4月20日
下一篇 2018年4月21日

相关推荐