筆記:NEC QTP 第一個實例

  • 2019 年 11 月 22 日
  • 筆記

第一次的筆記

Call LoopTable

Public Sub LoopTable

'Dim tableInput

'Set tableInput=new Sheet 'new出新的excel表格

'tableInput.SetSheet("Action1")

rem 測試title圖片是否合格

JavaWindow("User Login").JavaObject("MessageLabel(st)").Check CheckPoint("MessageLabel(st)")

'

'

'Dim AllRowCount

'AllRowCount=tableinput.AllRowCount rem 獲取總行數

'rem 進入循環

'For i=1 to AllRowCount

REM 輸入用戶資訊並確定 獲取了tableinput中的數據

JavaWindow("User Login").JavaEdit("User:").Set Parameter("username")

JavaWindow("User Login").JavaEdit("Password:").SetSecure Parameter("userpwd")

rem port在此版本中不能設置

'JavaWindow("User Login").JavaEdit("Port:").Set tableinput.GetRowColData(i,"port")

JavaWindow("User Login").JavaEdit("Server:").Set Parameter("server")

JavaWindow("User Login").JavaButton("Login").Click

If JavaWindow("User Login").JavaDialog("Warning").Exist=true Then '如果彈出的是warning,捕獲warning中的值與預期比較

Dim errorinfo1

errorinfo1=JavaWindow("User Login").JavaDialog("Warning").JavaStaticText("msg").GetROProperty("text")

rem 插入檢查點

' InsertCheckPoint(errorTitle, curError, expectedError)

call InsertCheckPoint(Parameter("username"),    errorinfo1,    Parameter("errorinfo"))

JavaWindow("User Login").JavaDialog("Warning").JavaButton("OK").Click

ElseIf    JavaDialog("Error").Exist = true Then  '如果彈出error,捕獲error內容與預期比較

rem 從錯誤窗口獲取錯誤資訊

Dim errorinfo2      

errorinfo2= JavaDialog("Error").JavaTable("ExceptionTable").GetCellData(0,2)

rem 插入檢查點

call InsertCheckPoint(Parameter("username"),     errorinfo2,     Parameter("errorinfo"))

rem 最後點擊確定

JavaDialog("Error").JavaButton("OK").Click

ElseIf JavaWindow("hiT 7090 NetManager").Exist=true Then'如果登錄成功,捕獲登錄名與預期比較

rem 插入檢查點,測試結束

Dim errorinfo3

errorinfo3=JavaWindow("hiT 7090 NetManager").JavaStaticText("Current User").GetROProperty("text")

call InsertCheckPoint(Parameter("username"),     errorinfo3,     Parameter("errorinfo"))

JavaWindow("hiT 7090 NetManager").JavaMenu("System").JavaMenu("Log Off").Select

JavaDialog("Log Off").JavaButton("Yes").Click

End If

'Next

End Sub

'Public Sub InsertCheckPoint(errorTitle,curError,expectedError)

'rem 手工插入檢查點

'If curError=expectedError Then

'Reporter.ReportEvent micPass, "錯誤回饋"+errorTitle, "期望結果:" & expectedError & Chr(10) &" 實際結果:" & curError

'Else

'Reporter.ReportEvent micFail, "錯誤回饋"+errorTitle, "期望結果:" & expectedError & Chr(10) & "實際結果:" & curError

'End If

'End Sub

'Public Function ReturnDt(rowNum)

'Set odic = createobject("Scripting.Dictionary")

'Set st=new Sheet

'st.SetSheet("Action1")

'With odic

'.Add "username",st.GetRowColData(rowNum,"username")

'.Add "userpwd",st.GetRowColData(rowNum,"userpwd")

'.Add "errorinfo",st.GetRowColData(rowNum,"errorinfo")

'End With

'Set ReturnDt=odic

'End Function

Class Sheet

'定義一些變數

private m_AllRowCount,m_SheetTable

rem 定義表實例

Public function SetSheet(sheetName)

setm_SheetTable=DataTable.GetSheet(sheetName)

End function

rem 只讀屬性:總行數

Public Property Get AllRowCount

AllRowCount = GetAllRowCount()

End Property

rem 方法,獲取行列值

Public function GetRowColData(row,colname)

GetRowColData=m_SheetTable.GetParameter(colname).ValueByRow(row)

End function

rem 此方法獲取錶行數

Private Function GetAllRowCount()

 GetAllRowCount= m_SheetTable.GetRowCount rem 獲取總行數

End Function

End Class