|
做了一段时间silktest了
讨论讨论框架问题
Framework 结构
Inc 文件 需要6个
第一个用来 定义const 变量
许多常量最好动态得到,因为你的测试脚本 需要在很多机器上运行
建议多使用 SYS_GetEnv()
比如路径里要用到你的机器名字 你可以 const Dir =directory+SYS_GetEnv("COMPUTERNAME")//name of directory
第二个定义 windows delaration 对某个对象定义方法
第三个定义 测试用例exit函数
第四定义函数库
第五定义 appstate 函数 SetAppState () 顺便说一句最好在case 进入的时候 最好定义一个clearwin() function 把你application 所有可能UI object 放到一个list of window 里 然后用一个loop把它们给关了 我一般都kill 掉process 三个 方法 pskill taskkill ntsd
第六定义类库 ,在silktest里不能识别的对象很少能用silktest自带的classmap map 成silktest build-in class 大部分情况要用引入c++
like winclass MyClass
extern INTEGER Increment (INTEGER iNum,
out INTEGER iFinal)
在给大家点常用函数
创建文件夹
[-] public void MakeDirectory (STRING sDir)
[ ] INTEGER iBreak = 0
[ ] STRING sBreak = ""
[ ] ResOpenList ("MakeDirectory ({sDir})")
[ ]
[-] if (SubStr (sDir, Len(sDir)) != "\")
[ ] sDir = sDir + "\"
[ ]
[-] if (SYS_DirExists (sDir) == FALSE)
[ ]
[-] while (sBreak != sDir)
[ ]
[ ] iBreak = iBreak + 1
[ ]
[ ] sBreak = sBreak + GetField (sDir, "\", iBreak) + "\"
[ ]
[-] if (SYS_DirExists (sBreak) == FALSE)
[ ]
[ ] // Print ("Directory '{sBreak}' created.")
[ ]
[ ] SYS_MakeDir (sBreak)
[-] else
[ ] Print ("Directory Structure already exists")
[ ] ResCloseList ()
得到文件夹大小
[ ] // dir - the full path of the directory of which to caculate the size
[-] private Real directory_size (String dir)
[ ] LIST OF FILEINFO files = SYS_GetDirContents (dir)
[ ] int numfiles = ListCount (files)
[ ] int i
[ ] Real dirsize=0
[-] for (i = 1; i <= numfiles; ++i)
[ ] String file = dir + "\" + files.sName
[-] if (!files.bIsDir)
[ ] dirsize = dirsize + files.iSize
[-] else
[ ] dirsize = dirsize + directory_size (file) //call directory size recursively
[ ] return dirsize
搜索文件夹
[-] public void Search(STRING root)//,STRING oringinal)
[ ] // MakeDirectory(oringinal)
[ ] LIST OF FILEINFO lsf={}
[ ] lsf=SYS_GetDirContents(root)
[ ] int i=1
[-] if ListCount(lsf)!=0
[-] for (i=1;i<=ListCount(lsf);i++)
[-] if !lsf.bIsDir
[ ] continue
[-] else
[ ] STRING sDir=root+"\"+lsf.sName
[ ] Search(sDir)//,oringinal)
删除文件夹
[+] public remove_directory (String dir)
[ ] //clean if it exists already
[-] if SYS_DirExists (dir) == TRUE
[ ] print ("**** directory { dir} exists, removing ***")
[ ] //call ms-dos and delete directory recursively
[ ] String command = cmd+" /c rmdir " + """" + dir + """"+"/s" + "/q"
[ ] Sys_SetDir(Sys_GetEnv("USERPROFILE"))
[ ] SYS_Execute (command)
[ ]
[ ]
copy 文件夹
[-] public copy_directory (String dir, String destination)
[ ] LIST OF FILEINFO files = SYS_GetDirContents (dir)
[ ] int numfiles = ListCount (files)
[ ] int i
[ ] Real dirsize=0
[-] for (i = 1; i <= numfiles; ++i)
[ ] String new_file = destination + "\" + files.sName
[-] if (!files.bIsDir) //not a directory so just copy file
[ ] SYS_CopyFile (dir+"\"+files.sName, new_file)
[-] else //directory, so create it and continue copying
[ ] SYS_MakeDir (new_file)
[ ] copy_directory (dir+"\"+files.sName, new_file) //call copy directory recursively
判断文件是否是加密文件
[-] public Boolean check_encrypted (String file)
[ ] String command = cmd + " /C " + "efsinfo " + """" + file + """" + " | find "+""""+"Not"+""""
[ ] LIST OF STRING output
[ ] SYS_Execute (command,output)
[ ] print (output)
[-] if ListCount (output) == 1 //"Not encrypted" was found
[ ] print ("found not")
[ ] return false
[ ] return true
测试进程是否运行
[-] BOOLEAN isInList(String sName)
[ ] STRING sCommand="tasklist /FO LIST"
[ ] LIST OF STRING ls={}
[ ] LIST OF STRING ls_image={}
[ ] SYS_Execute(sCommand,ls)
[ ] int i=1
[-] for(i=1;i<=ListCount(ls);i++)
[-] if MatchStr("*Image Name*",ls)
[ ] STRING sTemp=GetField(ls,":",2)
[ ] ListAppend( ls_image,Upper(Trim(sTemp)))
[ ]
[-] if ListFind(ls_image,Upper(sName))==0
[ ] return false
[-] else
[ ] return true
自动发邮件 注需要下载blat.exe
[-] void MAIL(STRING sFile,STRING sRecipients,STRING senderEmail,STRING UserName,STRING PassWord)
[ ] STRING sDir="C:\"
[ ] STRING sMail="blat"
[ ] LIST OF STRING ls={}
[ ] STRING sCommandLine=sDir+sMail+" "+sFile+" "+"-to"+" "+sRecipients+" "+"-f "+" "+senderEmail+" "+"-u"+" "+UserName+" "+"-pw"+" "+PassWord
[ ] print(sCommandLine)
[ ] SYS_Execute(sCommandLine,ls)
[ ] listprint(ls)
对比两个excel 内容
[-] type Content is record
[ ] STRING sEn
[ ] STRING sLocal
[-] public LIST OF ANYTYPE getItem(STRING DNS)
[ ] HDATABASE hdbc
[ ] HSQL hstmt
[ ] Content tool
[ ] LIST OF ANYTYPE ls={}
[ ] STRING s
[-] do
[ ] hdbc=DB_Connect("DSN={DNS}")
[ ] hstmt=DB_ExecuteSql(hdbc,"SELECT * FROM [Sheet1$]")
[-] while (DB_FetchNext(hstmt,tool))
[ ] ListAppend(ls,tool)
[ ] DB_Disconnect(hdbc)
[ ] return ls
[-] except
[ ] return ls
[ ] ExceptLog()
[-] public LIST OF ANYTYPE Compare(STRING sTarget,STRING sTemplate)
[ ] LIST OF ANYTYPE ls_sTarget={}
[ ] LIST OF ANYTYPE ls_sTemplate={}
[ ] LIST OF ANYTYPE ls_res={}
[ ] ls_sTarget=getItem(sTarget)
[ ] ls_sTemplate=getItem(sTemplate)
[ ] int i=1
[ ] int j=1
[-] for (i=1;i<=ListCount(ls_sTarget);i++)
[-] for(j=1;j<=ListCount(ls_sTemplate);j++)
[-] if ls_sTarget.sEn==ls_sTemplate[j].sEn&&ls_sTarget.sLocal!=ls_sTemplate[j].sLocal
[ ] ListAppend(ls_res,ls_sTarget)
[ ] ListAppend(ls_res,ls_sTemplate[j])
[ ] return ls_res
any question please contact me kettlescott@hotmail.com
[ 本帖最后由 kettleyang 于 2008-3-27 16:00 编辑 ] |
|