'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''函数功能:Quick 和 Robot 常用库函数''''''''''''''''''''''''''''''
'''''说明:1.以QTP_开头的函数只适用于QuickTest''''''''''''''''''''''''
''''' 2.以Robot_开头的函数只适用于Robot''''''''''''''''''''''''''
''''' 3.除以上外,QuickTest和Robot都适用'''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''以下为QuickTest和Robot都适用函数''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'生成整数随机数
Public Function Rand(min,max)
Randomize '对随机数生成器做初始化的动作。
Rand = Int((max * Rnd) + min)
End Function
'脚本之间共享变量,以及相互调用函数
Public Sub Include(sInstFile)
Dim oFSO, f, s
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set f = oFSO.OpenTextFile(sInstFile)
s = f.ReadAll
f.Close
ExecuteGlobal s
End Sub
'获取当前日期
Public Function Get_Data()
Dim currentDate
currentDate = Date
Get_Data = currentDate
End Function
'月日年 122611
Public Function Converts_Data()
Dim currentDate,year1,month1,day1,date1
currentDate = Date
year1 = Mid(currentDate,3,2)
If(Mid(currentDate,7,1)<>"-")Then
month1 = Mid(currentDate,6,2)
Else
month1 = "0"&Mid(currentDate,6,1)
End If
temp = (Len(currentDate)-1)
If(Mid(currentDate,temp,1)<>"-")Then
day1 = right(currentDate,2)
day1 = day1+1
Else
day1 = right(currentDate,1)+1
day1 = "0"&day1
End If
date1 = month1&day1&year1
Converts_Data = date1
End Function
'获取当前时间
Public Function Get_Time()
Dim currentTime
currentTime = Time
Get_Time = currentTime
End Function
'随机函数生成
'输入值:生成值范围 i~j
'返回值:随机数
Public Function Get_RandNum(fromNum,toNum)
If (fromNum<0) Or (toNum<0) Then
MsgBox "只接受大于零的输入"
ElseIf fromNum>toNum then
MsgBox "起始值必须小于结束值"
Else
Dim RunTime
Randomize
RunTime = Int((10 * Rnd) + 1)
Dim MyValue,i
For i = 1 To RunTime
Randomize
MyValue = Int(((toNum - fromNum + 1) * Rnd) + (fromNum))
Next
Get_randNum=MyValue
End If
End Function
'值交换函数
Public Sub swap(byref a,byref b)
Dim c
c = a
a = b
b = c
End Sub
'是否是质数函数
'是质数返回true,否则返回false
Function IsPrimeNumber(num)
Dim i,flag
flag = true
If num = 1 Then
flag = False
ElseIf num < 1 Then
MsgBox "只能接受大于0的数"
flag = False
Else
For i = 2 To (num - 1)
If ((num Mod i) = 0) Then
flag = False
Exit For
End If
Next
End If
IsPrimeNumber = flag
End Function
'读指定文本文件指定行内容
Function ReadLine(pathway, rowcount)
Dim fso,myfile,i,flag
flag = 1
Set fso=CreateObject("scripting.FileSystemObject")
If fso.FileExists(pathway) then
Set myfile = fso.openTextFile(pathway,1,false)
Else
flag = 0
End If
For i=1 to rowcount-1
If Not myfile.AtEndOfLine Then
myfile.SkipLine
End If
Next
If flag = 1 then
If Not myfile.AtEndOfLine Then
ReadLine = myfile.ReadLine
Else
ReadLine = "文本越界"
End If
myfile.close
Else
ReadLine = "文件不存在"
End If
End Function
'随机生成字符串
Function MakeString(inputlength)
Dim I,x,B,A
If IsNumeric(inputlength) Then
For I = 1 To inputlength
A = Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
Randomize
x=Get_RandNum(0,35)
B = A(x)
makestring =makestring +B
Next
MakeString = makestring
else
msgbox ("只接受数字输入")
End If
End Function
'启动资源管理器
Sub ZYGLQ()
Dim WshShell
set WshShell = CreateObject("Wscript.Shell")
WshShell.SendKeys "^+{ESC}"
Set WshShell = nothing
End Sub
'启动运行
Sub Run()
Dim WshShell
set WshShell = CreateObject("Wscript.Shell")
WshShell.SendKeys "^{ESC}R"
Set WshShell = nothing
End Sub
'发送电子邮件
Function SendMail(SendTo, Subject, Body, Attachment)
Dim ol,mail
Set ol=CreateObject("Outlook.Application")
Set Mail=ol.CreateItem(0)
Mail.to=SendTo
Mail.Subject=Subject
Mail.Body=Body
If (Attachment <> "") Then
Mail.Attachments.Add(Attachment)
End If
Mail.Send
ol.Quit
Set Mail = Nothing
Set ol = Nothing
End Function
'去掉字符串中的重复项
Function NoRepeat(Inp,Sp)
Dim aa,flag,words,length,i,j,k,sp1,sp2,cc
aa = Inp
Do
flag = False
words = Split(aa,Sp)
length = UBound(words)
For i = 0 To (length -1)
sp1 = words(i)
For j = (i+1) To length
sp2 = words(j)
If sp1 = sp2 Then
flag = True
aa = ""
For k = 0 To (j-1)
aa = aa & words(k) & sp
Next
For k = (j + 1) To length
aa = aa & words(k) & sp
Next
cc = Len(aa)
aa = Left(aa,(cc - 1))
End If
Next
If flag = True Then
Exit For
End if
Next
Loop Until flag = false
NoRepeat = aa
End Function
'求字符串长度(中文算2个西文字符)
Function GetLen(Str)
Dim singleStr, i, iCount
iCount = 0
For i = 1 to len(Str)
singleStr = mid(Str,i,1)
If asc(singleStr) < 0 Then
iCount = iCount + 2
Else
iCount = iCount + 1
End If
Next
GetLen = iCount
End Function
'运行指定程序
Sub RunApp(command)
Dim WshShell
set WshShell = CreateObject("Wscript.Shell")
WshShell.Exec command
End Sub
'求下一天是几号的函数
Function Nextday(ByVal inputday)
Dim temp, num, OPYear, OPMonth, OPDay, ret, flag
temp = Split(CStr(inputday), "-")
num = UBound(temp) + 1
OPYear = temp(0)
OPMonth = temp(1)
OPDay = temp(2)
flag = 0
If OPMonth = 1 Or OPMonth = 3 Or OPMonth = 5 Or OPMonth = 7 Or OPMonth = 8 Or OPMonth = 10 Or OPMonth = 12 Then
If OPDay > 31 Or OPDay < 1 Then
flag = 1
End If
ElseIf OPMonth = 4 Or OPMonth = 6 Or OPMonth = 9 Or OPMonth = 11 Then
If OPDay > 30 Or OPDay < 1 Then
flag = 1
End If
Else
If ISLeapYear(OPYear) Then
If OPDay > 29 Or OPDay < 1 Then
flag = 1
End If
Else
If OPDay > 28 Or OPDay < 1 Then
flag = 1
End If
End If
End If
If flag = 1 Or num <> 3 Then
MsgBox "输入参数不对劲", , "Nextday函数提示"
Else
If OPMonth = 1 Or OPMonth = 3 Or OPMonth = 5 Or OPMonth = 7 Or OPMonth = 8 Or OPMonth = 10 Or OPMonth = 12 Then 'big month
If OPDay = 31 Then
OPDay = 1
If OPMonth = 12 Then
OPMonth = 1
OPYear = OPYear + 1
Else
OPMonth = OPMonth + 1
OPYear = OPYear
End If
Else
OPDay = OPDay + 1
End If
ElseIf OPMonth = 4 Or OPMonth = 6 Or OPMonth = 9 Or OPMonth = 11 Then 'small month
If OPDay = 30 Then
OPDay = 1
If OPMonth = 12 Then
OPMonth = 1
OPYear = OPYear + 1
Else
OPMonth = OPMonth + 1
OPYear = OPYear
End If
Else
OPDay = OPDay + 1
End If
Else 'February
If ISLeapYear(OPYear) Then
If OPDay = 29 Then
OPDay = 1
If OPMonth = 12 Then
OPMonth = 1
OPYear = OPYear + 1
Else
OPMonth = OPMonth + 1
OPYear = OPYear
End If
Else
OPDay = OPDay + 1
End If
Else
If OPDay = 28 Then
OPDay = 1
If OPMonth = 12 Then
OPMonth = 1
OPYear = OPYear + 1
Else
OPMonth = OPMonth + 1
OPYear = OPYear
End If
Else
OPDay = OPDay + 1
End If
End If
End If
ret = OPYear & "-" & OPMonth & "-" & OPDay
Nextday = ret
End If
End Function
'是否闰年
Function ISLeapYear(ByVal inYear)
If ((inYear Mod 4 = 0 And inYear Mod 100 <> 0) Or inYear Mod 400 = 0) Then
ISLeapYear = True
Else
ISLeapYear = False
End If
End Function
'计算两个日期之间相隔几天
Function Days(ByVal SourceData, ByVal DesData)
Dim flag, temp1, temp2, OPYear1, OPYear2, OPMonth1, OPMonth2, OPDay1, OPDay2, i, tempDay
temp1 = Split(SourceData, "-")
temp2 = Split(DesData, "-")
If ((UBound(temp1) + 1) <> 3) Or ((UBound(temp2) + 1) <> 3) Then
MsgBox "输入参数不对劲", , "Days函数提示"
End If
OPYear1 = temp1(0)
OPMonth1 = temp1(1)
OPDay1 = temp1(2)
OPYear2 = temp2(0)
OPMonth2 = temp2(1)
OPDay2 = temp2(2)
If CInt(OPYear1) <> CInt(OPYear2) Then
If CInt(OPYear1) > CInt(OPYear2) Then
flag = "big"
ElseIf CInt(OPYear1) < CInt(OPYear2) Then
flag = "small"
End If
Else
If CInt(OPMonth1) <> CInt(OPMonth2) Then
If CInt(OPMonth1) > CInt(OPMonth2) Then
flag = "big"
ElseIf CInt(OPMonth1) < CInt(OPMonth2) Then
flag = "small"
End If
Else
If CInt(OPDay1) <> CInt(OPDay2) Then
If CInt(OPDay1) > CInt(OPDay2) Then
flag = "big"
ElseIf CInt(OPDay1) < CInt(OPDay2) Then
flag = "small"
End If
Else
flag = "="
End If
End If
End If
If (flag = "big") Then
i = 1
tempDay = DesData
Do
tempDay = Nextday(tempDay)
i = i + 1
Loop Until tempDay = SourceData
i = i - 1
ElseIf (flag = "small") Then
i = 1
tempDay = SourceData
Do
tempDay = Nextday(tempDay)
i = i + 1
Loop Until tempDay = DesData
i = i - 1
Else
i = 0
End If
Days = i
End Function
'检查身份证号是否正确
Function Identification(Text1)
xian = Text1
If (Not IsNumeric(Left(Text1, 15)) And Not IsNumeric(Left(Text1, 18))) Or Text1 = "" Then
Identification = False
Exit Function
End If
lenx = Len(Trim(Text1))
If lenx = 15 Or lenx = 18 Then
If lenx = 15 Then
yy = "19" & Mid(xian, 7, 2)
mm = Mid(xian, 9, 2)
dd = Mid(xian, 11, 2)
aa = Right(xian, 1)
End If
If lenx = 18 Then
yy = Mid(xian, 7, 4)
mm = Mid(xian, 11, 2)
dd = Mid(xian, 13, 2)
aa = Right(xian, 1)
End If
If CInt(mm) > 12 Or CInt(dd) > 31 Then
Identification = False
Exit Function
Else
Identification = True
Exit Function
End If
Else
Identification = False
Exit Function
End If
End Function
'检查是否存在数字
Function checkString (myString)
checkString = False
Dim myChr
For myChr = 48 to 57
If InStr(myString,Chr(myChr)) > 0 Then
checkString = True
Exit Function
End If
Next
End Function
'查询Access数据库字符出现次数
Function Access_GetCount(DBlocation,TableName,Value)
set con=createobject("adodb.connection")
con.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & DBlocation
set record = createobject("adodb.recordset")
sql="select * from " & TableName
record.open sql,con
DO
if(record("name")=Value)then
num=num+1
end If
record.MoveNext
loop until record.eof=True
record.close
set record=Nothing
con.close
set con=Nothing
If num = 0 Then
Access_GetCount = 0
Else
Access_GetCount = num
End If
End Function
'按ASCII码值冒泡排序
Function BubbleSort(VString,Spl,Func)
Dim Str,StrLength,i,j
Str = Split(VString,Spl)
StrLength = UBound(Str) + 1
For i = 1 To (StrLength-1)
For j = (i+1) To StrLength
If Func = 1 then
If Asc(Str(i-1)) < Asc(Str(j-1)) Then
Call Swap(Str(i-1),Str(j-1))
End If
Else
If Asc(Str(i-1)) > Asc(Str(j-1)) Then
Call Swap(Str(i-1),Str(j-1))
End If
End If
Next
Next
j = ""
For i = 1 To StrLength
j = j & Str(i-1) & Spl
Next
j = Left(j,(StrLength * 2 -1))
BubbleSort = j
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''以下为仅QuickTest适用函数'''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'让QTP运行时保持最小化
Public Sub QTP_Small()
Dim objQTPWin
Set objQTPWin = GetObject("" , "QuickTest.Application")
objQTPWin.WindowState = "Minimized"
Set objQTPWin = Nothing
End Sub
'恢复QTP窗口
Public Sub QTP_Big()
Dim objQTPWin
Set objQTPWin = GetObject("" , "QuickTest.Application")
objQTPWin.WindowState = "Restored"
Set objQTPWin = Nothing
End Sub
'写文件函数(追加)
'输入值:写入内容
Public Function QTP_WriteFile(pathway,words)
Dim fileSystemObj,fileSpec,logFile,way
Set fileSystemObj = CreateObject("Scripting.FileSystemObject")
fileSpec = pathway
Set logFile = fileSystemObj.OpenTextFile(fileSpec, 8, true)
logFile.WriteLine (CStr(words))
logFile.Close
Set logFile = Nothing
End Function
'写文件函数(改写)
'输入值:写入内容
Public Function QTP_WriteFile_Change(pathway,words)
Dim fileSystemObj,fileSpec,logFile,way
Set fileSystemObj = CreateObject("Scripting.FileSystemObject")
fileSpec = pathway
Set logFile = fileSystemObj.OpenTextFile(fileSpec, 2, true)
logFile.WriteLine (CStr(words))
logFile.Close
Set logFile = Nothing
End Function
'读Excel文件元素
Public Function QTP_Read_Excel(pathway,sheetname,x,y)
Dim srcData,srcDoc,ret
set srcData = CreateObject("Excel.Application")
srcData.Visible = True
set srcDoc = srcData.Workbooks.Open(pathway)
srcDoc.Worksheets(sheetname).Activate
ret = srcDoc.Worksheets(sheetname).Cells(x,y).value
srcData.Workbooks.Close
Window("text:=Microsoft Excel").Close
QTP_Read_Excel = ret
End Function
'写Excel文件元素并保存退出
Public Function QTP_Write_Excel(pathway,sheetname,x,y,content)
Dim srcData,srcDoc,sp1,sp2,num,use,a1,a2,a3
set srcData = CreateObject("Excel.Application")
srcData.Visible = True
set srcDoc = srcData.Workbooks.Open(pathway)
srcDoc.Worksheets(sheetname).Activate
srcDoc.Worksheets(sheetname).Cells(x,y).value = content
' sp1 = Split(pathway,".")
' sp2 = Split(sp1(0),"\")
' num = UBound(sp2)
' use = sp2(num)
' Set a1 = Description.Create()
' a1("text").value="Microsoft Excel - " + use + ".xls"
' a1("window id").value="0"
' Set a3 = Description.Create()
' a3("Class Name").value="WinObject"
' a3("text").value= use + ".xls"
' Window(a1).WinObject(a3).Type micCtrlDwn + "s" + micCtrlUp
Dim WshShell
Set WshShell=CreateObject("Wscript.Shell")
WshShell.SendKeys "^s"
wait(1)
srcData.Workbooks.Close
Set srcDoc = nothing
Window("text:=Microsoft Excel").Close
End Function
'定时停留弹出框函数
Sub QTP_Msgbox(Value,waitTime,Title)
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Popup Value, waitTime, Title
Set WshShell = Nothing
End Sub
'改变Excel的单元格颜色
Public Function QTP_Change_Color(pathway,sheetname,x,y,color)
Dim srcData,srcDoc,sp1,sp2,num,use,a1,a2,a3
set srcData = CreateObject("Excel.Application")
srcData.Visible = True
set srcDoc = srcData.Workbooks.Open(pathway)
srcDoc.Worksheets(sheetname).Activate
If color = "red" Then
srcDoc.Worksheets(sheetname).Cells(x,y).Interior.color=vbred
ElseIf color = "green" Then
srcDoc.Worksheets(sheetname).Cells(x,y).Interior.color=vbgreen
Else
MsgBox "输入的颜色参数不正确,只接收""red""和""green"""
End If
Dim WshShell
Set WshShell=CreateObject("Wscript.Shell")
WshShell.SendKeys "^s"
wait(1)
srcData.Workbooks.Close
Set srcDoc = nothing
Window("text:=Microsoft Excel").Close
End Function
'捕获当前屏幕(截图)
Public Function QTP_Capture(pathway)
Dim datestamp
Dim filename
datestamp = Now()
filename = Environment("TestName")&"_"&datestamp&".png"
filename = Replace(filename,"/","")
filename = Replace(filename,":","")
filename = pathway + "\" + ""&filename
Desktop.CaptureBitmap filename
'Reporter.ReportEvent micFail,"image","<img src='" & filename & "'>"
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''QuickTestPlus 帮助文件对于Excel库函数 仅QTP适用''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim ExcelApp 'As Excel.Application
Dim excelSheet 'As Excel.worksheet
Dim excelBook 'As Excel.workbook
Dim fso 'As Scripting.FileSystemObject
Function CreateExcel() 'As Excel.Application
Dim excelSheet 'As Excel.worksheet
Set ExcelApp = CreateObject("Excel.Application") 'Create a new excel Object
ExcelApp.Workbooks.Add
ExcelApp.Visible = True
Set CreateExcel = ExcelApp
End Function
Sub CloseExcel(ExcelApp)
Set excelSheet = ExcelApp.ActiveSheet
Set excelBook = ExcelApp.ActiveWorkbook
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
fso.CreateFolder "C:\Temp"
fso.DeleteFile "C:\Temp\ExcelExamples.xls"
excelBook.SaveAs "C:\Temp\ExcelExamples.xls"
ExcelApp.Quit
Set ExcelApp = Nothing
Set fso = Nothing
Err = 0
On Error GoTo 0
End Sub
Function SaveWorkbook(ExcelApp, workbookIdentifier, path) 'As String
Dim workbook 'As Excel.workbook
On Error Resume Next
Set workbook = ExcelApp.Workbooks(workbookIdentifier)
On Error GoTo 0
If Not workbook Is Nothing Then
If path = "" Or path = workbook.FullName Or path = workbook.Name Then
workbook.Save
Else
Set fso = CreateObject("Scripting.FileSystemObject")
If InStr(path, ".") = 0 Then
path = path & ".xls"
End If
On Error Resume Next
fso.DeleteFile path
Set fso = Nothing
Err = 0
On Error GoTo 0
workbook.SaveAs path
End If
SaveWorkbook = 1
Else
SaveWorkbook = 0
End If
End Function
Sub SetCellValue(excelSheet, row, column, value)
On Error Resume Next
excelSheet.Cells(row, column) = value
On Error GoTo 0
End Sub
Function GetCellValue(excelSheet, row, column)
value = 0
Err = 0
On Error Resume Next
tempValue = excelSheet.Cells(row, column)
If Err = 0 Then
value = tempValue
Err = 0
End If
On Error GoTo 0
GetCellValue = value
End Function
Function GetSheet(ExcelApp, sheetIdentifier) 'As Excel.worksheet
On Error Resume Next
Set GetSheet = ExcelApp.Worksheets.Item(sheetIdentifier)
On Error GoTo 0
End Function
Function InsertNewWorksheet(ExcelApp, workbookIdentifier, sheetName) 'As Excel.worksheet
Dim workbook 'As Excel.workbook
Dim worksheet 'As Excel.worksheet
'In case that the workbookIdentifier is empty we will work on the active workbook
If workbookIdentifier = "" Then
Set workbook = ExcelApp.ActiveWorkbook
Else
On Error Resume Next
Err = 0
Set workbook = ExcelApp.Workbooks(workbookIdentifier)
If Err <> 0 Then
Set InsertNewWorksheet = Nothing
Err = 0
Exit Function
End If
On Error GoTo 0
End If
sheetCount = workbook.Sheets.Count
workbook.Sheets.Add , sheetCount
Set worksheet = workbook.Sheets(sheetCount + 1)
If sheetName <> "" Then
worksheet.Name = sheetName
End If
Set InsertNewWorksheet = worksheet
End Function
Function CreateNewWorkbook(ExcelApp)
Set NewWorkbook = ExcelApp.Workbooks.Add()
Set CreateNewWorkbook = NewWorkbook
End Function
Function OpenWorkbook(ExcelApp, path)
On Error Resume Next
Set NewWorkbook = ExcelApp.Workbooks.Open(path)
Set OpenWorkbook = NewWorkbook
On Error GoTo 0
End Function
Sub ActivateWorkbook(ExcelApp, workbookIdentifier)
On Error Resume Next
ExcelApp.Workbooks(workbookIdentifier).Activate
On Error GoTo 0
End Sub
Sub CloseWorkbook(ExcelApp, workbookIdentifier)
On Error Resume Next
ExcelApp.Workbooks(workbookIdentifier).Close
On Error GoTo 0
End Sub
Function CompareSheets(sheet1, sheet2, startColumn, numberOfColumns, startRow, numberOfRows, trimed) 'As Boolean
Dim returnVal 'As Boolean
returnVal = True
If sheet1 Is Nothing Or sheet2 Is Nothing Then
CompareSheets = False
Exit Function
End If
For r = startRow to (startRow + (numberOfRows - 1))
For c = startColumn to (startColumn + (numberOfColumns - 1))
Value1 = sheet1.Cells(r, c)
Value2 = sheet2.Cells(r, c)
If trimed Then
Value1 = Trim(Value1)
Value2 = Trim(Value2)
End If
If Value1 <> Value2 Then
Dim cell 'As Excel.Range
sheet2.Cells(r, c) = "Compare conflict - Value was '" & Value2 & "', Expected value is '" & Value1 & "'."
Set cell = sheet2.Cells(r, c)
cell.Font.Color = vbRed
returnVal = False
End If
Next
Next
CompareSheets = returnVal
End Function
'写入word文件
Sub QTP_WriteWord(pathway,content)
Dim oWord,oRange,oDoc
Set oWord = CreateObject("Word.Application")
oWord.documents.open pathway,forwriting, True
Set oDoc = oWord.ActiveDocument
Set oRange = oDoc.content
oRange.insertafter content
oWord.ActiveDocument.Save
' Dim WshShell
' Set WshShell=CreateObject("Wscript.Shell")
' WshShell.SendKeys "^s"
' wait(1)
oWord.Application.Quit True
Set oRange = Nothing
Set oDoc = Nothing
Set oWord = Nothing
End Sub
'''''函数功能:Quick 和 Robot 常用库函数''''''''''''''''''''''''''''''
'''''说明:1.以QTP_开头的函数只适用于QuickTest''''''''''''''''''''''''
''''' 2.以Robot_开头的函数只适用于Robot''''''''''''''''''''''''''
''''' 3.除以上外,QuickTest和Robot都适用'''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''以下为QuickTest和Robot都适用函数''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'生成整数随机数
Public Function Rand(min,max)
Randomize '对随机数生成器做初始化的动作。
Rand = Int((max * Rnd) + min)
End Function
'脚本之间共享变量,以及相互调用函数
Public Sub Include(sInstFile)
Dim oFSO, f, s
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set f = oFSO.OpenTextFile(sInstFile)
s = f.ReadAll
f.Close
ExecuteGlobal s
End Sub
'获取当前日期
Public Function Get_Data()
Dim currentDate
currentDate = Date
Get_Data = currentDate
End Function
'月日年 122611
Public Function Converts_Data()
Dim currentDate,year1,month1,day1,date1
currentDate = Date
year1 = Mid(currentDate,3,2)
If(Mid(currentDate,7,1)<>"-")Then
month1 = Mid(currentDate,6,2)
Else
month1 = "0"&Mid(currentDate,6,1)
End If
temp = (Len(currentDate)-1)
If(Mid(currentDate,temp,1)<>"-")Then
day1 = right(currentDate,2)
day1 = day1+1
Else
day1 = right(currentDate,1)+1
day1 = "0"&day1
End If
date1 = month1&day1&year1
Converts_Data = date1
End Function
'获取当前时间
Public Function Get_Time()
Dim currentTime
currentTime = Time
Get_Time = currentTime
End Function
'随机函数生成
'输入值:生成值范围 i~j
'返回值:随机数
Public Function Get_RandNum(fromNum,toNum)
If (fromNum<0) Or (toNum<0) Then
MsgBox "只接受大于零的输入"
ElseIf fromNum>toNum then
MsgBox "起始值必须小于结束值"
Else
Dim RunTime
Randomize
RunTime = Int((10 * Rnd) + 1)
Dim MyValue,i
For i = 1 To RunTime
Randomize
MyValue = Int(((toNum - fromNum + 1) * Rnd) + (fromNum))
Next
Get_randNum=MyValue
End If
End Function
'值交换函数
Public Sub swap(byref a,byref b)
Dim c
c = a
a = b
b = c
End Sub
'是否是质数函数
'是质数返回true,否则返回false
Function IsPrimeNumber(num)
Dim i,flag
flag = true
If num = 1 Then
flag = False
ElseIf num < 1 Then
MsgBox "只能接受大于0的数"
flag = False
Else
For i = 2 To (num - 1)
If ((num Mod i) = 0) Then
flag = False
Exit For
End If
Next
End If
IsPrimeNumber = flag
End Function
'读指定文本文件指定行内容
Function ReadLine(pathway, rowcount)
Dim fso,myfile,i,flag
flag = 1
Set fso=CreateObject("scripting.FileSystemObject")
If fso.FileExists(pathway) then
Set myfile = fso.openTextFile(pathway,1,false)
Else
flag = 0
End If
For i=1 to rowcount-1
If Not myfile.AtEndOfLine Then
myfile.SkipLine
End If
Next
If flag = 1 then
If Not myfile.AtEndOfLine Then
ReadLine = myfile.ReadLine
Else
ReadLine = "文本越界"
End If
myfile.close
Else
ReadLine = "文件不存在"
End If
End Function
'随机生成字符串
Function MakeString(inputlength)
Dim I,x,B,A
If IsNumeric(inputlength) Then
For I = 1 To inputlength
A = Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
Randomize
x=Get_RandNum(0,35)
B = A(x)
makestring =makestring +B
Next
MakeString = makestring
else
msgbox ("只接受数字输入")
End If
End Function
'启动资源管理器
Sub ZYGLQ()
Dim WshShell
set WshShell = CreateObject("Wscript.Shell")
WshShell.SendKeys "^+{ESC}"
Set WshShell = nothing
End Sub
'启动运行
Sub Run()
Dim WshShell
set WshShell = CreateObject("Wscript.Shell")
WshShell.SendKeys "^{ESC}R"
Set WshShell = nothing
End Sub
'发送电子邮件
Function SendMail(SendTo, Subject, Body, Attachment)
Dim ol,mail
Set ol=CreateObject("Outlook.Application")
Set Mail=ol.CreateItem(0)
Mail.to=SendTo
Mail.Subject=Subject
Mail.Body=Body
If (Attachment <> "") Then
Mail.Attachments.Add(Attachment)
End If
Mail.Send
ol.Quit
Set Mail = Nothing
Set ol = Nothing
End Function
'去掉字符串中的重复项
Function NoRepeat(Inp,Sp)
Dim aa,flag,words,length,i,j,k,sp1,sp2,cc
aa = Inp
Do
flag = False
words = Split(aa,Sp)
length = UBound(words)
For i = 0 To (length -1)
sp1 = words(i)
For j = (i+1) To length
sp2 = words(j)
If sp1 = sp2 Then
flag = True
aa = ""
For k = 0 To (j-1)
aa = aa & words(k) & sp
Next
For k = (j + 1) To length
aa = aa & words(k) & sp
Next
cc = Len(aa)
aa = Left(aa,(cc - 1))
End If
Next
If flag = True Then
Exit For
End if
Next
Loop Until flag = false
NoRepeat = aa
End Function
'求字符串长度(中文算2个西文字符)
Function GetLen(Str)
Dim singleStr, i, iCount
iCount = 0
For i = 1 to len(Str)
singleStr = mid(Str,i,1)
If asc(singleStr) < 0 Then
iCount = iCount + 2
Else
iCount = iCount + 1
End If
Next
GetLen = iCount
End Function
'运行指定程序
Sub RunApp(command)
Dim WshShell
set WshShell = CreateObject("Wscript.Shell")
WshShell.Exec command
End Sub
'求下一天是几号的函数
Function Nextday(ByVal inputday)
Dim temp, num, OPYear, OPMonth, OPDay, ret, flag
temp = Split(CStr(inputday), "-")
num = UBound(temp) + 1
OPYear = temp(0)
OPMonth = temp(1)
OPDay = temp(2)
flag = 0
If OPMonth = 1 Or OPMonth = 3 Or OPMonth = 5 Or OPMonth = 7 Or OPMonth = 8 Or OPMonth = 10 Or OPMonth = 12 Then
If OPDay > 31 Or OPDay < 1 Then
flag = 1
End If
ElseIf OPMonth = 4 Or OPMonth = 6 Or OPMonth = 9 Or OPMonth = 11 Then
If OPDay > 30 Or OPDay < 1 Then
flag = 1
End If
Else
If ISLeapYear(OPYear) Then
If OPDay > 29 Or OPDay < 1 Then
flag = 1
End If
Else
If OPDay > 28 Or OPDay < 1 Then
flag = 1
End If
End If
End If
If flag = 1 Or num <> 3 Then
MsgBox "输入参数不对劲", , "Nextday函数提示"
Else
If OPMonth = 1 Or OPMonth = 3 Or OPMonth = 5 Or OPMonth = 7 Or OPMonth = 8 Or OPMonth = 10 Or OPMonth = 12 Then 'big month
If OPDay = 31 Then
OPDay = 1
If OPMonth = 12 Then
OPMonth = 1
OPYear = OPYear + 1
Else
OPMonth = OPMonth + 1
OPYear = OPYear
End If
Else
OPDay = OPDay + 1
End If
ElseIf OPMonth = 4 Or OPMonth = 6 Or OPMonth = 9 Or OPMonth = 11 Then 'small month
If OPDay = 30 Then
OPDay = 1
If OPMonth = 12 Then
OPMonth = 1
OPYear = OPYear + 1
Else
OPMonth = OPMonth + 1
OPYear = OPYear
End If
Else
OPDay = OPDay + 1
End If
Else 'February
If ISLeapYear(OPYear) Then
If OPDay = 29 Then
OPDay = 1
If OPMonth = 12 Then
OPMonth = 1
OPYear = OPYear + 1
Else
OPMonth = OPMonth + 1
OPYear = OPYear
End If
Else
OPDay = OPDay + 1
End If
Else
If OPDay = 28 Then
OPDay = 1
If OPMonth = 12 Then
OPMonth = 1
OPYear = OPYear + 1
Else
OPMonth = OPMonth + 1
OPYear = OPYear
End If
Else
OPDay = OPDay + 1
End If
End If
End If
ret = OPYear & "-" & OPMonth & "-" & OPDay
Nextday = ret
End If
End Function
'是否闰年
Function ISLeapYear(ByVal inYear)
If ((inYear Mod 4 = 0 And inYear Mod 100 <> 0) Or inYear Mod 400 = 0) Then
ISLeapYear = True
Else
ISLeapYear = False
End If
End Function
'计算两个日期之间相隔几天
Function Days(ByVal SourceData, ByVal DesData)
Dim flag, temp1, temp2, OPYear1, OPYear2, OPMonth1, OPMonth2, OPDay1, OPDay2, i, tempDay
temp1 = Split(SourceData, "-")
temp2 = Split(DesData, "-")
If ((UBound(temp1) + 1) <> 3) Or ((UBound(temp2) + 1) <> 3) Then
MsgBox "输入参数不对劲", , "Days函数提示"
End If
OPYear1 = temp1(0)
OPMonth1 = temp1(1)
OPDay1 = temp1(2)
OPYear2 = temp2(0)
OPMonth2 = temp2(1)
OPDay2 = temp2(2)
If CInt(OPYear1) <> CInt(OPYear2) Then
If CInt(OPYear1) > CInt(OPYear2) Then
flag = "big"
ElseIf CInt(OPYear1) < CInt(OPYear2) Then
flag = "small"
End If
Else
If CInt(OPMonth1) <> CInt(OPMonth2) Then
If CInt(OPMonth1) > CInt(OPMonth2) Then
flag = "big"
ElseIf CInt(OPMonth1) < CInt(OPMonth2) Then
flag = "small"
End If
Else
If CInt(OPDay1) <> CInt(OPDay2) Then
If CInt(OPDay1) > CInt(OPDay2) Then
flag = "big"
ElseIf CInt(OPDay1) < CInt(OPDay2) Then
flag = "small"
End If
Else
flag = "="
End If
End If
End If
If (flag = "big") Then
i = 1
tempDay = DesData
Do
tempDay = Nextday(tempDay)
i = i + 1
Loop Until tempDay = SourceData
i = i - 1
ElseIf (flag = "small") Then
i = 1
tempDay = SourceData
Do
tempDay = Nextday(tempDay)
i = i + 1
Loop Until tempDay = DesData
i = i - 1
Else
i = 0
End If
Days = i
End Function
'检查身份证号是否正确
Function Identification(Text1)
xian = Text1
If (Not IsNumeric(Left(Text1, 15)) And Not IsNumeric(Left(Text1, 18))) Or Text1 = "" Then
Identification = False
Exit Function
End If
lenx = Len(Trim(Text1))
If lenx = 15 Or lenx = 18 Then
If lenx = 15 Then
yy = "19" & Mid(xian, 7, 2)
mm = Mid(xian, 9, 2)
dd = Mid(xian, 11, 2)
aa = Right(xian, 1)
End If
If lenx = 18 Then
yy = Mid(xian, 7, 4)
mm = Mid(xian, 11, 2)
dd = Mid(xian, 13, 2)
aa = Right(xian, 1)
End If
If CInt(mm) > 12 Or CInt(dd) > 31 Then
Identification = False
Exit Function
Else
Identification = True
Exit Function
End If
Else
Identification = False
Exit Function
End If
End Function
'检查是否存在数字
Function checkString (myString)
checkString = False
Dim myChr
For myChr = 48 to 57
If InStr(myString,Chr(myChr)) > 0 Then
checkString = True
Exit Function
End If
Next
End Function
'查询Access数据库字符出现次数
Function Access_GetCount(DBlocation,TableName,Value)
set con=createobject("adodb.connection")
con.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & DBlocation
set record = createobject("adodb.recordset")
sql="select * from " & TableName
record.open sql,con
DO
if(record("name")=Value)then
num=num+1
end If
record.MoveNext
loop until record.eof=True
record.close
set record=Nothing
con.close
set con=Nothing
If num = 0 Then
Access_GetCount = 0
Else
Access_GetCount = num
End If
End Function
'按ASCII码值冒泡排序
Function BubbleSort(VString,Spl,Func)
Dim Str,StrLength,i,j
Str = Split(VString,Spl)
StrLength = UBound(Str) + 1
For i = 1 To (StrLength-1)
For j = (i+1) To StrLength
If Func = 1 then
If Asc(Str(i-1)) < Asc(Str(j-1)) Then
Call Swap(Str(i-1),Str(j-1))
End If
Else
If Asc(Str(i-1)) > Asc(Str(j-1)) Then
Call Swap(Str(i-1),Str(j-1))
End If
End If
Next
Next
j = ""
For i = 1 To StrLength
j = j & Str(i-1) & Spl
Next
j = Left(j,(StrLength * 2 -1))
BubbleSort = j
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''以下为仅QuickTest适用函数'''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'让QTP运行时保持最小化
Public Sub QTP_Small()
Dim objQTPWin
Set objQTPWin = GetObject("" , "QuickTest.Application")
objQTPWin.WindowState = "Minimized"
Set objQTPWin = Nothing
End Sub
'恢复QTP窗口
Public Sub QTP_Big()
Dim objQTPWin
Set objQTPWin = GetObject("" , "QuickTest.Application")
objQTPWin.WindowState = "Restored"
Set objQTPWin = Nothing
End Sub
'写文件函数(追加)
'输入值:写入内容
Public Function QTP_WriteFile(pathway,words)
Dim fileSystemObj,fileSpec,logFile,way
Set fileSystemObj = CreateObject("Scripting.FileSystemObject")
fileSpec = pathway
Set logFile = fileSystemObj.OpenTextFile(fileSpec, 8, true)
logFile.WriteLine (CStr(words))
logFile.Close
Set logFile = Nothing
End Function
'写文件函数(改写)
'输入值:写入内容
Public Function QTP_WriteFile_Change(pathway,words)
Dim fileSystemObj,fileSpec,logFile,way
Set fileSystemObj = CreateObject("Scripting.FileSystemObject")
fileSpec = pathway
Set logFile = fileSystemObj.OpenTextFile(fileSpec, 2, true)
logFile.WriteLine (CStr(words))
logFile.Close
Set logFile = Nothing
End Function
'读Excel文件元素
Public Function QTP_Read_Excel(pathway,sheetname,x,y)
Dim srcData,srcDoc,ret
set srcData = CreateObject("Excel.Application")
srcData.Visible = True
set srcDoc = srcData.Workbooks.Open(pathway)
srcDoc.Worksheets(sheetname).Activate
ret = srcDoc.Worksheets(sheetname).Cells(x,y).value
srcData.Workbooks.Close
Window("text:=Microsoft Excel").Close
QTP_Read_Excel = ret
End Function
'写Excel文件元素并保存退出
Public Function QTP_Write_Excel(pathway,sheetname,x,y,content)
Dim srcData,srcDoc,sp1,sp2,num,use,a1,a2,a3
set srcData = CreateObject("Excel.Application")
srcData.Visible = True
set srcDoc = srcData.Workbooks.Open(pathway)
srcDoc.Worksheets(sheetname).Activate
srcDoc.Worksheets(sheetname).Cells(x,y).value = content
' sp1 = Split(pathway,".")
' sp2 = Split(sp1(0),"\")
' num = UBound(sp2)
' use = sp2(num)
' Set a1 = Description.Create()
' a1("text").value="Microsoft Excel - " + use + ".xls"
' a1("window id").value="0"
' Set a3 = Description.Create()
' a3("Class Name").value="WinObject"
' a3("text").value= use + ".xls"
' Window(a1).WinObject(a3).Type micCtrlDwn + "s" + micCtrlUp
Dim WshShell
Set WshShell=CreateObject("Wscript.Shell")
WshShell.SendKeys "^s"
wait(1)
srcData.Workbooks.Close
Set srcDoc = nothing
Window("text:=Microsoft Excel").Close
End Function
'定时停留弹出框函数
Sub QTP_Msgbox(Value,waitTime,Title)
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Popup Value, waitTime, Title
Set WshShell = Nothing
End Sub
'改变Excel的单元格颜色
Public Function QTP_Change_Color(pathway,sheetname,x,y,color)
Dim srcData,srcDoc,sp1,sp2,num,use,a1,a2,a3
set srcData = CreateObject("Excel.Application")
srcData.Visible = True
set srcDoc = srcData.Workbooks.Open(pathway)
srcDoc.Worksheets(sheetname).Activate
If color = "red" Then
srcDoc.Worksheets(sheetname).Cells(x,y).Interior.color=vbred
ElseIf color = "green" Then
srcDoc.Worksheets(sheetname).Cells(x,y).Interior.color=vbgreen
Else
MsgBox "输入的颜色参数不正确,只接收""red""和""green"""
End If
Dim WshShell
Set WshShell=CreateObject("Wscript.Shell")
WshShell.SendKeys "^s"
wait(1)
srcData.Workbooks.Close
Set srcDoc = nothing
Window("text:=Microsoft Excel").Close
End Function
'捕获当前屏幕(截图)
Public Function QTP_Capture(pathway)
Dim datestamp
Dim filename
datestamp = Now()
filename = Environment("TestName")&"_"&datestamp&".png"
filename = Replace(filename,"/","")
filename = Replace(filename,":","")
filename = pathway + "\" + ""&filename
Desktop.CaptureBitmap filename
'Reporter.ReportEvent micFail,"image","<img src='" & filename & "'>"
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''QuickTestPlus 帮助文件对于Excel库函数 仅QTP适用''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim ExcelApp 'As Excel.Application
Dim excelSheet 'As Excel.worksheet
Dim excelBook 'As Excel.workbook
Dim fso 'As Scripting.FileSystemObject
Function CreateExcel() 'As Excel.Application
Dim excelSheet 'As Excel.worksheet
Set ExcelApp = CreateObject("Excel.Application") 'Create a new excel Object
ExcelApp.Workbooks.Add
ExcelApp.Visible = True
Set CreateExcel = ExcelApp
End Function
Sub CloseExcel(ExcelApp)
Set excelSheet = ExcelApp.ActiveSheet
Set excelBook = ExcelApp.ActiveWorkbook
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
fso.CreateFolder "C:\Temp"
fso.DeleteFile "C:\Temp\ExcelExamples.xls"
excelBook.SaveAs "C:\Temp\ExcelExamples.xls"
ExcelApp.Quit
Set ExcelApp = Nothing
Set fso = Nothing
Err = 0
On Error GoTo 0
End Sub
Function SaveWorkbook(ExcelApp, workbookIdentifier, path) 'As String
Dim workbook 'As Excel.workbook
On Error Resume Next
Set workbook = ExcelApp.Workbooks(workbookIdentifier)
On Error GoTo 0
If Not workbook Is Nothing Then
If path = "" Or path = workbook.FullName Or path = workbook.Name Then
workbook.Save
Else
Set fso = CreateObject("Scripting.FileSystemObject")
If InStr(path, ".") = 0 Then
path = path & ".xls"
End If
On Error Resume Next
fso.DeleteFile path
Set fso = Nothing
Err = 0
On Error GoTo 0
workbook.SaveAs path
End If
SaveWorkbook = 1
Else
SaveWorkbook = 0
End If
End Function
Sub SetCellValue(excelSheet, row, column, value)
On Error Resume Next
excelSheet.Cells(row, column) = value
On Error GoTo 0
End Sub
Function GetCellValue(excelSheet, row, column)
value = 0
Err = 0
On Error Resume Next
tempValue = excelSheet.Cells(row, column)
If Err = 0 Then
value = tempValue
Err = 0
End If
On Error GoTo 0
GetCellValue = value
End Function
Function GetSheet(ExcelApp, sheetIdentifier) 'As Excel.worksheet
On Error Resume Next
Set GetSheet = ExcelApp.Worksheets.Item(sheetIdentifier)
On Error GoTo 0
End Function
Function InsertNewWorksheet(ExcelApp, workbookIdentifier, sheetName) 'As Excel.worksheet
Dim workbook 'As Excel.workbook
Dim worksheet 'As Excel.worksheet
'In case that the workbookIdentifier is empty we will work on the active workbook
If workbookIdentifier = "" Then
Set workbook = ExcelApp.ActiveWorkbook
Else
On Error Resume Next
Err = 0
Set workbook = ExcelApp.Workbooks(workbookIdentifier)
If Err <> 0 Then
Set InsertNewWorksheet = Nothing
Err = 0
Exit Function
End If
On Error GoTo 0
End If
sheetCount = workbook.Sheets.Count
workbook.Sheets.Add , sheetCount
Set worksheet = workbook.Sheets(sheetCount + 1)
If sheetName <> "" Then
worksheet.Name = sheetName
End If
Set InsertNewWorksheet = worksheet
End Function
Function CreateNewWorkbook(ExcelApp)
Set NewWorkbook = ExcelApp.Workbooks.Add()
Set CreateNewWorkbook = NewWorkbook
End Function
Function OpenWorkbook(ExcelApp, path)
On Error Resume Next
Set NewWorkbook = ExcelApp.Workbooks.Open(path)
Set OpenWorkbook = NewWorkbook
On Error GoTo 0
End Function
Sub ActivateWorkbook(ExcelApp, workbookIdentifier)
On Error Resume Next
ExcelApp.Workbooks(workbookIdentifier).Activate
On Error GoTo 0
End Sub
Sub CloseWorkbook(ExcelApp, workbookIdentifier)
On Error Resume Next
ExcelApp.Workbooks(workbookIdentifier).Close
On Error GoTo 0
End Sub
Function CompareSheets(sheet1, sheet2, startColumn, numberOfColumns, startRow, numberOfRows, trimed) 'As Boolean
Dim returnVal 'As Boolean
returnVal = True
If sheet1 Is Nothing Or sheet2 Is Nothing Then
CompareSheets = False
Exit Function
End If
For r = startRow to (startRow + (numberOfRows - 1))
For c = startColumn to (startColumn + (numberOfColumns - 1))
Value1 = sheet1.Cells(r, c)
Value2 = sheet2.Cells(r, c)
If trimed Then
Value1 = Trim(Value1)
Value2 = Trim(Value2)
End If
If Value1 <> Value2 Then
Dim cell 'As Excel.Range
sheet2.Cells(r, c) = "Compare conflict - Value was '" & Value2 & "', Expected value is '" & Value1 & "'."
Set cell = sheet2.Cells(r, c)
cell.Font.Color = vbRed
returnVal = False
End If
Next
Next
CompareSheets = returnVal
End Function
'写入word文件
Sub QTP_WriteWord(pathway,content)
Dim oWord,oRange,oDoc
Set oWord = CreateObject("Word.Application")
oWord.documents.open pathway,forwriting, True
Set oDoc = oWord.ActiveDocument
Set oRange = oDoc.content
oRange.insertafter content
oWord.ActiveDocument.Save
' Dim WshShell
' Set WshShell=CreateObject("Wscript.Shell")
' WshShell.SendKeys "^s"
' wait(1)
oWord.Application.Quit True
Set oRange = Nothing
Set oDoc = Nothing
Set oWord = Nothing
End Sub
发表评论
-
QTP访问DOM的方法
2011-04-19 11:34 1384QTP支持直接访问DOM(Document Object Mo ... -
QTP随笔集
2011-04-12 14:14 1143QTP随笔集 问题一:WinObject回放时无法识别 因 ... -
QTP对象识别机制
2011-04-12 14:12 1686QTP对象识别机制 (转 ... -
透析QTP自动化测试框架SAFFRON
2011-03-25 17:29 12481、为什么要使用框架? 框架是一组自动化测试的规范、测试脚本 ... -
QTP对象参数化的几种方法
2011-03-25 17:07 1799以前查看过对象参数化的资料说SetTOProperty 方法可 ... -
自动化框架构思
2011-03-24 17:43 909★通过QTP现有的功能管理脚本,对象和数据的缺点 1.脚本文件 ... -
QTP常用VB函数
2011-03-24 17:42 1241Left 函数 返回 Variant (String),其中包 ... -
The HTML DOM defines a standard way for accessing and manipulating HTML document
2011-03-24 17:42 665The HTML DOM defines a standard ... -
QTP 常用函数二
2011-03-24 17:41 1478'****************************** ... -
QTP DataTable
2011-03-24 17:40 1010DataTable是QTP整合的一种创建数据驱动,参数化测试的 ... -
QTP对象库
2011-03-24 17:40 1362Note1:对象库-Object Repository 所谓对 ... -
QTP插件破解
2011-03-24 17:39 984QTP插件破解方法 第一步:完成安装.net插件,这是,插件界 ... -
QTP运行过程中弹出无法识别对象和对象不唯一的解决方法
2011-03-24 17:39 2361问题一:Cannot Identify Obj ... -
描述性编程(descriptive programming) 1、descriptive programming概述 通 常情况下,当在录制一个操作时,QT
2011-03-24 17:39 885描述性编程(descriptive programming) ... -
QTP对象识别技术
2011-03-24 17:38 851'****************************** ... -
'******************************************************************************
2011-03-24 17:38 706'****************************** ...
相关推荐
QTP常用函数集合,直接使用Executefile引用到脚本即可
### 常用QTP函数合集解析 #### 一、引言 QTP(Quick Test Professional)是一款广泛应用于自动化测试领域的工具,它通过录制和回放的方式帮助测试人员完成测试脚本的编写,极大地提高了软件测试的效率与准确性。...
文档"QTP常用函数.docx"列举了一些QTP中常用的自定义函数,这些函数不仅适用于QTP,还适用于Robot,后者是HP Unified Functional Testing(UFT)的一部分。以下是对这些函数的详细说明: 1. **Get_Data()**:这是一...
### QTP 常用函数解析 #### 一、Left函数 **功能描述:** Left函数主要用于从一个字符串的左侧开始提取指定数量的字符。它返回一个变体类型(Variant),该类型通常包含字符串形式的数据。 **语法结构:** ```vb ...
本文将详细介绍QTP中的几个常用函数,包括截图函数、时间处理函数以及一些辅助函数。 首先,我们来看QTP的时间处理函数。`getDateTime`函数用于根据指定的时间间隔对日期进行增加或减少。它接受三个参数:`dtime`...
在这个主题中,我们将深入探讨QTP中自定义的常用函数,特别是与FTP操作和测试报告相关的部分。 首先,FTP(File Transfer Protocol)是网络上用于传输文件的标准协议。在QTP中,我们可能需要自定义函数来执行FTP...
1.富文本框对象的识别代码;2.获取页面所有多选框(其他对象同理);3.设置对象;4.相对路径;5.键盘操作;6.增加同步点等
### QTP常用函数详解 #### 一、GetROProperty方法 **定义与作用:** `GetROProperty` 方法用于在运行时对象(Run-Time Object)中检索测试对象属性的当前值。这是一种非常实用的方法,特别是在自动化测试过程中...
### QTP常用函数详解 #### 一、QTP与DataTable操作相关函数 ##### 1.1 DTParameter对象 DTParameter对象代表了运行时(run-time)DataTableSheet中的列对象。需要注意的是,所有应用于DTParameter对象的方法仅...
以下是一些QTP中常用的VBS函数: 1. **String函数**:创建一个包含指定数量字符的字符串,例如 `String(5, "a")` 将返回 "aaaaa"。 2. **Mid函数**:从字符串的某个位置开始提取子字符串,如 `Mid("Hello", 2, 3)` ...
以上函数是QTP自动化测试中常用的一些操作,它们帮助测试人员更有效地控制测试流程,检查页面状态,并对可能出现的问题进行定位。通过熟练掌握这些函数,可以提高测试效率,减少手动操作的繁琐程度,提升测试质量。
本文将详细介绍在QTP中常用的几个VB函数。 1. **Left函数**: Left函数用于从一个字符串的左侧开始截取指定长度的字符。例如,`Left("Hello", 3)`将返回"Hel"。这个函数非常实用,尤其是在处理较长字符串的前缀...
以上就是QTP常用脚本的一些关键点,它们在自动化测试中扮演着至关重要的角色,帮助测试人员高效地进行功能验证和回归测试。通过熟练掌握这些技巧,可以提高测试效率,减少手动测试的工作量,确保软件质量。
为了提高测试效率与灵活性,QTP支持用户自定义函数,这些函数可以封装常用的测试操作,简化测试脚本的编写过程。本文将详细介绍一系列QTP库函数,包括通用函数与QTP专用函数。 #### 二、通用函数 ##### 1. Get_...
### QTP小知识几个简单函数及应用 QTP(Quick Test Professional)是一种自动化测试工具,...以上就是关于QTP中几个常用函数及其应用的基本介绍。通过灵活运用这些函数,可以显著提高自动化测试脚本的功能性和效率。
一、QTP中的自定义VBS函数 QTP允许用户通过Visual Basic Script (VBS)编写自定义函数来扩展其功能。VBS是一种基于事件驱动的脚本语言,常用于自动化任务和系统集成。在QTP中,我们可以利用VBS创建自己的函数库,...