日历
| |||||||||
| 日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
| 1 | 2 | 3 | 4 | ||||||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | |||
| 12 | 13 | 14 | 15 | 16 | 17 | 18 | |||
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | |||
| 26 | 27 | 28 | 29 | 30 | 31 | ||||
搜索标题
最新来客
最新评论
统计信息
- 访问量: 244
- 日志数: 3
- 建立时间: 2007-01-16
- 更新时间: 2007-11-11
我的最新日志
-
[原创]解析QTP资源文件
2007-11-11
------------------------------------
' 从XML格式的资源文件中获取对象
'------------------------------------
Public Function GetResource(Byval XmlFile,byval ResourceFile)
Dim XmlObj,i,j,curRow
Dim ObjRoot,Children
Dim childCnt,Parent
Dim Layer,CurLayerIndex()
Dim sourceID,ParentID,sourceClass,sourceName
Dim ExcelApp,Exlsheet,ExcelWorkBook
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Visible = True
ExcelApp.DisplayAlerts = False
Set ExcelWorkBook = ExcelApp.Workbooks.Open(ResourceFile)
Set Exlsheet = ExcelApp.Sheets("对象库")
Exlsheet.Activate
Set XmlObj = XMLUtil.CreateXMLFromFile(XmlFile)
'---当前行
curRow = 1
'----子对象个数
childCnt = 1
'---------获取根对象
Set bjRoot = XmlObj.GetRootElement().ChildElements().ItemByName("qtpRep:Objects")
set Children = ObjRoot.ChildElementsByPath( "./qtpRep:Object" )
For i = 1 to Children.count()
' 第一层对象
Layer = 0
ReDim Preserve CurLayerIndex(Layer)
CurLayerIndex(Layer ) = i
j = 1
Set Child = Children.item(i)
curRow = curRow + 1
Parent = curRow - 1
Set Children = Child.ChildElementsByPath( "./qtpRep:ChildObjects/qtpRep:Object" )
sourceID = curRow - 1
Call GetAttrib(Child,sourceClass,sourceName)
ParentID = 0
Exlsheet.cells(curRow,1) = sourceID
Exlsheet.cells(curRow,2) = sourceName
Exlsheet.cells(curRow,3) = ParentID
Exlsheet.cells(curRow,4) = sourceClass
Exlsheet.cells(curRow,5) = "(" + chr(34) + sourceName + chr(34) + ")"
If Children.count() >0 Then
Layer = Layer + 1
ReDim Preserve CurLayerIndex(Layer)
End If
While Children.count() > 0
If Children.count() >= j Then
CurLayerIndex(Layer ) = j
Set Child = Children.item(j)
curRow = curRow + 1
sourceID = curRow-1
Call GetAttrib(Child,sourceClass,sourceName)
ParentID = Parent
Exlsheet.cells(curRow,1) = sourceID
Exlsheet.cells(curRow,2) = sourceName
Exlsheet.cells(curRow,3) = ParentID
Exlsheet.cells(curRow,4) = sourceClass
Exlsheet.cells(curRow,5) = "(" + chr(34) + sourceName + chr(34) + ")"
childCnt = Child.ChildElementsByPath( "./qtpRep:ChildObjects/qtpRep:Object" ).count()
If childCnt > 0 Then
Layer = Layer + 1
ReDim Preserve CurLayerIndex(Layer)
Set Children = Child.ChildElementsByPath( "./qtpRep:ChildObjects/qtpRep:Object" )
Parent = curRow - 1
j = 1
CurLayerIndex(Layer ) = j
Else
j = j + 1
End If
Else
temprow = CurRow
parent = CInt(Exlsheet.cells(parent + 1,3))
Layer = Layer - 1
Set Child = Child.Parent.Parent
Set Children = Child.Parent.Parent.ChildElementsByPath( "./qtpRep:ChildObjects/qtpRep:Object" )
j = CurLayerIndex(Layer) + 1
End If
Wend
Set Children = Child.Parent.ChildElementsByPath( "./qtpRep:Object" )
Next
ExcelWorkBook.save
ExcelApp.Quit
Set ExcelApp = Nothing
End Function
'--------------------------------------
' 获取资源对象的描述
'--------------------------------------
Public Function GetAttrib(byval Obj,byref attrClass,byref attrName)
Dim attrIdx
GetAttrib = ""
Set CurPara = Obj
Set attribs = CurPara.Attributes()
Set attr = attribs.Item(1)
attrClass = attr.Value()
GetAttrib = GetAttrib + attr.name() + "=" + chr(34) + attrClass + chr(34) + " "
Set attr = attribs.Item(2)
attrName = attr.Value()
GetAttrib = GetAttrib + attr.name() + "=" + chr(34) + attrName + chr(34)End Function
-
<原创>一个批处理执行Test的VBS脚本
2007-8-03
BatchRun.vbs(转载请注明出处)
同目录下需存在runlist.txt文件,保存需要批量运行的test路径,形如:
c:\autotest\test1
c:\autotest\test2------------------
On Error Resume Next
error.clear
Dim qtApp
Dim qtTest
Dim qtResultsOpt
Dim fso, MyFile,TestName
Const ForReading = 1, ForWriting = 2Set WshShell = CreateObject("Wscrīpt.Shell")
WshShell.Popup "开始批量执行自动化测试脚本!", 3, "IPTV AutoTest", 0 + 64Set qtApp = CreateObject("QuickTest.Application")
qtApp.LaunchqtApp.Visible = True
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = FalseSet fso = CreateObject("scrīpting.FileSystemObject")
Set MyFile = fso.OpenTextFile(".\RunList.txt", ForReading, True)
Do While MyFile.AtEndOfStream <> True
TestName = MyFile.ReadLineqtApp.Open TestName, True
Set qtTest = qtApp.Test
qtTest.Settings.Run.OnError = "Dialog"
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")
qtResultsOpt.ResultsLocation = TestName &"\AutoRes"
qtTest.Run qtResultsOpt, True
qtTest.close
wait 1
LoopMyFile.Close
qtApp.QuitMsgBox "自动化测试脚本执行完毕!脚本测试结果存放在各自的AutoRes目录下,请用QTP result工具查看"
Set fso = Nothing
Set qtResultsOpt = Nothing
Set qtTest = Nothing
Set qtApp = Nothing
Set WshShell = Nothing -
自己写的,QTP中的database基本操作函数
2007-4-13
DBconnect初始化数据库连接,传入5个参数
DBtype -数据库类型
server,服务器名称
user,用户
pass,密码
DBname,数据库名
ChkDbError 用于检查数据库错误的,返回的ADO自己的错误描述
ExcuteSql 执行sql用的
执行select语句时,错误返回-1,查询无结果返回0,查询有数据返回结果条数,结果保存到datatable SQL RecordSet里
执行其他语句 错误返回-1,正确返回1Public Cnn
Set Cnn = CreateObject("ADODB.Connection")
'-----------------------------------------------------------------
'函数功能:连接数据库
'-----------------------------------------------------------------
Public Sub DBConnect(ByVal DBType,ByVal DBServer,ByVal DBUser,ByVal DBPass,ByVal DBName)
On error resume Next
Dim StrCon,rel
Select Case DBType
Case 0 'Sql Server
StrCon = "Provider=MSDASQL;Driver={SQL Server};Server="&DBServer&";Database="&DBName&";Uid="&DBUser&";Pwd="&DBPass&";"
Case 1 'Oracle
StrCon = "Provider=MSDAORA.1;Data Source="&DBServer&";Password="&DBPass&";User ID="&DBUser&";Persist Security Info=True"
Case 2 'Sybase
StrCon = "Driver={SYBASE SYSTEM 11};Srvr="&DBServer&";Uid="&DBUser&";Pwd="&DBPass&";Database="&DBName&";"
Case 3 'Access
StrCon = "Driver={Microsoft Access Driver (*.mdb)};Dbq="&DBName&";Uid="&DBUser&";Pwd="&DBPass&";"
End Select
Cnn.Open StrCon
rel = chkDBError()
If rel = true Then
MsgBox "数据库连接失败,测试中止!"
On Error GoTo 0
Else
Reporter.ReportEvent micPass,"数据库已建立连接! StrCon = " &strCon
End If
End Sub
'----------------------------------------------------------------
'函数功能:检查数据库执行是否有错误发生
'返回值: true/false
'----------------------------------------------------------------
Public Function chkDBError()
Dim ObjError
If Cnn.Errors.Count > 0 Then
For Each ObjError In Cnn.Errors
If objError.Number <> 0 Then
Reporter.ReportEvent micFail,数据库操作失败:" &objError.descrīption
chkDBError = true
End If
Next
Else
chkDBError = false
End If
End Function
'----------------------------------------------------------------
'函数功能:执行sql
'返回值: -1,sql语句执行错误
' 0,查询sql没有有结果返回
' >0,查询sql有结果时为结果集记录数,
' 非查询sql执行成功 ,值为1
'-----------------------------------------------------------------
Public Function ExecuteSql(ByVal sqlstr)
On error resume next
Dim rel,Rst
Dim RstCol
Dim i,j,n
Set Rst =CreateObject("ADODB.Recordset")
sqlstr = LTrim(sqlstr)
If Left(sqlstr,6)="select" Then
Rst.open sqlstr, Cnn
If chkDBError() = True Then
rel = -1
Reporter.ReportEvent micFail, "查询语句 "&sqlstr& " 发生错误!"
Else
IF Rst.EOF THEN
rel = 0
Reporter.ReportEvent micWarning, "查询语句 "&sqlstr& " 无返回值!"
Else
i = 0
For each RstCol in Rst.Fields
i = i+1
datatable.AddSheet("SQL RecordSet").AddParameter RstCol.name,""
Next
n=0
While not Rst.EOF
n=n+1
For j = 0 to i-1
datatable.SetCurrentRow n
datatable.Value( Rst.Fields(j).name,"SQL RecordSet") = Rst.Fields(j).value
Next
Rst.MoveNext
Wend
rel =datatable.GetSheet("SQL RecordSet").GetRowCount
Reporter.ReportEvent micPass,"查询语句 "&sqlstr& " 返回"&rel&"条结果,保存于datatable <SQL RecordSet>"
End if
End If
Else
Rst.open sqlstr, Cnn
If chkDBError() = True Then
rel = -1
Reporter.ReportEvent micFail,"执行语句 "&sqlstr& " 发生错误!"
Else
rel = 1
Reporter.ReportEvent micPass,"执行语句 "&sqlstr& " 成功!"
End If
End If
ExecuteSql=CInt(rel)
Rst.close
End Function
