1. 程式人生 > >qtp指令碼測試飛機訂票系統(程式碼)

qtp指令碼測試飛機訂票系統(程式碼)

嗯,以前沒怎麼研究過這個,最近做課設用到了,順便發一下。

有要用的話,自己改一下路徑什麼的。版本qtp10.0

Mainaction

Dim AgentName

Dim Password

Dim DateOfFlight

Dim FaxNumber

Dim SelectTest

Dim DateOfUpdate

Dim DeleteName

Dimy 

Dim e

Dim e

Datatable.ImportSheet "C:\Users\yue\Desktop\yuetest\excel\Main.xls","Sheet1","Main"

'建立ExcelApp

物件

Set ExcelApp=CreateObject("Excel.Application")

'開啟excel 

Set ExcelWor=ExcelApp.Workbooks.Open("C:\Users\L\Desktop\Version1\excel\Main.xls")

'這裡需要用到UsedRange,表示Sheet1所使用單元格的範圍,否則會將所有單元格都打印出

Set ExcelShe=ExcelWor.Worksheets("Sheet1").UsedRange

'計算使用的單元格行數

rowcount=ExcelShe.Rows.count

'計算使用的單元格的列數

columncount=ExcelShe.Columns.count

 

For x=1 to rowcount

y =1

AgentName = ExcelShe.Cells(x,y)

y= y+1

Password = ExcelShe.Cells(x,y)

y = y+1

DateOfFlight = ExcelShe.Cells(x,y)

y= y+1

FaxNumber = ExcelShe.Cells(x,y)

y= y+1

SearchTest = ExcelShe.Cells(x,y)

y = y+1

DateOfUpdate = ExcelShe.Cells(x,y)

j =y+1

DeleteName = ExcelShe.Cells(x,y)

 

u = 0

'呼叫登入Action

SystemUtil.run "C:\Program Files (x86)\HP\QuickTest Professional\samples\flight\app\flight4a.exe"

RunAction "Login", oneIteration, AgentName, Password

 e = DataTable.Value("Login","Global")

   

If e = "1" Then  RunAction "Book", oneIteration, DateOfFlight else u = 1 End If

 e  = DataTable.Value("Book","Global")

If e = "1" Then  RunAction "Fax", oneIteration, FaxNumber End If

 e  = DataTable.Value("Fax","Global")

If e = "1" Then  RunAction "Search", oneIteration, SearchTest, x  End If

 e  = DataTable.Value("Search","Global")

If e = "1" Then  RunAction "Update", oneIteration, DateOfUpdate End If

 e  = DataTable.Value("Update","Global")

If e = "1" Then  RunAction "Delete", oneIteration,DeleteName  End If

If u =0 Then Window("Flight Reservation").WinMenu("Menu").Select "File;Exit" End If

Next

Set ExcelShe=Nothing

'關閉工作簿物件

ExcelWor.Close

'退出ExcelApp物件

ExcelApp.Quit

 

 

Loginaction

Dim user

Dim pass

Datatable.ImportSheet " C:\Users\yue\Desktop\yuetest\excel\Login.xls","Sheet1","Login"

'建立ExcelApp物件

Set ExcelApp=CreateObject("Excel.Application")

'開啟excel檔案工作簿

Set ExcelWor=ExcelApp.Workbooks.Open("C:\Users\yue\Desktop\yuetest\excel\Login.xls")

'這裡需要用到UsedRange,表示Sheet1所使用單元格的範圍,否則會將所有單元格都打印出

Set ExcelShe=ExcelWor.Worksheets("Sheet1").UsedRange

'計算使用的單元格行數

rowcount=ExcelShe.Rows.count

'計算使用的單元格的列數

columncount=ExcelShe.Columns.count

For i=1 to rowcount

For j=1 to columncount

'獲取單元格的內容

If j=1 Then  AgentName =ExcelShe.Cells(i,j)  Else Password = ExcelShe.Cells(i,j)  End If

Next

'呼叫登入Action

SystemUtil.RUN "C:\Program Files (x86)\HP\QuickTest Professional\samples\flight\app\flight4a.exe"

RunAction "Login", oneIteration, AgentName, Password

If Window("Flight Reservation").Exist Then  Window("Flight Reservation").Close  

Next

Set ExcelShe=Nothing

'關閉工作簿物件

ExcelWor.Close

