51Testing软件测试论坛
标题:
QTP针对WEB项目自动化开发的简单总结
[打印本页]
作者:
测试工坊
时间:
2012-7-29 18:05
标题:
QTP针对WEB项目自动化开发的简单总结
本帖最后由 测试工坊 于 2012-7-29 18:06 编辑
刚做了几个针对Web的自动化测试项目,简单总结一下,仅供缺乏实际项目经验的同僚参考使用。
[attach]80227[/attach]
[attach]80228[/attach]
[attach]80226[/attach]
下面是外部调用的示例,更多需求请参考帮助文件中的自动化对象模型部分。
'--------------------------------------------------------
Const runLevel = n ' which level are you goint to run? set 0 to run all pages
Const endLine = n ' Enter the number of the end line here.
TestLinkFlag = False' This is a falg to determine if the Links should be tested.
'--------------------------------------------------------
currentPath=left(Wscript.ScriptFullName,len(Wscript.ScriptFullName)-len(Wscript.ScriptName))
testPath = currentPath & "script\"
excelPath = currentPath & "\sitemap.xlsx"
Public runAction
Public qtApp
Public testArray
Class caseClass
Public TestName
Public Priority
Public ActionName
End Class
SetActionName runLevel,endLine,excelPath
tName = ""
For Each arr In testArray
If arr.Priority = runLevel Then
runAction = runAction&arr.ActionName&"|"
If Not inStr(tName,arr.TestName) = 1 Then
tName = arr.TestName
testString = testString & testPath & tName & "|"
End If
End If
Next
'If none of the action in the test needs to be executed, then pass this test.
If Len(runAction)> 0 Then runAction = runAction & "init|Finalize|Header|Footer"
runTestPath = Split(testString,"|")
'Load test
Set fso = CreateObject("Scripting.FileSystemObject")
For Each testPath In runTestPath
If Len(testPath) > 0 And fso.FolderExists(testPath) Then
RunQTPTest testPath
End If
Next
'Invoke QTP
Function RunQTPTest(testPath)
Set qtApp = CreateObject("QuickTest.Application")
arrTestAddins = qtApp.GetAssociatedAddinsForTest(testPath)
blnNeedChangeAddins = False
For Each testAddin In arrTestAddins
If qtApp.Addins(testAddin).Status <> "Active" Then
blnNeedChangeAddins = True
Exit For
End If
Next
If qtApp.Launched And blnNeedChangeAddins Then
qtApp.Quit
End If
If blnNeedChangeAddins Then
blnActivateOK = qtApp.SetActiveAddins(arrTestAddins, errorDescription)
If Not blnActivateOK Then
MsgBox errorDescription
WScript.Quit
End If
End If
If Not qtApp.Launched Then
qtApp.Launch
End If
qtApp.Open testPath,True
qtApp.Test.Environment.Value("runAction") = runAction
qtApp.Test.Environment.Value("LinkFlag") = TestLinkFlag
qtApp.Visible = True
qtApp.Options.Run.ImageCaptureForTestResults = "OnError"
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False
Set qtTest = qtApp.Test
qtTest.Settings.Run.OnError = "NextStep"
qtTest.run
'qtApp.quit
Set qtApp = Nothing
Set qtTest = Nothing
End Function
Public Function SetActionName(runLevel,endLine,excelPath)
Set objExcel = GetExcelObject(excelPath)
Dim actionArray()
arrIndex = 0
For i = 2 To endLine
ActionName = GetCellValue(objExcel,"Sitemap",i,4)
Priority = GetCellValue(objExcel,"Sitemap",i,5)
url = GetCellValue(objExcel,"Sitemap",i,3)
If GetCellValue(objExcel,"Sitemap",i,1)<> "" Then TestName = GetCellValue(objExcel,"Sitemap",i,1)
If url <> "" Then
ReDim Preserve actionArray(arrIndex)
Set actionArray(arrIndex) = New caseClass
actionArray(arrIndex).Priority = Priority
actionArray(arrIndex).ActionName = ActionName
actionArray(arrIndex).TestName = TestName
arrIndex = arrIndex + 1
End If
Next
testArray = actionArray
objExcel.Save
objExcel.close
Set w = CreateObject("Wscript.Shell")
w.run "Library/GetResultByAction.vbs"
Set w = Nothing
End Function
Function GetExcelObject(excelPath)
Set objExcel = CreateObject("Excel.Application")
Set GetExcelObject = objExcel.Workbooks.Open (excelPath)
End Function
Function GetCellValue(objExcel, sheetName, row, col)
objExcel.Worksheets(sheetName).Activate
GetCellValue = objExcel.Worksheets(sheetName).Cells(row, col)
End Function
复制代码
作者:
lsekfe
时间:
2012-7-30 09:31
感谢下LZ!
作者:
AntonioNikki
时间:
2012-7-30 09:47
感谢分享
作者:
黑羽祭
时间:
2012-7-30 13:22
感谢分享
作者:
bslkzhw
时间:
2012-8-2 16:29
非常感谢楼主的简单结构,最近一直苦于怎么实施QTP,怎样把它导入进现在的测试,你的部署让我茅塞顿开。非常感谢
作者:
monica.lijing
时间:
2012-8-28 10:26
过来看看,呵呵
作者:
louqqson008
时间:
2012-8-28 15:09
看看,学习下
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2