link:http://www.51testing.com/?uid-72002-action-viewspace-itemid-210607
'关闭所有打开的IE进程
systemutil.CloseProcessByName("iexplore.exe")
'设置对象超时时间:为1000S
setting("defaulttimeout")=1000000
*defaulttimeout
*Sets or retrieves the delay for finding objects. DefaultTimeOut is a per-test setting.
'调用VBS文件
executefile "D:\chuchangceshi\public.vbs"
'systemutil对象
SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE","","C:\Documents and Settings\test","open","3"
open-- Opens the file specified by the FileName parameter. The file can be an executable file, a document file, or a folder. Non-executable files are open in the associated application.
3-- Activates the window and displays it as a maximized window.
'Opens a specified URL in the browser 打开一个指定的URL地址
object.Navigate Location, [TargetFrame], [PostData], [Headers]
Browser("Browser").Navigate URL
'常见的IE浏览器打开窗口的操作语句
Browser("Browser").Dialog("选择数字证书").WinListView("您要查看的网站要求标识。请选择证书。").Select "normal"
'excel文件读取方式
==1
Dim excel_ob,my_excel_workbook,my_excel_worksheet,range1,range2
Set excel_ob =CreateObject("excel.application")
excel_ob.Visible=True
setmy_excel_workbook=excel_ob.Workbooks.Open("D:\MyVBscript\vba_excel.xls")
Setmy_excel_worksheet=my_excel_workbook.Worksheets("test001")
Sub test_copy()
my_excel_worksheet.range("b1")=28
Set range1=my_excel_worksheet.range("b1")
Set range2=my_excel_worksheet.range("c3")
range1.copy range2
excel_ob.Workbooks.Close
window("text:=microsoft excel").close
'my_excel_worksheet.range("b1").copy my_excel_worksheet.range("b2")
End Sub
==2
Public FunctionQTP_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
'调用已有的QTP脚本 RunAction
RunAction ActionName, [IterationMode , IterationRange , Parameters]
ActionName:(String) The name of the action.
IterationMode:(Pre-defined constant ) Optional.
oneIteration or 0 (Default) - runs the action only once
rngIterations or 1 - runs iterations according to the third parameter.
IterationRange:Not always required.
Parameters:The values and storage locations for the called action's input and output parameters.
eg:
RunAction "https_portal_denglu [Login]", oneIteration
'判断指定文件是否存在
Function ReportFileStatus(filespec)
Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
msg = True
Else
msg = False
End If
ReportFileStatus = msg
End Function
'获得当前对象属性信息 GetROProperty
object.GetROProperty (Property, [PropData])
object: Any Webtestobject.
Property: Required. A String value. The property to retrieve from the object.
PropData: Optional. A Variant value. Not in use.
Return Type:A Variant value.
eg:'HWND是Browser("sts demo 演示")的一项属性
Browser("sts demo 演示").GetROProperty("HWND")
'使用eqv
Performs a logical equivalence on two expressions
result = expression1 Eqv expression2
'比较两个表达式的值,当且仅当 表达式1和表达式2同为true或同为false时,结果才为true
'生成结果报告 Reporter.ReportEvent
Reporter.ReportEvent EventStatus, ReportStepName, Details [, in]
EventStatus :
0 or micPass: Causes the status of this step to be passed and sends the specified message to the report.
1 or micFail: Causes the status of this step to be failed and sends the specified message to the report.
When this step runs, the test or component fails.
2 or micDone: Sends a message to the report without affecting the pass/fail status of the test or component.
3 or micWarning: Sends a warning message to the report, but does not cause the test or component to
stop running, and does not affect the pass/fail status of the test or component.
ReportStepName: Name of the intended step in the report (object name).
Details :Description of the report event. The string will be displayed in the step details frame. in the report.
eg:
If check eqv true Then
reporter.ReportEvent 0,"pass","添加BS应用自动登录功能正确"
else
reporter.ReportEvent 1,"fail","添加BS应用自动登录功能失败"
End If
获取表格对象的行数 RowCount
object.RowCount
Returns the number of rows in the table.
row=Browser("JIT Cinas").Page("JIT Cinas").Frame("mainFrame_4").WebTable("应用信息列表").RowCount
'获取列表对象单元格的值 GetCellData
object.GetCellData (vtRow, vtColumn)
Returns the text contained in the specified cell.
object: Atestobject of type WebTable.
vtRow: Required. A Variant value. The row number where the cell is located. The first row in the table is numbered 1.
vtColumn: Required. A Variant value. The column number where the cell is located. The first column in the table is numbered 1.
eg:
micheng=Browser("JIT Cinas").Page("JIT Cinas").Frame("mainFrame_4").WebTable("应用信息列表").GetCellData(i,1)
'对运行场景抓图 CaptureBitmap
object.CaptureBitmap FullFileName, [OverrideExisting]
Saves a screen capture of the object as a .png or .bmp image using the specified file name.
object: Any StandardWindowstest object.
FullFileName: Required. A String value.
OverrideExisting: Optional. A Boolean value. Indicates whether the captured image should be overwritten if the image file already exists in the test results folder. Possible values: True/False (default)
'按照索引获取对象中的值
'获取表格对象的行数
row=Browser("JIT Cinas").Page("JIT Cinas").Frame("mainFrame_4").WebTable("应用信息列表").RowCount
'判断名称为bs的应用所在的行数,获取到配置信息图片的索引值
dex=2 '索引的初始值
For i=3 to row
micheng=Browser("JIT Cinas").Page("JIT Cinas").Frame("mainFrame_4").WebTable("应用信息列表").GetCellData(i,1)
'获取所在行的应用名称
If trim(micheng)=trim("cs") Then
Exit for
End If
dex=dex+3 '进入下一行,图片索引值加3
Next
'关闭指定的进程
systemutil.CloseProcessByName("iexplore.exe")'关闭所有打开的IE进程