'退出ExcelApp物件

ExcelApp.Quit

 

 

Login

Option explicit

Dim AgentName

Dim Password

Dim login

   login  = 0

user = parameter("AgentName")

pass = parameter("Password")

 

Dialog("Login").WinEdit("Agent Name:").Set user

Dialog("Login").WinEdit("Agent Name:").Type  micTab

Dialog("Login").WinEdit("Password:").Set pass

Dialog("Login").WinButton("OK").Click

 

'登入指令碼實現引數化驗證

If Dialog("Login").Dialog("Flight Reservations").Exist Then

If Dialog("Login").Dialog("Flight Reservations").Static("text:=Please enter agent name").Exist Then

Dialog("Login").Dialog("Flight Reservations").WinButton("確定").Click

Dialog("Login").WinButton("Cancel").Click

Reporter.ReportEvent micPass, "使用者名稱不能為空"

elseIf Dialog("Login").Dialog("Flight Reservations").Static("text:=Agent name must be at least 4 characters long.").Exist Then

Dialog("Login").Dialog("Flight Reservations").WinButton("確定").Click

Dialog("Login").WinButton("Cancel").Click

Reporter.ReportEvent micPass, "使用者名稱必須大於 4 個字元"

elseIf Dialog("Login").Dialog("Flight Reservations").Static("text:=Please enter password").Exist Then

Dialog("Login").Dialog("Flight Reservations").WinButton("確定").Click

Dialog("Login").WinButton("Cancel").Click

Reporter.ReportEvent micPass, "密碼不能為空"

elseIf Dialog("Login").Dialog("Flight Reservations").Static("text:=Incorrect password. Please try again").Exist Then

Dialog("Login").Dialog("Flight Reservations").WinButton("確定").Click

Dialog("Login").WinButton("Cancel").Click

Reporter.ReportEvent micPass, "密碼輸入錯誤"

elseIf Dialog("Login").Dialog("Flight Reservations").Static("text:=Password must be at least 4 characters long").Exist Then

Dialog("Login").Dialog("Flight Reservations").WinButton("確定").Click

Dialog("Login").WinButton("Cancel").Click

Reporter.ReportEvent micPass, "密碼必須大於 4 個字元"

else

Dialog("Login").Dialog("Flight Reservations").WinButton("確定").Click

Dialog("Login").WinButton("Cancel").Click

Reporter.ReportEvent micFail, "輸入異常錯誤!!"

End If

else

login = 1

Reporter.ReportEvent micDone, "登入", "完成登入操作"

Reporter.ReportEvent micDone, "訂票", "開始訂票"

wait 2

End If

DataTable.Value("Login","Global") = login

 

 

Bookaction

Dim dingprq

Datatable.ImportSheet "C:\Users\yue\Desktop\yuetest\excel\Book.xls","Sheet1","Book"

'建立ExcelApp物件

Set ExcelApp=CreateObject("Excel.Application")

'開啟excel檔案工作簿

Set ExcelWor=ExcelApp.Workbooks.Open("C:\Users\yue\Desktop\yuetest\excel \Book.xls")

'這裡需要用到UsedRange,表示Sheet1所使用單元格的範圍,否則會將所有單元格都打印出

Set ExcelShe=ExcelWor.Worksheets("Sheet1").UsedRange

'計算使用的單元格行數

rowcount=ExcelShe.Rows.count

'計算使用的單元格的列數

columncount=ExcelShe.Columns.count

For i=1 to rowcount

For j=1 to columncount

'獲取單元格的內容

dingprq =ExcelShe.Cells(i,j)

Next

'呼叫訂票Action

SystemUtil.run "C:\Program Files (x86)\HP\QuickTest Professional\samples\flight\app\flight4a.exe"

Dialog("Login").WinEdit("Agent Name:").Set "mercury"

Dialog("Login").WinEdit("Agent Name:").Type  micTab

Dialog("Login").WinEdit("Password:").Set "mercury"

Dialog("Login").WinButton("OK").Click

RunAction "Book", oneIteration, DateOfFlight

Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"

Next

Set ExcelShe=Nothing

'關閉工作簿物件

ExcelWor.Close

'退出ExcelApp物件

ExcelApp.Quit

 

 

Book

Option explicit

Dim dingprq

dingprq = parameter("DateOfFlight")

