日历
| |||||||||
| 日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
| 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 | ||||
存档
搜索标题
最新评论
统计信息
- 访问量: 1549
- 日志数: 11
- 建立时间: 2007-11-17
- 更新时间: 2008-08-22
我的最新日志
-
用VBS对XML 的读取
2008-8-22
用VBS对XML 的读取
VBS脚本:
Dim strXML
GetXml "c:\task01.xml","TestNumberOne0" '该行仅为实例,前面为xml文件路径,后面为查找的tag名称
MsgBox strXML
Function GetXml (ByVal strXmlFilePath,ByVal xmlNodeName)
Dim xmlDoc,xmlRoot
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False
xmlDoc.load strXmlFilePath
If xmlDoc.parseError.errorCode <> 0 Then
MsgBox "XML文件格式不对,原因是:" & Chr(13) & xmlDoc.parseError.reason
Exit Function
End If
Set xmlRoot = xmlDoc.documentElement
xmlRecursion xmlRoot,xmlNodeName
GetXml = True
'xmlRecursion (xmlRoot)
End Function
Function xmlRecursion(byval xmlNode,byval strNodeName)
If xmlNode.nodeName = strNodeName And xmlNode.hasChildNodes Then
If xmlNode.childNodes.item(0).nodeName = "#text" Then
strXML = strXML & xmlNode.nodeName & ":" & xmlNode.childNodes.item(0).nodeValue & Chr(13)
End If
End If
If xmlNode.hasChildNodes Then
For Each childNodeItem In xmlNode.ChildNodes
If childNodeItem.hasChildNodes Then
xmlRecursion childNodeItem,strNodeName
End If
Next
End If
End Function
XML文件内容:c:\task01.xml
<?xml version="1.0" encoding="GB2312"?>
<ROOT>
<TestCase>
<TestNumberOne0>1</TestNumberOne0>
<TestNumberTwo>2</TestNumberTwo>
<TestNumberThree>+</TestNumberThree>
<TestResult>3</TestResult>
</TestCase>
<TestCase>
<TestNumberOne1>3</TestNumberOne1>
<TestNumberTwo>2</TestNumberTwo>
<TestNumberThree>-</TestNumberThree>
<TestResult>1</TestResult>
</TestCase>
<TestCase>
<TestNumberOne2>3</TestNumberOne2>
<TestNumberTwo>7</TestNumberTwo>
<TestNumberThree>*</TestNumberThree>
<TestResult>21</TestResult>
</TestCase>
<TestCase>
<TestNumberOne3>2</TestNumberOne3>
<TestNumberTwo>5</TestNumberTwo>
<TestNumberThree>/</TestNumberThree>
<TestResult>0.4</TestResult>
</TestCase>
</ROOT> -
在QTP中,使用Exist属性来判断控件是否存在。
2008-8-22
可以通过访问控件的exist属性来判断控件是否存在于当前打开的应用程序中。例如:下面的脚本就是用于判断Login窗口是否存在:
'判断某个控件是否存在
If Dialog("Login").Exist(3)=false then
MsgBox ("Login window not exist.")
Else
MsgBox ("Login window exist.")
End if
值得注意的是:exist属性中可以指定“TimeOut”参数,用于指定查控件的时间。调用Exist将返回True 或者false,用于表示窗体是否存在。 -
在QTP中,用vbscript模拟鼠标右键点击
2008-8-21
Object, micRightBtn
Set keys_a= createobject("Wscrīpt.shell")
keys_a.sendkeys "{down}"
keys_a.sendkeys "{enter}" -
自定义QTP的report函数
2008-8-21
Function LogEvent(ByVal strType, ByVal strProcedure, ByVal strMessage)
Select Case strType
Case "FAIL" Reporter.ReportEvent micFail, strProcedure, strMessage
Case "WARNING" Reporter.ReportEvent micWarning, strProcedure, strMessage
Case "PASS" Reporter.ReportEvent micPass, strProcedure, strMessage
Case "INFORMATION" Reporter.ReportEvent micDone, strProcedure, strMessage
Case Else Reporter.ReportEvent micWarning, "LogEvent", "Invalid Parameter strType: " & strType
End Select
End function使用:
Logevent "PASS","Uninstall Result","Uninstall SQL Server 2005 successfully!"
-
在QTP运行过程中输出txt文件
2008-8-21
Function WriteLog(LogContent)
logfile=LogName
Const forappending=8
Set ōbjFSO=CreateObject("scrīpting.FileSystemObject")
Set ōbjTextFile=objFSO.OpenTextFile(LogFile,forappending,true)
objTextFile.WriteLine now&chr(9)&chr(9)&LogContent
objTextFile.close
End functionFunction LogName
Gethostname hostname
Month1=Month(now)
If month1 >0 and Month1<10 Then
LongMonth="0" & cstr(Month1)
else
longmonth=month1
End If
day1=day(now)
If day1 >0 and day1<10 Then
Longday="0" & cstr(day1)
else
longday=day1
End If
hour1=hour(now)
If hour1 >0 and hour1<10 Then
Longhour="0" & cstr(hour1)
else
longhour=hour1
End If
LogName="Z:\Logs\" &hostname &"_"& year(now) & longmonth & longday & longhour &".txt"
End Function使用:
WriteLog("Test Pass")
生成的日志为:
8/12/2008 8:10:19 PM Test Pass
-
获取ini配置文件中的信息
2008-8-21
在固定配置文件中,读取相应行的信息。
function GetFile(strPath,numH)
const ForReading=1
set ōbjFSO=CreateObject("scrīpting.FileSystemObject")
set ōbjTextFile=objFSO.OpenTextFile(strPath,ForReading)
temp=objTextFile.ReadAll
strArray=Split(temp,vbCrLf)
GetFile=strArray(numH-1)
objTextFile.close
End Function使用:
dim x
x=GetFile("Z:\scrīpts\install.ini",2) '读取第二行的信息。
dim MyString,msg
MyArray=split(x,"=",-1,1)
a="Z:\AdminKit\" & MyArray(1) & "\setup.exe" -
写一个自定义QTP中的等待
2008-8-21
由于QTP中自带的wait函数,使用起来,不那么顺心。。特别是等待新窗体出现的时候。于是写了一个自定义的waittime函数。。
Function waittime(ByRef condition)
Dim wait_time
wait_time=0
Do while wait_time<=10000
If condition.exist=true Then
Exit do
else
wait 2
wait_time=wait_time+1
End If
Loop
End Function -
获得计算机名
2008-8-21
Public Function GetHostName (ByRef strComputerName)
Dim objNetwork
Set ōbjNetwork = CreateObject("Wscrīpt.Network")
strComputerName = objNetwork.ComputerName
GetComputerName = True
Set ōbjNetwork = Nothing
End function -
xml遍历
2008-8-21
Dim strXML
GetXml "c:\task01.xml","TestResult"
MsgBox strXML
Function GetXml (ByVal strXmlFilePath,ByVal xmlNodeName)
Dim xmlDoc,xmlRoot
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False
xmlDoc.load strXmlFilePath
If xmlDoc.parseError.errorCode <> 0 Then
MsgBox "XML文件格式不对,原因是:" & Chr(13) & xmlDoc.parseError.reason
Exit Function
End If
Set xmlRoot = xmlDoc.documentElement
xmlRecursion xmlRoot,xmlNodeName
GetXml = True
'xmlRecursion (xmlRoot)
End FunctionFunction xmlRecursion(byval xmlNode,byval strNodeName)
If xmlNode.nodeName = strNodeName And xmlNode.hasChildNodes Then
If xmlNode.childNodes.item(0).nodeName = "#text" Then
strXML = strXML & xmlNode.nodeName & ":" & xmlNode.childNodes.item(0).nodeValue & Chr(13)
End If
End If
If xmlNode.hasChildNodes Then
For Each childNodeItem In xmlNode.ChildNodes
If childNodeItem.hasChildNodes Then
xmlRecursion childNodeItem,strNodeName
End If
Next
End If
End Function
