-
QTP调用winrar压缩
2009-12-08 16:36:16
Dim command(3)
command(0)="c:"
command(1)="cd \"
command(2)="cd c:\Program Files\WinRAR"
command(3)="WinRAR a -r -ep1 D:\project\QTP\文档\test.rar D:\project\QTP\文档"
SystemUtil.Run "cmd.exe"
For i=0 to UBound(command)
Window( "object class:=ConsoleWindowClass" ).Type command(i)
Window( "object class:=ConsoleWindowClass" ).Type micReturn
Next -
QTP运行写入日志文件
2009-12-08 16:32:13
Option Explicit
'==========================================================================
' 脚本说明: 写入日志文件
'
' AUTHOR: 孙强
' DATE : 2009-12-8
'
' COMMENT:
'
'==========================================================================
'调用写入日志文件入口
'==========================================================================
'Dim sFoldername,sComtenet
'sFoldername = "D:\temp\"
'sComtenet = "测试脚本调用"
'WriteLog sFoldername,sComtenet
'==========================================================================
' 写入日志文件入口
'==========================================================================
Function WriteLog(sFoldername,sComtenet)
Dim LogTime,sFilename
LogTime = FormatDateTime(Date, 0)&" "&Time&"-------"
sComtenet = LogTime&sComtenet
sFilename = sFoldername&"\QTPlog.txt"
Dim oFSO
'创建文件系统对象
Set FSO = CreateObject ("Scripting.FileSystemObject")
Dim CheckFolderExists,CheckfileExists
'检查日志存放文件夹是否存在
CheckFolderExists = oFSO.FolderExists(sFoldername)
If CheckFolderExists = True Then
'检查日志文件是否存在
CheckfileExists = oFSO.FileExists(sFilename)
If CheckfileExists = True Then
AppendToFile sFilename,sComtenet
Else WriteToFile sFilename,sComtenet
End If
Else CreateFolderDemo sFoldername
WriteToFile sFilename,sComtenet
End If
End Function
'==========================================================================
' 追加Log文件
'==========================================================================
Function AppendToFile(sFilename, sComtenet)
Dim fso,OpenFile
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
Set penFile = fso.OpenTextFile(sFilename, ForAppending, True)
OpenFile.WriteLine(sComtenet)
OpenFile.Close
End Function
'==========================================================================
'写入Log文件
'==========================================================================
Function WriteToFile(sFilename, sComtenet)
Dim fso,CreateFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set CreateFile = fso.CreateTextFile(sFilename, True)
CreateFile.WriteLine(sComtenet)
CreateFile.Close
End Function
'==========================================================================
'创建文件夹
'==========================================================================
Function CreateFolderDemo(sFlodername)
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateFolder(sFlodername)
End Function -
QTP批量执行并发邮件
2009-12-08 16:29:04
Option Explicit
'*****************************************************************
'脚本说明:公共变量声明,路径根据实际环境修改
'*****************************************************************
Dim ReportLocation '报告存放路径
ReportLocation = "D:\project\QTP\qtpscript\"
Dim QtpLocation 'Qtp安装路径
QtpLocation = "D:\softwaretesting\Mercury Interactive\QuickTest Professional\bin\QTPro.exe"
'*****************************************************************
'脚本说明:启动QTP
'*****************************************************************
Dim WshShell,oExec
set WshShell = WScript.CreateObject("WScript.Shell")
Set Exec = WshShell.Exec (QtpLocation)
Set WshShell = Nothing
WScript.Sleep 60000 '等待1分钟
'*****************************************************************
'脚本说明:判断文件是否存在,存在删除
'*****************************************************************
Dim oFSO
' 创建一个文件系统对象
set FSO = CreateObject ("Scripting.FileSystemObject")
CheckFileExists(ReportLocation)
Function CheckFileExists (FilePath)
FilePath = FilePath &"测试结果1.html"
' 检查文件是否存在,如果存在删除
CheckFileExists = oFSO.FileExists(FilePath)
'MsgBox CheckFileExists
If (CheckFileExists = true) Then
oFSO.DeleteFile (FilePath)
End if
End Function'*****************************************************************
'脚本说明:批量执行脚本并生成摘要报告
'*****************************************************************
Dim oMTM
' 创建 Multi Test Manager 对象
Set MTM = CreateObject("MultiTestManager.Application")
oMTM.Visible = True' 修改运行时的默认设置
Dim oRunSettings
Set RunSettings = oMTM.Preferences.RunSettings
oRunSettings.Iterations = 1
oRunSettings.CloseQuickTest = True
'打开注释启用定时调度
'oRunSettings.ScheduleRun = True
'oRunSettings.Day = 3
'oRunSettings.Month = 12
'oRunSettings.Year = 2009
'oRunSettings.Second = 00
'oRunSettings.Minute = 55
'oRunSettings.Hour = 15
' 修改报告的默认设置
Dim oReportSettings
Set ReportSettings = oMTM.Preferences.ReportSettings
oReportSettings.CreateReport = True
oReportSettings.OverwriteReport = False
oReportSettings.DefaultLocation = False
oReportSettings.ReportLocation = ReportLocation '报告存放路径
oReportSettings.ReportName = "测试结果"
oReportSettings.ViewReport = True
'批量执行脚本:脚本的目录,是否执行,执行结果存放位置
oMTM.AddTestScript. "D:\project\QTP\qtpscript\rarTest", True,ReportLocation
'oMTM.AddTestScript. "D:\project\QTP\qtpscript\rarTest", True,ReportLocation 根据脚本进行添加' 运行脚本
oMTM.Run
while ( oMTM.IsRunning )
Wend
oMTM.Quit
Set RunSettings = Nothing
Set ReportSettings = Nothing
Set MTM = Nothing'*****************************************************************
'脚本说明:将运行结果发送邮件
'*****************************************************************
Dim SendTo, Subject, Body, Attachment
'SendTo ="test@163.com;test1@163.com" '发送多个邮箱以分号分割
SendTo ="test@163.com"
Subject ="自动化测试结果"
Body ="自动化测试结果"
Attachment =ReportLocation&"测试结果1.html"
'SendMail SendTo, Subject, Body, AttachmentFunction SendMail(SendTo, Subject, Body, Attachment)
Dim ol,Mail
Set l=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.display '邮件显示
Mail.Send
ol.Quit
Set Mail = Nothing
Set l = Nothing
End Function -
QTP将错误信息写到数据库中
2008-09-08 14:42:02
1、在SQL Server中新建数据库QTP,并新建表Q_Message,字段ID,自动增加,字段Message,varchar255
2、在管理工具中新建ODBC的数据源
3、将错误信息存储到数据库中
On Error Resume Next
Dim a,b,c
a=0
b=1
c=b/a
ErrorHandle()Public Function ErrorHandle()
If Err.Number <> 0 ThenDB("Error Num: " & Err.Number & "; Error Src: " & Err.Source & "; Error Desc: " & Err.Descrīption)
End If
End FunctionPublic Function DB (sql)
Dim cmd,aa
aa="INSERT INTO Q_Message(Message) VALUES ('"&sql&"')"
Set cmd=createobject("adodb.command")
cmd.activeconnection="Driver={SQL Server};Server=TJMDCL-SUNQIANG;Uid=sa;Pwd=sa;DATABASE=QTP;"
cmd.CommandType = 1
cmd.CommandText = aa
cmd.Execute()
Set cmd.activeconnection=Nothing
Set cmd=Nothing
End Function -
(原创)QTP安装视频教程
2008-08-27 15:00:14
一直没有时间,今天抽空录制了QTP的安装视频教程,和大家分享一下,同时也为那些安装出问题朋友,提供一下参考QTP安装教程http://bbs.51testing.com/thread-108263-1-1.html -
最好用的vbs编辑工具,不信进来看看,o(∩_∩)o...
2008-08-27 11:02:04
最好用的vbs编辑工具,不信进来看看,o(∩_∩)o...
-
VBScript With 语句
2008-04-07 10:40:35
VBscrīpt With 语句
with 语句对一个对象执行一系列的语句。
with object
statements
end with参数
object必需的部分。可以是一个对象名称,也可以是返回值为对象的一个函数。
statements
必需的部分。将要对 object 执行的一个或多个命令。
说明
with 语句可以用来对指定的对象执行一系列的语句,但不需要重复地说明对象的名称。例如,如果要修改一个对象的多个属性,可以将所有属性赋值语句放在 with 控制结构中,这样对对象的引用就只需要一次,而不是在每个赋值语句中都引用。下面的例子说明如何使用 with 语句对同一个对象的几个属性进行赋值。with mylabel
.height = 2000
.width = 2000
.caption = "这是mylabel"
end with尽管属性操作是使用 with 语句最多的情况,它的用法并不仅限于此。with 块中可以使用任何合法的语句。
注意 一旦进入了 with 块,object是不可改变的。因此,不能使用一个with语句去改变若干对象的值。
可以嵌套使用 with 语句,将一个 with 块写在另一个块中。然而,由于外部的 with 块的成员被内部的 with 块掩盖,无论内部的 with 块要引用外部的 with 块中的某个对象的什么成员,都必须使用完全限定的对象引用。
重点 不要跳入或跳出 with 块。如果执行了 with 块中的语句却没有执行 with 或 end with 语句,结果将引发错误或其他难以预见的行为。
-
QTP中Link的解决办法
2008-02-29 17:12:45
Dim aa,bb,cc,dd
aa=Browser("CYBRE - OREV Concluded").Page("CYBRE - OREV Concluded").WebTable("Date Received").RowCount'先获得表格的行数
bb="200802-7501-024"'设置的变量
For i=1 to aa
cc= Browser("CYBRE - OREV Concluded").Page("CYBRE - OREV Concluded").WebTable("Date Received").GetCellData(i,5)'得到表格中单元格的值
msgbox cc
If (bb=cc) Then'进行比较
msgbox bb
dd=i'获得变量所在的行
Exit for
End If
Next
msgbox dd
Browser("CYBRE - OREV Concluded").Page("CYBRE - OREV Concluded").WebTable("Date Received").ChildItem(dd,8,"Link" , 0).Click'根据变量所在的行去点击相应单元格中的链接。'如果当前也没有,先在最外层增加多少页的循环,然后在内层的循环中,可以增加else,进行翻页。
-
MultiTestManager,QTP的工具
2008-02-21 10:37:28
-
QTP-用变量代替Browser,Page等元素
2008-02-02 17:58:38
Dim aa
Set aa=Browser("雅虎免费邮箱–全球邮箱第一品牌").Page("雅虎免费邮箱–全球邮箱第一品牌")
aa.WebEdit("login").Set "XXXX"
aa.WebEdit("passwd").Set "XXXX"
这个方法对描述性编程很管用啊,o(∩_∩)o...
-
Msgbox的另一种替代(论坛转载)
2008-01-25 16:49:07
Dim res, WSH
Set WSH = CreateObject("Wscrīpt.Shell")
res = WSH.Popup("Closed after 2 seconds.", 2) '代替msgbox "Closed after 2 seconds"
Set WSH = Nothingwscrīpt.shell 对象详细介绍!!
wshshell.createshortcut(strdesktop & "/a_key.lnk")
omyshortcut.targetpath = "%windir%/notepad.exe"
omyshortcut.hotkey = "alt+ctrl+f"
omyshortcut.save
wscrīpt.echo omyshortcut.hotkey = "alt+ctrl+f"
请参阅
wshspecialfolders 对象
wshshortcut.iconlocation
iconlocation 属性提供快捷方式对象的图标位置。图标位置的格式应为 "path,index"。
语法
wshshortcut.iconlocation = striconlocation
wshshortcut.targetpath
targetpath 属性提供快捷方式对象的目标路径。
语法
wshshortcut.targetpath = strtargetpath
wshshortcut.windowstyle
windowstyle 属性提供快捷方式对象的窗口样式。
语法
wshshortcut.windowstyle = natwindowstyle
wshshortcut.workingdirectory
workingdirectory 为一个快捷方式对象提供工作目录。
语法
wshshortcut.workingdirectory = strworkingdirectory
wshshortcut.save
save 方法把快捷方式对象保存到由 fullname 属性指定的位置。
语法
wshshortcut.save
wshurlshortcut 对象
该对象未直接给出。要获取 wshurlshortcut 对象,可使用 wshshell.createshortcut 方法。
progid n/a
文件名 wshom.ocx
clsid
iid
下表说明了和 wshurlshortcut 对象有关的属性。
属性 说明
fullname url 快捷方式对象的完整路径。
targetpath url 快捷方式对象的目标路径。
下表说明了和 wshurlshortcut 对象有关的方法。
方法 说明
save 将快捷方式保存到指定的文件系统中。
wshurlshortcut.fullname
fullname 属性提供快捷方式对象的完整路径。
语法
wshurlshortcut.fullname = strfullname
wshurlshortcut.targetpath
targetpath 属性提供快捷方式对象的目标路径。
语法
wshurlshortcut.targetpath = strtargetpath
wshurlshortcut.save
save 方法保存一个快捷方式,该快捷方式指向 fullname 属性指定的位置。
语法
wshurlshortcut.save
wshshell.expandenvironmentstrings
expandenvironmentstrings 方法在 strstring 中扩展 process 环境变量并返回结果字符串。变量被 "%" 字符括起。
环境变量不区分大小写。
语法
wshshell.expandenvironmentstrings(strstring) = strexpandedstring
示例
msgbox "prompt is " & wshshell.expandenviromentstrings("%prompt%")
wshshell.popup
popup 方法显示一个弹出式消息框窗口,消息框中包含的消息由 strtext 指定。该消息框的窗口标题由 strtitle 指定。若 strtitle 省略,则窗口标题为 windows scrīpting host。
语法
wshshell.popup(strtext, , , ) = intbutton
注释
若提供 natsecondstowait 且其值大于零,则消息框在 natsecondstowait 秒后关闭。
nattype 的含义与其在 win32? messagebox 函数中相同。下表显示 nattype 中的值及含义。下表中的值可以组合。
按钮类型
值 说明
0 显示“确定”按钮
1 显示“确定”和“取消”按钮
2 显示“终止”、“重试”和“忽略”按钮
3 显示“是”、“否”和“取消”按钮
4 显示“是”和“否”按钮
5 显示“重试”和“取消”按钮
图标类型
值 说明
16 显示停止标记图标
32 显示问号图标
48 显示感叹号图标
64 显示信息标记图标
以上两个表并不涵盖 nattype 的所有值。完整的列表请参阅 win32 文档。
返回值 intbutton 指示用户所单击的按扭编号。若用户在 natsecondstowait 秒之前不单击按扭,则 intbutton 设置为 -1 。
值 说明
1 “确定”按扭
2 “取消”按扭
3 “终止”按扭
4 “重试”按扭
5 “忽略”按扭
6 “是”按扭
7 “否”按扭
示例
set wshshell = wscrīpt.createobject("wscrīpt.shell")
wshshell.popup "where do you want to go today?"
请参阅
wscrīpt.echo 方法
wscrīpt.echo
echo 方法在窗口(wscrīpt.exe 中)或“命令提示符”窗口(cscrīpt.exe 中)显示参数。
参数用空格分隔。在 cscrīpt.exe 中,该方法在显示最后一个参数之后输出一对回车/换行(cr lf)。
语法
wscrīpt.echo
示例
wscrīpt.echo
wscrīpt.echo 1, 2, 3
wscrīpt.echo "windows scrīpting host is cool."
wshshell.regdelete
regdelete 从注册表中删除名为 strname 的键或值。
语法
wshshell.regdelete strname
参数
strname
如果 strname 以反斜杠 (/) 结束,则该方法删除键而不是值。
strname 参数必须以下列之一的根键名开始:
短根键名 长根键名
hkcu hkey_current_user
hklm hkey_local_machine
hkcr hkey_classes_root
hkey_users
hkey_current_config
示例
set wshshell = wscrīpt.createobject("wscrīpt.shell")
wshshell.regdelete "hkcu/scrīptengine/value" " delete value "value"
wshshell.regdelete "hkcu/scrīptengine/key/" " delete key "key"
请参阅
wshshell.regread 方法、wshshell.regwrite 方法
wshshell.regread
regread 方法返回名为 strname 的注册表键或值。
语法
wshshell.regread(strname) = strvalue
参数
strname
如果 strname 以反斜杠 (/) 结束,则该方法返回键,而不是值。
strname 参数必须以下列根键名开始。
short long
hkcu hkey_current_user
hklm hkey_local_machine
hkcr hkey_classes_root
hkey_users
hkey_current_config
注释
regread 方法仅支持 reg_sz、reg_expand_sz、reg_dword、reg_binary 和 reg_multi_sz 数据类型。若注册表有其他数据类型,regread 返回 disp_e_typemismatch。
示例
set wshshell = wscrīpt.createobject("wscrīpt.shell")
wshshell.regread("hkcu/scrīptengine/val") " read from value "val"
wshshell.regread("hkcu/scrīptengine/key/") " read from key "key"
请参阅
wshshell.regdelete 方法、wshshell.regwrite 方法
wshshell.regwrite
regwrite 方法设置名为 strname 的注册表键或值。
语法
wshshell.regwrite strname, anyvalue,
参数
strname
若 strname 以一个反斜杠 (/) 结束,则该方法设置键,而不是值。
strname 参数必须以下列根键名开头。
short long
hkcu hkey_current_user
hklm hkey_local_machine
hkcr hkey_classes_root
hkey_users
hkey_current_config
anyvalue
当 strtype 为 reg_sz 或 reg_expand_sz 时,regwrite 方法自动将 anyvalue 转换为字符串。若 strtype 为 reg_dword,则 anyvalue 被转换为整数。若 strtype 为 reg_binary,则 anyvalue 必须是一个整数。
strtype
regwrite 方法支持 strtype 为 reg_sz、reg_expand_sz、reg_dword 和 reg_binary。若其他的数据类型被作为 strtype 传递,regwrite 返回 e_invalidarg。
示例
set wshshell = wscrīpt.createobject("wscrīpt.shell")
wshshell.regwrite "hkcu/scrīptengine/value", "some string value"
wshshell.regwrite "hkcu/scrīptengine/key/", 1 "reg_dword"
请参阅
wshshell.regdelete 方法、wshshell.regwrite方法
wshshell.run
run 方法创建一个新的进程,该进程以 intwindowstyle 窗口样式执行 strcommand。
语法
wshshell.run (strcommand, , )
参数
strcommand
在 strcommand 参数内部的环境变量被自动扩展。
intwindowstyle
这是为新进程在 startupinfo 结构内设置的 wshowwindow 元素的值。其意义与 showwindow 中的 ncmdshow 参数相同,可取以下值之一。名称 值 含义
sw_hide
0 隐藏窗口并激活另一窗口。
sw_minimize
6 最小化指定窗口并激活按 z 序排序的下一个顶层窗口。
sw_restore
9 激活并显示窗口。若窗口是最小化或最大化,则恢复到原来的大小和位置。在还原应用程序的最小化窗口时,应指定该标志。
sw_show
5 以当前大小和位置激活并显示窗口。
sw_showmaximized
3 激活窗口并以最大化显示该窗口。
sw_showminimized
2 激活窗口并以最小化显示该窗口。
sw_showminnoactive
7 最小化显示窗口。活动窗口保持活动。
sw_showna
8 以当前状态显示窗口。活动窗口保持活动。
sw_shownoactivate
4 按窗口最近的大小和位置显示。活动窗口保持活动。
sw_shownormal
1 激活并显示一个窗口。若窗口是最小化或最大化,则恢复到其原来的大小和位置。
blnwaitonreturn
如果未指定 blnwaitonreturn 或其值为 false,则该方法立即返回到脚本继续执行而不等待进程结束。
若 blnwaitonreturn 设为 true,则 run 方法返回由应用程序返回的任何错误代码。如果未指定 blnwaitonreturn 或其值为 false,则 run 返回错误代码 0(zero)。
示例
" this fragment launches notepad with the current executed scrīpt
set wshshell = wscrīpt.createobject("wscrīpt.shell")
wshshell.run ("notepad " & wscrīpt.scrīptfullname)
wshshell.run ("%windir%/notepad" & wscrīpt.scrīptfullname)
" this fragment returns the error code from the executed application
return = wshshell.run("notepad " & wscrīpt.scrīptfullname, 1, true) -
QTP的分页,另一种方法
2008-01-24 14:32:45
'************************************************************************
'功能:分页
'说明:对于需要调用此方法的使用者,可以自己改造,例如对于
' 检查页面值时,可以使用While...Wend 语句,判断当前页是否包括
'如果没有点击下一页或者上一页。'intTotal_Page 总页数 intCur_Page 当前页
'************************************************************************
Public Sub Pagination ()
Reporter.ReportEvent micDone ,"调用 Pagination ()","Start"
intTotal_Page=Browser("name:="&strBrowserName).Page("title:="&strPageName).Frame("title:="&strFrameName).WebElement("html id:=total_page").GetROProperty("innertext")
msgbox intTotal_Page
intCur_Page=Browser("name:="&strBrowserName).Page("title:="&strPageName).Frame("title:="&strFrameName).WebElement("html id:=cur_page").GetROProperty("innertext")
msgbox intCur_Page
If (intTotal_Page=0and intCur_Page=0)or (intTotal_Page=1and intCur_Page=1) Then
Reporter.ReportEvent micpass ,"分页","没有分页"
End If
if (intCur_Page<intTotal_Page) then
Browser("name:="&strBrowserName).Page("title:="&strPageName).Frame("title:="&strFrameName).Image("file name:=pages_go.gif").Click
end if
If (intTotal_Page= intCur_Page) then
Browser("name:="&strBrowserName).Page("title:="&strPageName).Frame("title:="&strFrameName).Image("file name:=pages_back.gif").Click
end if
Reporter.ReportEvent micDone ,"调用 Pagination ()","End"
End Sub -
QTP-关于ActiveX加载问题
2008-01-07 11:26:44
-
QTP总结之(七)datatable的注意的问题
2007-07-31 17:49:14
当为datatable添加参数化数据,如果删除参数化的数据,但是行数并没有减少,比如,已经有了两行数据,添加一行后,使用clear删除了这行的数据或者格式,但是使用GetRowCount,检查还是三行,所以要用delete删除整行后,在检查就是两行了,否则对于datatable的循环就会出错。 -
QTP总结之(六)Test Batch Runner的使用
2007-07-27 15:53:00
-
VBSCRIPT通用脚本
2007-07-13 10:05:08
1、将返回值拼接为字符串
Dim strLink,inti,straa,straa1
straa=null
strLink=Array("权限管理","人员组织","业务流程管理","系统配置","日志管理")For intI=0 to ubound(strLink)
straa1=ClickLink1(strLink(intI))
straa=straa&straa1'将所得值拼为111111
msgbox straa
NextFunction ClickLink1(strLink)
ClickLink1=1
End Function -
QTP总结之(五)Action模版文件
2007-07-03 15:49:06
新建名称为ActionTemplate.mst,然后放入QTP的安装目录的dat文件夹下,在每次启动QTP的时候会自动加载。
-
QTP总结之(四)结果集循环取出
2007-07-03 15:45:56
结果集循环
do
DataTable.GlobalSheet.AddParameter "type", res("type_def_name")
res.movenext
loop until res.eof=true
-
QTP总结之(三)描述性编程
2007-07-03 15:43:45
对于描述性编程,可以解决很多QTP无法正常录制的问题。
1)对于对象可以使用
2)对于链接的参数化,可以使用(描述性编程)
Dim text
text="人员组织"
Browser(" BPM").Page("BPM").Link("innertext:="&text).Click
-
QTP总结之(二)-报告的输出
2007-06-28 14:13:29
'使用report.ReportEvent,会在执行后将错误的信息打印到报告中
'Status的设定分为四种:
' 0或者micpass
' 1或者micfail
' 2或者micdone
' 3或者micwarning
'Reporter.ReportEvent micFail ,"错误报告","请检查用户名和密码或着页面上是否包含“表单管理”字样"
标题搜索
我的存档
数据统计
- 访问量: 54777
- 日志数: 53
- 图片数: 6
- 文件数: 5
- 建立时间: 2006-12-14
- 更新时间: 2009-12-08