Dim  book

   book  = 0

Window("Flight Reservation").WinObject("Date of Flight:").Type dingprq

Window("Flight Reservation").WinComboBox("Fly From:").Select "Frankfurt"

'訂票指令碼實現引數化驗證

If Window("Flight Reservation").Dialog("Flight Reservations").Exist Then

If Window("Flight Reservation").Dialog("Flight Reservations").Static("text:=Valid flight dates are after 01/02/19").Exist Then                         '日期變化

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("確定").Click

Reporter.ReportEvent micPass, "訂票日期必須為當前日期(含)之後"

'月份錯誤

elseIf Window("Flight Reservation").Dialog("Flight Reservations").Static("text:=Invalid month Entered.The month must be greater than 01 and less than 12.").Exist Then

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("確定").Click

Reporter.ReportEvent micPass, "訂票月份必須大於01且小於12"

'日期錯誤

elseIf Window("Flight Reservation").Dialog("Flight Reservations").Static("text:=Invalid day Entered. The date should be valid for the given month.").Exist Then

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("確定").Click

Reporter.ReportEvent micPass, "訂票日期必須對給定月份有效"

'未輸入

elseIf Window("Flight Reservation").Dialog("Flight Reservations").Static("text:=Please enter a flight date.").Exist Then

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("確定").Click

Reporter.ReportEvent micPass, "未輸入航班日期"

'年份錯誤

elseIf Window("Flight Reservation").Dialog("Flight Reservations").Static("text:=Invalid year Entered. " + chr(10) + "The year must be greater than 2019" + chr(10) + "and less than 2038.").Exist Then

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("確定").Click

'Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"

Reporter.ReportEvent micPass, "訂票年份必須大於2019且小於2038"

else

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("確定").Click

Reporter.ReportEvent micFail, "輸入異常錯誤!!"

End If

else

book = 1

Window("Flight Reservation").WinComboBox("Fly To:").Select "Denver"

Window("Flight Reservation").WinButton("FLIGHT").Click

Window("Flight Reservation").Dialog("Flights Table").WinList("From").Activate "17707   FRA   03:48 PM   DEN   04:31 PM   AA     $111.00"

Window("Flight Reservation").WinEdit("Name:").Set "Dylan"

Window("Flight Reservation").WinEdit("Tickets:").Set "3"

Window("Flight Reservation").WinRadioButton("First").Set

Window("Flight Reservation").WinButton("Insert Order").Click

Reporter.ReportEvent micDone, "訂票", "完成訂票操作"

Reporter.ReportEvent micDone, "傳真", "開始傳真"

wait 2

End If

DataTable.Value("Book","Global") =  book

 

 

Faxaction

Dim chuanzh

Datatable.ImportSheet " C:\Users\yue\Desktop\yuetest\excel \Fax.xls","Sheet1","Fax"

'建立ExcelApp物件

Set ExcelApp=CreateObject("Excel.Application")

'開啟excel檔案工作簿

Set ExcelWor=ExcelApp.Workbooks.Open("C:\Users\yue\Desktop\yuetest\excel \Fax.xls")

'這裡需要用到UsedRange,表示Sheet1所使用單元格的範圍,否則會將所有單元格都打印出

Set ExcelShe=ExcelWor.Worksheets("Sheet1").UsedRange

'計算使用的單元格行數

rowcount=ExcelShe.Rows.count

'計算使用的單元格的列數

columncount=ExcelShe.Columns.count

For i=1 to rowcount

For j=1 to columncount

'獲取單元格的內容

FaxNumber =ExcelShe.Cells(i,j)

Next

'呼叫傳真Action

SystemUtil.run "C:\Program Files (x86)\HP\QuickTest Professional\samples\flight\app\flight4a.exe"

Dialog("Login").WinEdit("Agent Name:").Set "mercury"

Dialog("Login").WinEdit("Agent Name:").Type  micTab

Dialog("Login").WinEdit("Password:").Set "mercury"

Dialog("Login").WinButton("OK").Click

RunAction "Fax", oneIteration, FaxNumber

Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"

Next

Set ExcelShe=Nothing

'關閉工作簿物件

ExcelWor.Close

'退出ExcelApp物件

ExcelApp.Quit

 

 

Fax

Option explicit

Dim chuanzh

Dim  fax

   fax = 0

