51Testing软件测试论坛
标题:
silktest中脚本文件?
[打印本页]
作者:
web_web_
时间:
2005-10-19 15:33
标题:
silktest中脚本文件?
谁能提供一份简单的脚本文件看一下啊!!
[
Last edited by web_web_ on 2005-10-20 at 13:53
]
作者:
sincky
时间:
2005-10-24 22:00
给你提供一个脚本,希望对你有所参考:
[ ] // File: TestAceMenu.t
[ ] // *******************************************************************************
[ ] // Project: AutoCAD Electrical
[ ] //
[ ] // Revision History:
[ ] // Release day-mon-year Name Comment
[ ] // --------------------------------------------------------------------------------
[ ] // 1 26-03-2004 Sijin Mathews Created framework for ACE Menu Testing
[ ] // --------------------------------------------------------------------------------
[ ]
[ ]
[ ] boolean bCreateBaseline = FALSE
[ ] string sBaselineLocation = "S:\TEST SUITES\Data\Menu\"
[ ]
[ ]
[+] testcase CheckAppMenu()
[ ]
[ ] List of Window lwSomething = AppWnd.GetChildren()
[ ]
[ ] // remove all other objects other than menus
[ ] int i
[+] for (i=1; i<=ListCount(lwSomething); i++)
[+] if !lwSomething[i].IsOfClass(Menu)
[ ] ListDelete(lwSomething, i)
[ ] i--
[ ]
[ ]
[ ] // remove the system menu. usually the first
[+] for (i=1; i<=ListCount(lwSomething); i++)
[+] if lwSomething[i] == AppWnd.Menu1
[ ] ListDelete(lwSomething, i)
[ ] break
[ ]
[ ]
[ ] // remove menu other than those specified to be looked up
[+] for (i=1; i<=ListCount(lwSomething); i++)
[+] if ListFind(lsMenus2Chk,lwSomething[i]) == 0
[ ] ListDelete(lwSomething, i)
[ ] i--
[ ]
[ ]
[ ] Print("******************************")
[ ] Print("***** Menus Being Tested *****")
[ ]
[ ] ListPrint(lwSomething)
[ ] Print("******************************")
[ ]
[ ] MakeFolder(sBaselineLocation)
[ ] CheckMenu(lwSomething, bCreateBaseline)
[ ]
[ ]
[ ] // boolean for current status of open drawing file
[ ] boolean bNewDwg = True
[+] CheckMenu(List of Window lwSomething, boolean bCreateBaseline optional)
[ ]
[+] if bCreateBaseline == NULL
[ ] bCreateBaseline = false
[ ]
[ ] // look up each of the menus and their submenus
[ ] int iCounter = 1
[+] while iCounter<=ListCount(lwSomething)
[+] do
[ ]
[+] if (!AppWnd.Exists())
[ ] BaseState()
[ ]
[ ]
[+] if !bNewDwg
[ ] ThisDwg.New ()
[ ] SetBaseProject()
[ ]
[ ] ThisDwg.TypeE ("cmddia")
[ ] ThisDwg.TypeE ("1")
[ ] ThisDwg.TypeE ("FileDia")
[ ] ThisDwg.TypeE ("1")
[ ]
[ ] // ThisDwg.TypeE ("SDI")
[ ] // ThisDwg.TypeE ("0")
[ ]
[ ] bNewDwg = True
[ ]
[ ]
[ ] window object = lwSomething[iCounter]
[ ]
[ ] // if some initialization steps are required, perform them
[+] do
[ ] object.PreMenu()
[ ]
[+] except
[ ] // do nothing
[ ]
[ ]
[ ] // if menu is enabled
[+] if object.IsEnabled()
[ ]
[ ] // if there are no further submenus
[+] if(object.GetChildren()=={})
[ ]
[ ] object.Pick()
[ ]
[ ] Print("Testcase {object}_{Harness.LangCode()}")
[ ] Print("****************** Enteriing testcase {object} ****************")
[ ]
[ ]
[+] do
[ ]
[+] do
[ ] object.PostMenu()
[ ]
[+] except
[ ]
[+] if (AlertDlg.Exists ())
[ ] AlertDlg.OK.Click ()
[ ]
[ ] // baseline mode
[+] if bCreateBaseline
[ ] CreateBaseline(sBaselineLocation, object)
[ ]
[ ] // verification mode
[+] else
[ ] DoVerification(sBaselineLocation, object)
[ ]
[ ]
[+] except
[ ] LogError("The {object} menu option failed.")
[ ] ExceptClear()
[ ]
[ ]
[ ] bNewDwg= False
[ ] Print("Exit testcase {object}_{Harness.LangCode()} !!!!!!!!!!!!!!!!!!!!!!!!!")
[ ]
[ ] Sleep(3)
[ ] // dismiss any dialog present
[+] while true
[ ]
[ ] WINDOW wWindow = Desktop.GetActive ()
[+] if (wWindow!= AppWnd)
[ ] wWindow.Close (TRUE)
[ ]
[+] else
[ ] break
[ ]
[ ]
[ ] // exit any active command
[+] while true
[+] if (!ThisDwg.ReadyForNextCommand ())
[ ] AppWnd.TypeKeys ("<ESC>")
[ ]
[+] else
[ ] break
[ ]
[ ]
[ ]
[ ]
[ ] // else recursively seek them out
[+] else
[ ] CheckMenu(object.GetChildren(),bCreateBaseline)
[ ]
[ ]
[ ] iCounter++
[ ]
[+] else
[ ] LogWarning("Warning:{object} is not enabled. Please look up the same manually")
[ ] Print("Exit testcase {object}_{Harness.LangCode()} !!!!!!!!!!!!!!!!!!!!!!!!!")
[ ] iCounter++
[ ]
[ ]
[+] except
[ ] print(ExceptData())
[ ] iCounter++
[ ]
[ ]
[ ]
[ ]
[+] CreateBaseline(string sFileLocation, window sCurrentMenu)
[ ]
[ ] List of cWindowDetail cTemp = {}
[ ] ANYTYPE sValue2Write
[ ] sleep (2)
[ ]
[ ] window w = Desktop.GetActive()
[ ]
[+] if w!= AppWnd
[ ] w.Move(0,0)
[ ] print("dialog")
[ ]
[ ] HWND iHandle = w.GetHandle()
[ ] GetWindowDetail (iHandle, cTemp)
[ ] sValue2Write = cTemp
[ ]
[+] else
[ ]
[ ] print("cmdline")
[ ]
[ ] sValue2Write = ThisDwg.ReadyForNextCommand()
[ ]
[ ]
[ ] string sFileName = [string]sCurrentMenu
[ ] string sFileName_temp = StrTran (sFileName, ".", "\")
[ ]
[ ] sFileName = StrTran (sFileName, ".", "_")
[ ]
[ ] sFileLocation = sFileLocation + sFileName_temp
[ ] MakeFolder(sFileLocation)
[ ]
[ ] sFileName = sFileLocation + "\" + sFileName + ".txt"
[ ]
[+] do
[ ] HFILE hBaselineFile = FileOpen (sFileName, FM_WRITE, FS_EXCLUSIVE)
[ ] FileWriteValue (hBaselineFile, @("sValue2Write"))
[ ] FileClose (hBaselineFile)
[ ] print("BaseLine {sFileName} sucessfully created")
[ ]
[+] except
[+] if hBaselineFile != NULL
[ ] FileClose (hBaselineFile)
[ ]
[ ]
[ ]
[ ]
[+] DoVerification(string sFileLocation, window sCurrentMenu)
[ ]
[ ] string sFileName = [string]sCurrentMenu
[ ] string sFileName_temp = StrTran (sFileName, ".", "\")
[ ]
[ ] sFileName = StrTran (sFileName, ".", "_")
[ ] sFileLocation = sFileLocation + sFileName_temp
[ ]
[ ] sFileName = sFileLocation + "\" + sFileName + ".txt"
[ ]
[ ] ANYTYPE cObjExpected = NULL
[+] do
[ ] HFILE hBaselineFile = FileOpen (sFileName, FM_READ, FS_DENY_WRITE)
[+] do
[ ] FileReadValue (hBaselineFile, cObjExpected)
[+] except
[ ] LogError("Error in file read operation")
[ ] reraise
[ ]
[ ] FileClose (hBaselineFile)
[ ]
[ ] sleep (2)
[+] if (TypeOf(cObjExpected)== List of cWindowDetail)
[ ]
[ ] hBaselineFile = FileOpen (sFileName, FM_READ, FS_DENY_WRITE)
[ ]
[ ] List of cWindowDetail ObjExpectedRefFile
[ ] FileReadValue (hBaselineFile, ObjExpectedRefFile)
[ ] FileClose (hBaselineFile)
[ ]
[ ] HWND iHandle = Desktop.GetActive().GetHandle()
[ ] List of cWindowDetail cObjActual
[ ]
[ ] GetWindowDetail (iHandle, cObjActual)
[+] if(cObjActual != ObjExpectedRefFile)
[ ]
[ ] LogError("Test Failed: Results for Review")
[ ] ResPrintList ("Expected", ObjExpectedRefFile)
[ ] ResPrintList ("Actual", cObjActual)
[ ]
[ ]
[+] else if(ThisDwg.ReadyForNextCommand() != cObjExpected)
[ ] LogError("Test Failed: Results for Review")
[ ] LogError("Expected: {cObjExpected}. Found Otherwise.")
[ ]
[ ]
[ ]
[+] except
[+] if ExceptNum() == E_FILE
[ ] LogError("Baseline file does not exist")
[+] if hBaselineFile != NULL
[ ] FileClose (hBaselineFile)
[ ]
[ ]
[ ]
[ ]
[ ]
[+] list of WINDOW lsMenus2Chk= {...}
[ ] AppWnd.Projects
[ ] AppWnd.Wires
[ ] AppWnd.Components
[ ] AppWnd.PanelLayout
[ ]
[ ]
[ ] // *************************************
[+] type cWindowDetail is record
[ ] LONG lStyle
[ ] STRING sType
[ ] STRING sClass
[ ] INT iCtrlID
[ ] Boolean bIsHidden
[ ]
[+] void GetWindowDetail (HWND hWnd, inout List of cWindowDetail lsWndDetail)
[ ]
[+] if lsWndDetail == NULL
[ ] lsWndDetail = {}
[ ]
[ ] cWindowDetail Temp
[ ]
[ ] HWND hWndChild = GetWindow (hWnd, GW_CHILD)
[ ]
[+] while (hWndChild != 0)
[ ] Temp.lStyle = GetWindowLong (hWndChild, GWL_STYLE)
[ ]
[+] select
[+] case ((Temp.lStyle & WS_CHILD) != 0)
[ ] Temp.sType = "Child"
[ ] break
[ ]
[+] case ((Temp.lStyle & WS_POPUP) != 0)
[ ] Temp.sType = "Popup"
[ ] break
[ ]
[+] default
[ ] Temp.sType = "Overlapped"
[ ] break
[ ]
[ ] GetClassName (hWndChild, Temp.sClass, 256)
[ ] Temp.iCtrlID= GetDlgCtrlID (hWndChild)
[ ]
[+] if (! IsWindowVisible (hWndChild))
[ ] Temp.bIsHidden = True
[ ]
[+] else
[ ] Temp.bIsHidden = False
[ ]
[ ]
[ ] ListAppend(lsWndDetail, Temp)
[ ]
[ ] GetWindowDetail (hWndChild, lsWndDetail)
[ ] hWndChild = GetWindow (hWndChild, GW_HWNDNEXT)
[ ]
[+] boolean MakeFolder(string sFolderPath, string sFNameDelimiter optional)
[ ]
[+] if sFNameDelimiter == NULL
[ ] sFNameDelimiter = '\'
[ ]
[+] else
[ ] sFolderPath = StrTran (sFolderPath, sFNameDelimiter, '\')
[ ] sFNameDelimiter = '\'
[ ]
[ ]
[ ] int iField = 0
[ ] string sTemp = "test"
[+] while sTemp != ""
[ ] iField++
[ ] sTemp = GetField (sFolderPath, sFNameDelimiter, iField)
[ ]
[ ] iField--
[ ]
[ ] string sTempCurrFolder = GetField (sFolderPath, sFNameDelimiter, iField)
[ ] int iPos = StrPos (sTempCurrFolder, sFolderPath,true)
[ ] string sTempPath = Stuff (sFolderPath, iPos-1, Len(sFolderPath)-iPos+2, "")
[ ]
[+] if Right(sTempPath,1)==':'
[ ] string sTempPath_temp = StrTran (sTempPath, ':', "")
[ ]
[ ] string sDriveName = SYS_GetDrive ()
[ ]
[+] do
[ ] Sys_SetDrive (sTempPath_temp)
[ ]
[+] except
[ ] LogError("Invalid Drive Specified")
[ ] ExceptClear()
[ ] Sys_SetDrive (sDriveName)
[ ] return false
[ ]
[ ]
[ ] Sys_SetDrive (sDriveName)
[ ] sTempPath = sTempPath+"\"
[ ]
[ ]
[+] if !SYS_DirExists(sTempPath)
[+] if !MakeFolder(sTempPath)
[ ] return false
[ ]
[ ]
[+] if !SYS_DirExists ("{sTempPath}\{sTempCurrFolder}")
[ ] SYS_MakeDir ("{sTempPath}\{sTempCurrFolder}")
[ ] return true
[ ]
[ ]
[ ] return true
[ ]
[ ]
作者:
web_web_
时间:
2005-10-25 11:44
标题:
非常感谢
谢谢sincky
作者:
3_little_pig
时间:
2006-7-25 11:01
谢谢楼主
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2