发布新日志

  • How to Get Object Data ?

    2007-07-03 12:22:41

    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

     

     

  • 经验介绍-如何添加一行到到XLS文件的末尾

    2007-06-22 23:16:15

    公司要使用Robot进行自动画测试,最近忙于编制通用的库函数。

    下列是关于函数是对XLS文件的操作。这是我在自动化测试中形成REPORT的方法。共定义了10个字段

    ' FuncitonArea  -  Test CaseID  -  Test Title  - Report Time -Check Points    -Result - Expected Values- Test Value-  Break Point- LogFile

    大家有兴趣可以查考参考。欢迎指教!

    Global Const  XlsFieldNumber   As Integer = 10
    Declare Function AppendOneLineIntoXlsFile(XlsFields() As String, XlsFileName As String) As Integer

    Sub Main

        Dim Result, i As Integer
        Dim FieldNumber As Integer
        Dim XlsFileName As String
        Dim XlsFields(1 to XlsFieldNumber ) As String
       
       
        XlsFileName = "D:\TestReport.xls"
        For i = 1 to XlsFieldNumber
            XlsFields(i) = cstr(i)
        Next
        
        
        Result = AppendOneLineIntoXlsFile(XlsFields(),XlsFileName)
        
        
       
    End Sub

    Function AppendOneLineIntoXlsFile(XlsFields() As String, XlsFileName As String) As Integer

       
        'Open up Excel Appliation
        Dim objExcel As Object            ' Refer to MS EXCEL Application
        If objExcel Is Nothing Then
            Set ōbjExcel = CreateObject("Excel.Application")
            If objExcel is Nothing Then
                MsgBox "Cannot Run Excel Application"
                AppendOneLineIntoXlsFile = sqaFail
                Exit Function
            End If
        End If
       
        'Open the workbook File
        Dim objWorkBook As Object         ' Refer to MS EXCEL File
        Set ōbjWorkBook = objExcel.Workbooks.Open(XlsFileName)
        If objWorkBook Is Nothing Then
            MsgBox "Cannot find the file of " + XlsFileName
            AppendOneLineIntoXlsFile = sqaFail
            Exit Function
        End If
       
        'Set up a reference to the first sheet in the workbook
        Dim objWorkSheet As Object        ' Refer to MS EXCEL Sheet
        Dim SheetNumber As Variant        ' Refer to Sheet number of one Xls file
        SheetNumber = 1                    ' Here Only write data into the sheet-1
        Set ōbjWorkSheet = objWorkBook.WorkSheets(SheetNumber)
        If objWorkSheet Is Nothing Then
            MsgBox "Cannot Find WorkSheet"+ Cstr(SheetNumber)
            AppendOneLineIntoXlsFile = sqaFail
            Exit Function
        End If
       
        ' Get the lineLocation to append the data in XlsFileName
        Dim TmpString As String
        Dim j As Integer   ' i stands for row number, j stands for column number
        Dim LineLocation As Integer
        LineLocation = 1   ' Default value
        Do
            TmpString = ""
            For j = 1 to XlsFieldNumber
                TmpString = TmpString + Trim(objWorkSheet.Cells(LineLocation,j))
            Next
            If TmpString =  "" Then
                Exit Do
            Else
                LineLocation = LineLocation + 1
            End If
        Loop 
       
        'Append the XlsFields() Array data on i'th row 
         For j = 1 to XlsFieldNumber
            objWorkSheet.Cells(LineLocation,j) = XlsFields(j)
         Next
       
       'Save the changes
        objWorkBook.Save
      
        'Close the workbook
        objWorkBook.Close
        'Exit Excel
        objExcel.Quit
        'Clear all the references to the objects
        Set ōbjWorkBook = Nothing
        Set ōbjWorkSheet = Nothing
        Set ōbjExcel = Nothing

    End Function

Open Toolbar