未来已来

SilkTest 脚本代码实例赏析

上一篇 / 下一篇  2008-09-25 09:26:56 / 个人分类:测试生活

获得对象中所有的子对象?

public LIST OF WINDOW GetChildObjects(Window wContainer, DATACLASS dcObject)
    [ ] // To get All child objects.
    [ ] // Used recursive method.
    [ ] LIST OF WINDOW lwndObjects, lwTemp1, lwTemp2
    [ ] LIST OF WINDOW lwndChildren = {...}
    [ ] WINDOW wParent, wChild, wTemp
    [ ]
    [-] do
        [-] if (wContainer.Exists (10))
            [ ] lwndChildren = wContainer.GetChildren (TRUE, FALSE)
            [ ]
            [-] for each wChild in lwndChildren
                [-] if wChild.IsOfClass(dcObject)
                    [ ] ListAppend (lwndObjects,wChild)
                [-] else
                    [ ] lwTemp1 = wChild.GetChildren(TRUE, FALSE)
                    [-] if (ListCount(lwTemp1) > 1)
                        [ ] lwTemp2 = GetChildObjects(wChild,dcObject)
     //To get particular objects
                        [-] if (ListCount(lwTemp2) > 0)
                            [ ] ListMerge (lwndObjects, lwTemp2)
        [-] else
            [ ] Print ("Container {[STRING]wContainer} is not available.")
    [+] except
        [ ] ExceptLog ()
    [ ]
    [ ] return lwndChildren

获得ip地址?

[+] public String GetIpAddress(String sMachineName)
    [ ] //To get IP Address for the particular machine in Network
    [ ] List of String lsOutput
    [ ] String sCommand
    [ ] String sTemp, sItem
    [ ] String sResult = NULL
    [ ] Boolean bResult = FALSE
    [ ] Integer iPos1, iPos2
    [ ]
    [ ] sCommand = "ping -a {sMachineName}"
    [ ] Sys_Execute (sCommand,lsOutput)
    [ ]
    [ ] //ListPrint (lsOutput)
    [-] for each sItem in lsOutput
        [-] if (MatchStr("*pinging*", sItem))
            [ ] bResult = TRUE
            [ ] break
        [ ]
    [-] if (bResult)
        [ ] iPos1 = StrPos ("[", sItem)
        [ ] iPos2 = StrPos ("]", sItem)
        [-] if ((iPos1 > 0) && (iPos2 > 0))
            [ ] sResult = SubStr(sItem,iPos1+1, iPos2-iPos1-1)
            [ ] Print ("Found IP Address: {sResult}")
    [ ] return sResult

 

获得子文件夹?

[ ]
[+] LIST OF STRING GetDirectories (STRING sDirPath)
[ ]
[ ] LIST OF FILEINFO lfFiles
[ ] FILEINFO file
[ ] LIST OF STRING lsDirsFound = {...}
[ ]
[ ]
[-] if ! SYS_DirExists ( sDirPath )
[ ] LogWarning ( "Cannot find '{sDirPath}' on file system" )
[ ]
[ ] lfFiles = SYS_GetDirContents (sDirPath)
[ ]
[-] for each file in lfFiles
[-] if (file.bIsDir)
[ ] ListAppend (lsDirsFound, sDirPath + "\" + file.sName)
[ ]
[ ] ListSort (lsDirsFound)
[ ]
[ ] return lsDirsFound


 


TAG: 测试生活

 

评分:0

我来说两句

Open Toolbar