How to Get Object Data ?

上一篇 / 下一篇  2007-07-03 12:22:41 / 个人分类:Robot测试交流

As we know, Rebot does not provide method to get Object Data, even through SQAGetProperty can get Object Property. But it is very important to get Object Data, such as ListView Data, normally, it is gripped data table with multiple columns and rows.  During our test, we may need to control different operations according to Listview data.   But Robot will come up with different Listview data when re-play scrīpts.

The normal example is, we want to get one alarm's detailed AlamInformation from a Alamlist, but the alarm list is refreshed constantly. So we need to location one alarm according some condition. To do it, we certainly want to know the actual AlarmList data when we play-back the scrīpts.

Here give you an example to get Object Data. Welcome you to give any comments. Thank you.

Sub Main
    Dim Result As Integer

    'Initially Recorded: 2007-07-03  09:03:31
    'scrīpt Name: ObjectData
    Dim Dir1,File1, file2 As String
   
    Window SetTestContext, "Caption=Alarm Manager", ""
    Window SetTestContext, "Caption=Alarm Manager;ChildWindow", ""
' 1. When you create VP=AlarmList, you need to edit it, change some cells' value. such kind of operation will cause the following "ListViewVP" always fails.
' 2. You need also  insert SqaSuspendLogOutput before call ListViewVP, it will cause the cripts still go down even the ListViewVP is failed. After ListViewVP, you can insert SqaResumeLogOutput.
' 3. You need change "Wait" option, so that you need not wait too long when the ListViewVP is failed.

    SqaSuspendLogOutput
    Result = ListViewVP (CompareData, "ID=59649", "VP=AlarmList;Wait=2,2")
    SqaResumeLogOutput
    Window ResetTestContext, "", ""
' Robot provide one function to get "Actual Data" file, this file is always with full path and file name. the file name always contains "act" substring. (you can also get "expected data", but it means nothing.)
' But I found a problem. the Path is correct, but I cannot find the filename. it is very intersting! So we need find correct file for actual data.

    File1 = sqaVPGetActualFileName("AlarmList","grd")
' Because the filename is not correct, we need to get correct file name.
' This function is to get the DIR name from UNCname. Maybe, you don't use UNCName, you need to change the function. it is very simple.
    dir1 = GetDIRFromUNC(File1 )  
' The following find the acutal data file. Rebot support the pattern matching. it is lucky that there is only one file with the format "*act*.grd".
    File2 = Dir1 +  DIR(dir1+"*act*.grd")
' After get the file, we can open the file use "open", you  can open it as txt file.
' In the "*.grd" each line means each row in Listview Data.
' And there is one "tap" signal between each column. so it is very easy to manipulate the actual data. 
     
    dim LineContents As String
    dim i,j As Integer
    Open File2 For Input As #1
    '$CStrings

' Here give you one example to get each column each row, and print the value into console log .
    Do until Eof(1) = -1
      Line input #1, LineContents
            For i = 1 to 32
                SqaConsoleWrite cstr(i) + "=" + GetField(LineContents,i,"\t")
            Next
   End do
    '$NoCStrings
    Close #1

End Sub

'Dir String fron UNCNAME
' For Example //autotest01/file.txt
Function GetDIRFromUNC(UNCName As String) As String
    Dim i As Integer
    Dim CharNumber          'To Store the number of "\" char
    dim TmpString          'To Store temporary string               
    i =  InStr(1,UNCName,"\")
    TmpString = Trim(UNCName)    ' Just make sure the UNCName is not changed in the function
    Do Until  i = 0
        TmpString = Left(TmpString,i-1) + Right(TmpString,Len(TmpString)-i)        ' Delete the "\", count the deleting times as the number of "/'
        i= InStr(1,TmpString,"\")
        CharNumber = CharNumber + 1                         ' to Store the Charnumber with the number of "/" in the UNCName
    Loop
    TmpString = GetField(UNCName,CharNumber+1,"\")              ' Get the FileName
    i = InStr(1,UNCName,TmpString)                              ' Get the position of FileName in the UNCNmae
    GetDirFromUNC = Left(UNCName, i-1)                              ' Get DirName
End Function

 

 


TAG: Robot测试交流

 

评分:0

我来说两句

Open Toolbar