一、split拆分字符串
函数调用格式:split(expression,delimiter,count,compare)
参数:
Expression为需要拆分的字符串
Delimiter为字符串中的某个字符,用来识别子串的拆分位置
Count为需要返回的子串的个数,-1意味着返回所有子串
Compare为0时是根据二进制方式匹配,为1时为文本方式匹配
示例:
Dim MyString, MyArray, Msg
MyString = "VBScriptXisXfun!"
MyArray = Split(MyString, "x", -1, 1)
' MyArray(0) contains "VBScript".
' MyArray(1) contains "is".
' MyArray(2) contains "fun!".
Msg = MyArray(0) & " " & MyArray(1)
Msg = Msg & " " & MyArray(2)
MsgBox Msg
二、Date获取当前系统日期
示例:
Dim MyDate
MyDate = Date ' MyDate contains the current system date.
三、Mid截取字符
函数调用格式:mid(string,start,length)
参数:
string为需要截取的字符串
start为开始位置
length为需要截取的长度
示例:
Dim myvar
Myvar = mid(“VBScript”,3,6) ‘myvar为“Script”
四、Time返回当前系统时间
示例:
Dim mytime
mytime = Time
五、CreateObject创建并返回一个自动对象的指针
函数调用格式:CreateObject(servername.typename,location)
参数:
servername为应用对象的名字
typename为需要创建对象的类型
location为将要创建对象所在网络服务器的名字
示例1:
,创建一个Microsoft Excel sheet 对象
Dim ExcelSheet
Set ExcelSheet = CreateObject("Excel.Sheet")
,设置相应属性和方法
' Make Excel visible through the Application object.
ExcelSheet.Application.Visible = True
' Place some text in the first cell of the sheet.
ExcelSheet.ActiveSheet.Cells(1,1).Value = "This is column A, row 1"
' Save the sheet.
ExcelSheet.SaveAs "C:\DOCS\TEST.XLS"
' Close Excel with the Quit method on the Application object.
ExcelSheet.Application.Quit
' Release the object variable.
Set ExcelSheet = Nothing
示例2: '=======================================================' 功能名 : TestResultLog
' 目的 : 将输入成功与否的日志输入到日志文件中
' 输入参数 : judgment,UserName
'=======================================================
Sub TestResultLog(judgment,UserName)
Dim strSuccess,strFail,fso,myfile,strTime
strTime="[" & date & "" & mid(time,1,5) & "]"
strSuccess=strTime & " 账户“" & UserName & " 登录成功"
strFail=strTime & " 账户“" & UserName & " 登录失败"
Set fso=CreateObject("Scripting.FileSystemObject")
'判断文件是否存在,如果存在打开,否则创建
If (fso.FileExists("F:\Test_Result_Log\TestResult_log.txt")) Then
'定义常量intCode,作为打开文件函数的参数,防止写入数据是Unicode编码乱码
Const intCode=-1
Set myfile=fso.OpenTextFile("F:\Test_Result_Log\TestResult_log.txt",8,true,intCode)
else
Set myfile=fso.CreateTextFile("F:\Test_Result_Log\TestResult_log.txt",2,true)
End If
If judgment Then
myfile.WriteLine strSuccess
else
myfile.WriteLine strFail
End If
myfile.Close
set myfile=nothing
set fso=nothing
End Sub
六、使用简单的自动化测试框架目录
将测试项目相应的脚本、数据、函数、对象库、输出日志等放到同一级目录下,并分别创建不同的文件夹进行存放。示例截图如下:
在SQL结构化查询语言中,LIKE语句有着至关重要的作用。
LIKE语句的语法格式是:select * from 表名 where 字段名 like 对应值(子串),它主要是针对字符型字段的,它的作用是在一个字符型字段列中检索包含对应子串的。
A:% 包含零个或多个字符的任意字符串:
1、LIKE'Mc%' 将搜索以字母 Mc 开头的所有字符串(如 McBadden)。
2、LIKE'%inger' 将搜索以字母 inger 结尾的所有字符串(如 Ringer、Stringer)。
3、LIKE'%en%' 将搜索在任何位置包含字母 en 的所有字符串(如 Bennet、Green、McBadden)。
B:_(下划线) 任何单个字符:LIKE'_heryl' 将搜索以字母 heryl 结尾的所有六个字母的名称(如 Cheryl、Sheryl)。
C:[ ] 指定范围 ([a-f]) 或集合 ([abcdef]) 中的任何单个字符: 1,LIKE'[CK]ars[eo]n' 将搜索下列字符串:Carsen、Karsen、Carson 和 Karson(如 Carson)。
2、LIKE'[M-Z]inger' 将搜索以字符串 inger 结尾、以从 M 到 Z 的任何单个字母开头的所有名称(如 Ringer)。
D:[^] 不属于指定范围 ([a-f]) 或集合 ([abcdef]) 的任何单个字符:LIKE'M[^c]%' 将搜索以字母 M 开头,并且第二个字母不是 c 的所有名称(如MacFeather)。
E:* 它同于DOS命令中的通配符,代表多个字符:c*c代表cc,cBc,cbc,cabdfec等多个字符。
F:?同于DOS命令中的?通配符,代表单个字符 :b?b代表brb,bFb等
G:# 大致同上,不同的是代只能代表单个数字。k#k代表k1k,k8k,k0k 。
F:[!] 排除 它只代表单个字符。
LIKE语句的语法格式是:select * from 表名 where 字段名 like 对应值(子串),它主要是针对字符型字段的,它的作用是在一个字符型字段列中检索包含对应子串的。