chuanzh = parameter("FaxNumber")

Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."

Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"

Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set "11"

Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click

Window("Flight Reservation").WinMenu("Menu").Select "File;Fax Order..."

Window("Flight Reservation").Dialog("Fax Order No. 11").WinObject("Fax Number:").Type FaxNumber

Window("Flight Reservation").Dialog("Fax Order No. 11").WinButton("Send").Click

'傳真指令碼實現引數化驗證

If Window("Flight Reservation").Dialog("Fax Order No. 11").Dialog("Flight Reservations").Exist Then

If Window("Flight Reservation").Dialog("Fax Order No. 11").Dialog("Flight Reservations").Static("text:=Please complete the fax number.").Exist Then

Window("Flight Reservation").Dialog("Fax Order No. 11").Dialog("Flight Reservations").WinButton("確定").Click

Window("Flight Reservation").Dialog("Fax Order No. 11").WinButton("Cancel").Click

Reporter.ReportEvent micPass, "傳真號碼錯誤"

else

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("確定").Click

Reporter.ReportEvent micFail, "輸入異常錯誤!!"

End If

else

fax = 1

Reporter.ReportEvent micDone, "傳真", "完成傳真操作"

Reporter.ReportEvent micDone, "查詢", "開始查詢"

wait 2

End If

DataTable.Value("Fax","Global") = fax

 

 

Searchaction

Dim SearchTest

Datatable.ImportSheet " C:\Users\yue\Desktop\yuetest\excel \Search.xls","Sheet1","Search"

'建立ExcelApp物件

Set ExcelApp=CreateObject("Excel.Application")

'開啟excel檔案工作簿

Set ExcelWor=ExcelApp.Workbooks.Open("C:\Users\yue\Desktop\yuetest\excel \Search.xls")

'這裡需要用到UsedRange,表示Sheet1所使用單元格的範圍,否則會將所有單元格都打印出

Set ExcelShe=ExcelWor.Worksheets("Sheet1").UsedRange

'計算使用的單元格行數

rowcount=ExcelShe.Rows.count

'計算使用的單元格的列數

columncount=ExcelShe.Columns.count

 

For i=1 to rowcount

For j=1 to columncount

'獲取單元格的內容

SearchTest =ExcelShe.Cells(i,j)

Next

SystemUtil.run "C:\Program Files (x86)\HP\QuickTest Professional\samples\flight\app\flight4a.exe"

Dialog("Login").WinEdit("Agent Name:").Set "mercury"

Dialog("Login").WinEdit("Agent Name:").Type  micTab

Dialog("Login").WinEdit("Password:").Set "mercury"

Dialog("Login").WinButton("OK").Click

'呼叫查詢Action

RunAction "Search", oneIteration, SearchTest, i

Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"

Next

Set ExcelShe=Nothing

'關閉工作簿物件

ExcelWor.Close

'退出ExcelApp物件

ExcelApp.Quit

 

 

Search

Option explicit

Dim SearchTest

Dim SearchNum

Dim search

search = 0

SearchTest = parameter("SearchTest")

SearchNum = parameter("SearchNum")

Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."

If SearchNum MOD 3 = 1 Then  

Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Customer Name").Set "ON"

Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set SearchTest

elseIf SearchNum MOD 3 = 2 Then

Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Flight Date").Set "ON"

Window("Flight Reservation").Dialog("Open Order").WinObject("23/22/3_").Type SearchTest

else

Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"

Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit_2").Set SearchTest

End If

Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click

'查詢指令碼實現引數化驗證

If Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").Exist Then

If Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").Static("text:=No orders found. Please try again").Exist Then

Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("確定").Click

Window("Flight Reservation").Dialog("Open Order").WinButton("Cancel").Click

Reporter.ReportEvent micPass, "沒有找到包含顧客名字的訂單"

elseIf Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").Static("text:=Invalid year Entered. The year must be greater than 1970 and less than 2038.").Exist Then

Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("確定").Click

Window("Flight Reservation").Dialog("Open Order").WinButton("Cancel").Click

Reporter.ReportEvent micPass, "訂票年份必須大於1970年且不到2038年"

elseIf Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").Static("text:=Invalid month Entered.The month must be greater than 01 and less than 12.").Exist Then

Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("確定").Click

Window("Flight Reservation").Dialog("Open Order").WinButton("Cancel").Click

Reporter.ReportEvent micPass, "訂票月份必須大於01且小於12"

