首页 > 代码库 > QTP关键字驱动框架之方法体封装

QTP关键字驱动框架之方法体封装

‘刷新浏览器
Public Sub Refresh
Browser("CreationTime:=0").Refresh
Browser("CreationTime:=0").Sync 
End Sub 

Public Function Include(value)
Dim ExcelPath,TCNum,arrTemp
arrTemp = Split(value,",")
ExcelPath = arrTemp(0)
TCNum = arrTemp(1)
‘执行用例
Set oExcel = CreateObject("Excel.Application")
Set oWookBook = oExcel.Workbooks.Open(ExcelPath)
Set oTCWookSheet = oExcel.Worksheets.Item(TCSheet).UsedRange 
Set oTSWookSheet = oExcel.Worksheets.Item(TSSheet).UsedRange
TCrow=oTCWookSheet.Rows.count                            ‘计算使用的单元格行数 
TSrow=oTCWookSheet.Rows.count 
For i = 2 To TCrow
TestCesesID = oExcelUtil.getCellData(oTCWookSheet,i,Col_TestCaseID)
RunMode = oExcelUtil.getCellData(oTCWookSheet,i,Col_Runmode)
If TestCesesID = TCNum And RunMode = "Yes" Then
For j = 2 To TSrow
tsTCID = oExcelUtil.getCellData(oTSWookSheet,j,Col_TestCaseID)
If tsTCID = TestCesesID Then
tsEvent = oExcelUtil.getCellData(oTSWookSheet,j,Col_Event)
tsElement = oExcelUtil.getCellData(oTSWookSheet,j,Col_Elenium)
tsAttribule = oExcelUtil.getCellData(oTSWookSheet,j,Col_Attribute)
tsValue = http://www.mamicode.com/oExcelUtil.getCellData(oTSWookSheet,j,Col_Value)
Select Case tsEvent
Case "Launch"
oKeyWord.Launch tsValue
Case "Refresh"
oKeyWord.Refresh
Case "Click"
oKeyWord.Click tsElement,tsAttribule
Case "Input"
oKeyWord.Input tsElement,tsAttribule,tsValue
Case "Sendkeys"
oKeyWord.Sendkeys tsValue
Case "Selects"
oKeyWord.Selects tsElement,tsAttribule,tsValue
Case "MouseMove"
oKeyWord.MouseMove tsElement,tsAttribule
Case "sSet"
oKeyWord.sSet tsElement,tsAttribule,tsValue
Case "CloseBrowser" 
oKeyWord.CloseBrowser
End Select
End If
Next 
End If
Next 
‘关闭Excel
Set oTCWookSheet = Nothing
Set oTSWookSheet = Nothing
‘oWookBook.Save
oWookBook.Close
oExcel.Quit
Set oExcel = Nothing
Set oKeyWord = Nothing
Set oExcelUtil = Nothing
End Function

‘点击
Public Function Click(element,oDesc)
Browser("title:=.*").Page("title:=.*").Sync 
arrayProperty element,oDesc
proName = Split(oPropertyName,",")
proValue = http://www.mamicode.com/Split(oPropertyValue,",")
Set oElement = getItemList(objPage,proName,proValue)
If oElement.count = 1 Then
oElement(0).Click
else if oElement.count = 2 then
oElement(1).Click
End IF
end if
Set oPropertyName = Nothing
End Function 

public Function Sync
Browser("CreationTime:=0").Sync
End Function

‘日历时间控件方法
public Function CalendarSet(element,oDesc,value)
arrayProperty element,oDesc
proName = Split(oPropertyName,",")
proValue = http://www.mamicode.com/Split(oPropertyValue,",")
Set oElement = getItemList(objPage,proName,proValue)
if oElement.count = 1 Then
oElement(0).Object.setAttribute "value",value,"0"
End IF
End Function

‘保存数据,提供下游业务引用
public Function SaveData(element,oDesc,sValue)
arrTemp = split(sValue,";")
arrayProperty element,oDesc
proName = Split(oPropertyName,",")
proValue = http://www.mamicode.com/Split(oPropertyValue,",")
Set oElement = getItemList(objPage,proName,proValue)
if oElement.count = 1 and UBound(arrTemp)=2 Then
select case arrTemp(2)
case "innertext" 
oExcelUtil.WriteExcelData arrTemp(0),arrTemp(1),oElement(0).GetROProperty("innertext")
case "value"
oExcelUtil.WriteExcelData arrTemp(0),arrTemp(1),oElement(0).GetROProperty("value")
End Select
End IF
End Function

QTP关键字驱动框架之方法体封装