1.
property
[-] property chbActive [-] window get() [-] if(this.ComboBox("Active|#3").Exists()) [ ] return this.ComboBox("Active|#3") [-] if(this.CustomWin("[HCustomControl]#1").CustomWin("[HyFramedForm]Black Oil Transition|$0").CheckBox("Active|#3").Exists()) [ ] return this.CustomWin("[HCustomControl]#1").CustomWin("[HyFramedForm]Black Oil Transition|$0").CheckBox("Active|#3") |
2. close()方法不起作用时用 Kill()
testcase test01() NotePad.invoke() NotePad.SetActive() sleep(3) NotePad.kill() // When close() method fails.
|
>>>
3. FlushCache( )
Causes SilkTest to reexamine the currently loaded page (BrowserChild) and get any new items as they are generated, such as popup menus. This method is very useful when you are recording dynamic objects that may not initially appear. This is available with the DOM extension only.
4. silktest 中调用 cmd 对话框(调用commandline 对话框)方法,不分操作系统都可以使用。
use "bwcompat.inc" [-] void Hysys_RunCommondLineFromCmd(String sCmdL) [-] //------------Log------------------------------------------- [ ] // Cheers Li 04-01-2010 [ ] // Run CMD comand line [ ] sleep(1) [ ] SYS_Execute("taskkill /f /t /im ""cmd.exe""") [ ] sleep(3) [ ] app_start("cmd") [ ] sleep(2) [-] do [ ] dlgSystem32Cmd.SetActive() [-] except [ ] app_start("cmd") [ ] dlgSystem32Cmd.TypeKeys(sCmdL) [ ] dlgSystem32Cmd.TypeKeys("<enter>") [ ] sleep(2)
|
5. 取一个real 型整数部分和小数部分的方法
[-] testcase temp() [ ] real rTemp=1.8213542235123212 [ ] integer iTempValue=[int]rTemp [ ] real rTempFraction=rTemp-iTempValue [ ] [ ] Print(iTempValue) [ ] Print(rTempFraction) |
6. withoptions
Opens a block of code in which Agent options can be set for the duration of the block.
7. with
with MainWin("Draw Prog*").ChildWin("c:\pix\pic2.bmp") .Click (1, 530, 272) .DragMouse (1, 529, 268, 509, 265) |
8. ArgListCall 用法
[-] testcase Temp_ArgListCall() [ ] [-] list of INTEGER lstemp={...} [ ] 3 [ ] 4 [ ] [ ] integer iReturn [ ] iReturn=ArgListCall("min",lstemp) [ ] [ ] Print(iReturn) |
9. silktest(4test)中 二维数组 的应用。
[-] testcase test01() [ ] [-] List of list of anytype tt={...} [ ] {"dog","19"} [ ] {"cat", "20"} [ ] {"pig", "31"} [ ] Print(ListCount(tt)) [ ] Print(tt[1,1]) |
10. silktest中获取文件类型和
[-] void VerifyDirFileTypeNumbers(String sFolderPath,String sFileType,integer iNumbers) [ ] // Veirfy the files numbers of specified type exists in the direcctory [-] if(!SYS_DirExists(sFolderPath)) [ ] RaiseError(13,"Directory: {sFolderPath} does not exists") [ ] List of FILEINFO lsTotal=SYS_GetDirContents(sFolderPath) [ ] int i,iN [ ] iN=ListCount(lsTotal) [ ] String a [ ] List of string lsFiles={} [-] for i=1 to iN [ ] a=lsTotal[i].sName [+] if(Right(a,Len(sFileType))==sFileType) [ ] ListAppend(lsFiles,a) [ ] //Print(a) [ ] int iActualNumbers=ListCount(lsFiles) [-] if(iActualNumbers==iNumbers) [ ] Log.Pass("The total numbers of .{sFileType} files equal to {iNumbers}.") [-] else [ ] Log.Error("The total numbers of .{sFileType} files does not equal to {iNumbers}, it is: {iActualNumbers}")
|
用法: VerifyDirFileTypeNumbers
(“c:\windows”,"exe",120)
11. silktest 等待对象为 enabled 方法:
[-] Boolean WaitForEnabled(window wObject) [ ] integer iTimeOut = iTimeLimit [ ] integer iTimeRetry = Agent.GetOption(OPT_WINDOW_RETRY) [ ] integer iTime = 0 [ ] Boolean bEnable = False [ ] [-] while( iTime<iTimeOut && !wObject.IsEnabled() ) [ ] sleep(iTimeRetry) [ ] iTime = iTime + iTimeRetry [ ] [ ] [ ] bEnable = wObject.IsEnabled() [ ] [ ] return ( bEnable ) |
12.
OPT_VERIFY_RESPONDING
Agent.SetOption(OPT_VERIFY_RESPONDING,false)
Setting this option to FALSE suppresses "control not responding" errors.
13. 等待鼠标状态。
[-] void WaitForMouseIdle(integer iTimeOut) [ ] integer iTime=1 [-] while(Cursor.GetType()=="WAIT" || Cursor.GetType()=="DELAY" && iTime < iTimeOut) [ ] sleep(1) [ ] iTime = iTime+5 [-] if(iTime > iTimeOut) [ ] Log.Fail("Cursor status is not idle in {iTimeOut} seconds") [ ] sleep(5)
|
14. 使用 ListRead()从一个文本中读取list变量,是一种数据驱动的好办法。
List of string lsFileContents
ListRead(lsFileContents,"C:\test.txt")
ListPrint(lsFileContents)
ListInsert (lsFile, i, lsNewInfo[i])
ListWrite (lsFile, "{GetProgramDir ()}\Sample.txt")
15. silktest 中使用递归实现清空文件夹内容方法:
[+] void glClearFolder(String filepath) [+] //---------------------Log---------------------// [ ] // Author : Cheers Li [ ] // Date : 2009-09-15 [ ] //-----------------------------------------------// [ ] filepath=Trim(filepath) [+] if(SubStr(filepath,Len(filepath),1)=="") [ ] filepath=SubStr(filepath,1,Len(filepath)-1) [+] else [ ] filepath=SubStr(filepath,1,Len(filepath)) [ ] String tempfilepath [ ] String tmDir [+] if(!SYS_DirExists(filepath)) [ ] RaiseError(13,"The path : {filepath} does not exists! ") [ ] List of FILEINFO fFileContents=SYS_GetDirContents(filepath) [-] FILEINFO item [-] for each item in fFileContents [ ] tempfilepath="{filepath}"+item.sName [-] if(item.bIsDir) [-] if(ListCount(SYS_GetDirContents(tempfilepath))==0) [ ] SYS_RemoveDir(tempfilepath) [-] else [ ] glClearFolder(tempfilepath) [ ] SYS_RemoveDir(tempfilepath) [-] else [ ] SYS_RemoveFile(tempfilepath)
|
16. Silktest 将 字符串转换成List of String 的方法
|
List of STRING lsConvertLineToList(String sLinfOfText) //--------------------------------------Log--------------------------------- // Author : Cheers Li September 24, 2010 // Description: This function is for getting Strings of line, and convert it to a list. [ ] String sTest=trim(sLinfOfText) [ ] long ltemp [ ] integer i,k=0 [ ] boolean blTemp [ ] List of STRING lsTestString [ ] ltemp=len(sTest) [ ] [+] for(i=1;i<=ltemp;i++) [-] if(IsSpace(substr(sTest,i,1))==false) [ ] k++ [ ] blTemp=false [-] else [-] if(blTemp==false) [ ] ListAppend(lsTestString,substr(sTest,i-k,k)) [ ] blTemp=true [ ] k=0 [ ] ListAppend(lsTestString,substr(sTest,i-k,k)) [ ] [ ] return lsTestString
|
17. 通过api sendmessage()来关闭窗口。
[ ] use "msw32.inc" [-] testcase testmenu() appstate none [ ] wRefSYSMain.Invoke() [ ] wRefSYSMain.SetActive() [ ] SendMessage(wRefSYSMain.hWnd,WM_CLOSE,0,0) |