elseIf Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").Static("text:=Invalid day Entered. The date should be valid for the given month.").Exist Then

Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("確定").Click

Window("Flight Reservation").Dialog("Open Order").WinButton("Cancel").Click

Reporter.ReportEvent micPass, "訂票日期必須對給定月份有效"

elseIf Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").Static("text:=Order number " + SearchTest + " does not exist").Exist Then

Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("確定").Click

Window("Flight Reservation").Dialog("Open Order").WinButton("Cancel").Click

Reporter.ReportEvent micPass,"失敗測試","訂單號不存在"

else

Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("確定").Click

Window("Flight Reservation").Dialog("Open Order").WinButton("Cancel").Click

Reporter.ReportEvent micFail,"輸入異常","輸入異常錯誤!!"

End If

elseIf SearchNum MOD 3 = 1 OR SearchNum MOD 3 = 2 Then Window("Flight Reservation").Dialog("Open Order").Dialog("Search Results").WinButton("OK").Click

search = 1

Reporter.ReportEvent micDone, "查詢", "完成查詢操作"

Reporter.ReportEvent micDone, "更新", "開始更新"

wait 2

End If

DataTable.Value("Search","Global") = search

 

 

Updateaction

Dim DateOfUpdate

Datatable.ImportSheet " C:\Users\yue\Desktop\yuetest\excel \Update.xls","Sheet1","Update"

'建立ExcelApp物件

Set ExcelApp=CreateObject("Excel.Application")

'開啟excel檔案工作簿

Set ExcelWor=ExcelApp.Workbooks.Open("C:\Users\yue\Desktop\yuetest\excel \Update.xls")

'這裡需要用到UsedRange,表示Sheet1所使用單元格的範圍,否則會將所有單元格都打印出

Set ExcelShe=ExcelWor.Worksheets("Sheet1").UsedRange

'計算使用的單元格行數

rowcount=ExcelShe.Rows.count

'計算使用的單元格的列數

columncount=ExcelShe.Columns.count

For i=1 to rowcount

For j=1 to columncount

'獲取單元格的內容

DateOfUpdate =ExcelShe.Cells(i,j)

Next

SystemUtil.run "C:\Program Files (x86)\HP\QuickTest Professional\samples\flight\app\flight4a.exe"

Dialog("Login").WinEdit("Agent Name:").Set "mercury"

Dialog("Login").WinEdit("Agent Name:").Type  micTab

Dialog("Login").WinEdit("Password:").Set "mercury"

Dialog("Login").WinButton("OK").Click

'呼叫更新Action

RunAction "Update", oneIteration, DateOfUpdate

Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"

Next

Set ExcelShe=Nothing

'關閉工作簿物件

ExcelWor.Close

'退出ExcelApp物件

ExcelApp.Quit

 

Update

Option explicit

Dim DateOfUpdate

Dim update

update = 0

DateOfUpdate = parameter("DateOfUpdate")

Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."

Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"

Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set "11"

Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click

Window("Flight Reservation").WinObject("Date of Flight:").Type  micDel

Window("Flight Reservation").WinObject("Date of Flight:").Type  micDel

Window("Flight Reservation").WinObject("Date of Flight:").Type  micDel

Window("Flight Reservation").WinObject("Date of Flight:").Type  micDel

Window("Flight Reservation").WinObject("Date of Flight:").Type  micDel

Window("Flight Reservation").WinObject("Date of Flight:").Type  micDel

Window("Flight Reservation").WinObject("Date of Flight:").Type DateOfUpdate

Window("Flight Reservation").WinButton("FLIGHT").Click

'更新指令碼實現引數化驗證

If Window("Flight Reservation").Dialog("Flight Reservations").Exist Then

If Window("Flight Reservation").Dialog("Flight Reservations").Static("text:=Valid flight dates are after 01/03/19").Exist Then                         '日期變化

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("確定").Click

Reporter.ReportEvent micPass,"失敗測試","訂票日期必須為當前日期(含)之後"

'年份錯誤

elseIf Window("Flight Reservation").Dialog("Flight Reservations").Static("text:=Invalid year Entered. " + chr(10) + "The year must be greater than 2019" + chr(10) + "and less than 2038.").Exist Then

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("確定").Click

Reporter.ReportEvent micPass, "訂票年份必須大於2019且小於2038"

'月份錯誤

elseIf Window("Flight Reservation").Dialog("Flight Reservations").Static("text:=Invalid month Entered.The month must be greater than 01 and less than 12.").Exist Then

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("確定").Click

Reporter.ReportEvent micPass, "訂票月份必須大於01且小於12"

'日期錯誤

elseIf Window("Flight Reservation").Dialog("Flight Reservations").Static("text:=Invalid day Entered. The date should be valid for the given month.").Exist Then

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("確定").Click

Reporter.ReportEvent micPass, "訂票日期必須對給定月份有效"

'未輸入

elseIf Window("Flight Reservation").Dialog("Flight Reservations").Static("text:=Please enter a flight date.").Exist Then

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("確定").Click

Reporter.ReportEvent micPass, "未輸入航班日期"

else

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("確定").Click

Reporter.ReportEvent micFail, "輸入異常錯誤!!"

End If

else

Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click

Window("Flight Reservation").WinButton("Update Order").Click

'未修改

If Window("Flight Reservation").Dialog("Flight Reservations").Static("text:=Record not updated; No Field values set").Exist Then

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("確定").Click

Reporter.ReportEvent micPass, "沒有記錄被更新"

End If

update = 1

Reporter.ReportEvent micDone, "完成更新操作"

Reporter.ReportEvent micDone, "開始刪除"

wait 2

End If

DataTable.Value("Update","Global") = update

 

 

Deleteaction

Dim DeleteName

Datatable.ImportSheet " C:\Users\yue\Desktop\yuetest\excel \Delete.xls","Sheet1","Delete"

'建立ExcelApp物件

Set ExcelApp=CreateObject("Excel.Application")

'開啟excel檔案工作簿

Set ExcelWor=ExcelApp.Workbooks.Open("C:\Users\L\Desktop\Version1\excel\Delete.xls")

'這裡需要用到UsedRange,表示Sheet1所使用單元格的範圍,否則會將所有單元格都打印出

Set ExcelShe=ExcelWor.Worksheets("Sheet1").UsedRange

'計算使用的單元格行數

rowcount=ExcelShe.Rows.count

'計算使用的單元格的列數

columncount=ExcelShe.Columns.count

For i=1 to rowcount

For j=1 to columncount

'獲取單元格的內容

DeleteName =ExcelShe.Cells(i,j)

Next

SystemUtil.run "C:\Program Files (x86)\HP\QuickTest Professional\samples\flight\app\flight4a.exe"

Dialog("Login").WinEdit("Agent Name:").Set "mercury"

Dialog("Login").WinEdit("Agent Name:").Type  micTab

Dialog("Login").WinEdit("Password:").Set "mercury"

Dialog("Login").WinButton("OK").Click

'呼叫刪除Action

RunAction "Delete", oneIteration, DeleteName

Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"

Next

Set ExcelShe=Nothing

'關閉工作簿物件

ExcelWor.Close

'退出ExcelApp物件

ExcelApp.Quit

 

 

 

Delete

Option explicit

Dim DeleteName

Dim del

del = 0

DeleteName = parameter("DeleteName")

Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."

If Window("Flight Reservation").Dialog("Flight Reservations").Exist Then

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("否(N)").Click

End If

Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Customer Name").Set "ON"

Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set DeleteName

Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click

'刪除指令碼實現引數化驗證

If Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").Exist Then

If Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").Static("text:=No orders found. Please try again").Exist Then

Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("確定").Click

Window("Flight Reservation").Dialog("Open Order").WinButton("Cancel").Click

Reporter.ReportEvent micPass, "沒有找到包含顧客名字的訂單"

else

Window("Flight Reservation").Dialog("Open Order").Dialog("Flight Reservations").WinButton("確定").Click

Window("Flight Reservation").Dialog("Open Order").WinButton("Cancel").Click

Reporter.ReportEvent micFail, "輸入異常錯誤!!"

End If

else

Window("Flight Reservation").Dialog("Open Order").Dialog("Search Results").WinButton("OK").Click

Window("Flight Reservation").WinButton("Delete Order").Click

Window("Flight Reservation").Dialog("Flight Reservations").WinButton("是(Y)").Click 

del = 1

Reporter.ReportEvent micDone, "完成刪除操作"

Reporter.ReportEvent micDone, "已經完成"

wait 2

End If

 

DataTable.Value("Del","Global") = del