2023年6月29日发(作者:)
UFT(QTP)-总结点与⾃动化测试框架UFT(QTP)-总结点与⾃动化测试框架
⽬录1、前⾔2、简介3、总结点3.1、Accessibility Checkpoint可访问性检查点3.2、Action Properties-Action属性设置3.3、Active Screen测试界⾯信息设置3.4、Active Screen插⼊位图检查点3.5、Active Screen中的对象输出其对象属性3.6、Active Screen中选择并添加对象到对象库3.7、Active Screen中选择对象并添加测试步骤3.8、Analog Recording-低级录制3.9、Associate Repositories-关联Action的对象库3.10、Check Syntax-语法检查3.11、Comment-添加注释3.12、Data Driver Wizard-数据驱动向导设置3.13、Data Driver-数据驱动器3.14、Data Table iterations设置数据表格的迭代⽅式3.15、Database Checkpoint数据库检查点3.16、DataTable参数化3.17、DataTable参数化检查点3.18、Documentation-导出测试步骤⽂档3.19、Function Definition Generator-创建⾃定义函数3.20、Image Checkpoint图像检查点3.21、Insert Call to New Action-添加新的Action3.22、Insert New Step-插⼊新的测试步骤3.23、Insert Report-测试信息的输出3.24、Insert Standard Checkpoint-插⼊标准检查点3.25、Object Identification-识别对象3.26、Object Repository-对象库3.27、Object Spy-查看测试对象的属性和⽅法3.28、Page Checkpoint页⾯检查点3.29、Random Number随机数进⾏参数化3.30、Record and Run Settings-windows应⽤程序设置3.31、Recovery Scenario-场景恢复3.32、Run-选择测试运⾏结果的存储位置3.33、Run-运⾏部分测试3.34、Run-运⾏⽅式设置3.35、Screen Recorder-在报表中查看测试过程的截屏3.36、Select Object for Step-为测试步骤选择对象3.37、Silent Test Runner模拟Loadrunner的调⽤3.38、Step Generator-插⼊新的测试步骤3.39、Step Generator-添加函数调⽤3.40、Table Checkpoint表格检查点3.41、Test Batch Runner-批量运⾏测试脚本3.42、Text Area Checkpoint⽂本区域检查点3.43、Text Checkpoint⽂本检查点3.44、Transaction添加事务3.45、Virtual Objects-定义虚拟对象3.46、Virtual Objects-虚拟对象管理3.47、XML Checkpoint-XML检查点3.48、导⼊导出环境变量⽂件3.49、调⽤Action3.50、定义和设置环境变量3.51、关联Recovery Scenario到测试脚本3.52、设置插件管理界⾯是否显⽰3.53、添加Action的输⼊参数3.54、运⾏过程中设置判断⼀个对象存在的最⼤时间3.55、在测试步骤中绑定环境变量值3.56、⾃动识别和完成VBScript语法的输⼊3.57、把屏幕截图保存到指定⽂件3.58、单步调试三种区别3.59、定位并激活对话框3.60、获取控件窗⼝的标题3.61、检查点3.62、检查结果写⼊测试报告中3.63、判断控件是否存在3.64、QTP对记事本的操作4、⾃动化测试框架
1、前⾔
随着⾃动化测试技术的发展,新兴的开源⾃动化测试⼯具崛起,例如:Selenium、Cypress等。但是⽼牌的⾃动化测试⼯具也在不断的更新与迭代,本篇介绍⼀下作者之前在使⽤UFT(QTP)时的⼀些总结。
2、简介
Unified Functional Testing(UFT)称为统⼀功能测试,是⼀种⾃动化测试⼯具,可为软件应⽤程序提供⾃动化功能和回归测试。
UFT⽀持关键字和脚本界⾯,并具有图形⽤户界⾯。它使⽤Visual Basic Scripting Edition(VBScript)脚本语⾔来指定⼀个测试过程,并操纵被测试应⽤程序的对象和控件。
原名为QuickTest Professional(QTP)。Unified Functional Testing 11.5将HP QuickTest Professional和HP Service Test整合到⼀个软件包中,重新起名为Unified Functional Testing。
UFT是收费的,要licence,新版的免费使⽤时间为60天。
3、总结点
3.1、Accessibility Checkpoint可访问性检查点
3.2、Action Properties-Action属性设置
3.3、Active Screen测试界⾯信息设置
3.4、Active Screen插⼊位图检查点
3.5、Active Screen中的对象输出其对象属性
3.6、Active Screen中选择并添加对象到对象库
3.7、Active Screen中选择对象并添加测试步骤
3.8、Analog Recording-低级录制
3.9、Associate Repositories-关联Action的对象库
3.10、Check Syntax-语法检查
3.11、Comment-添加注释
3.12、Data Driver Wizard-数据驱动向导设置
3.13、Data Driver-数据驱动器
3.14、Data Table iterations设置数据表格的迭代⽅式
3.15、Database Checkpoint数据库检查点
3.16、DataTable参数化
3.17、DataTable参数化检查点
3.18、Documentation-导出测试步骤⽂档
3.19、Function Definition Generator-创建⾃定义函数
3.20、Image Checkpoint图像检查点
3.21、Insert Call to New Action-添加新的Action
3.22、Insert New Step-插⼊新的测试步骤
3.23、Insert Report-测试信息的输出
3.24、Insert Standard Checkpoint-插⼊标准检查点 3.25、Object Identification-识别对象
3.26、Object Repository-对象库
3.27、Object Spy-查看测试对象的属性和⽅法
3.28、Page Checkpoint页⾯检查点
3.29、Random Number随机数进⾏参数化
3.30、Record and Run Settings-windows应⽤程序设置
3.31、Recovery Scenario-场景恢复
3.32、Run-选择测试运⾏结果的存储位置
3.33、Run-运⾏部分测试
3.34、Run-运⾏⽅式设置
3.35、Screen Recorder-在报表中查看测试过程的截屏 3.36、Select Object for Step-为测试步骤选择对象
3.37、Silent Test Runner模拟Loadrunner的调⽤
3.38、Step Generator-插⼊新的测试步骤
3.39、Step Generator-添加函数调⽤
3.40、Table Checkpoint表格检查点
3.41、Test Batch Runner-批量运⾏测试脚本
3.42、Text Area Checkpoint⽂本区域检查点
3.43、Text Checkpoint⽂本检查点
3.44、Transaction添加事务
3.45、Virtual Objects-定义虚拟对象
3.46、Virtual Objects-虚拟对象管理
3.47、XML Checkpoint-XML检查点
3.48、导⼊导出环境变量⽂件
3.49、调⽤Action
3.50、定义和设置环境变量
3.51、关联Recovery Scenario到测试脚本
3.52、设置插件管理界⾯是否显⽰
3.53、添加Action的输⼊参数
3.54、运⾏过程中设置判断⼀个对象存在的最⼤时间
3.55、在测试步骤中绑定环境变量值
3.56、⾃动识别和完成VBScript语法的输⼊
3.57、把屏幕截图保存到指定⽂件可以保存为“.png”或“.bmp”图像⽂件eBitmap "C:",true 3.58、单步调试三种区别(1)Step Into 执⾏Step Into命令有三种⽅式:菜单 Debug>Step Into、点击Step Into按钮、按F11。通过Step Into命令,执⾏当前脚本步骤。如果当前脚本是⼀个调⽤ Function的语句,则Function脚本会在QTP窗⼝中打开,并且当前步骤指向Function的第1⾏代码。(2)Step Out
执⾏Step Out命令有三种⽅式:菜单 Debug>step Out、点击Step Out按钮、按SHIFT+F11。只在当⽤户使⽤了Step Into命令执⾏了调⽤ Function语句,打开了Function后,才需要使⽤Step Out命令。Step Out⾃动运⾏到Function结束,然后返回到调⽤语句,并暂停运⾏脚本。(3)Step Over
执⾏Step Over命令有三种⽅式:菜单 Debug>Step Over、点击Setp Over按钮、按F10。Step Over只能运⾏当前代码⾏,当运⾏到调⽤Function语句时,Function被⾃动完整执⾏,QTP不打开Function的脚本。
3.59、定位并激活对话框Dialog("Login").Activate
3.60、获取控件窗⼝的标题Dim LoginTitleLoginTitle = Dialog("Login").GetROProperty("text")Msgbox LoginTitle
3.61、检查点(1)标准检查点(Standard Checkpoint):⽤于检查测试对象的属性(2)图像检查点(Image Checkpoint):⽤于检查被测试应⽤程序的图像(3)位图检查点(Bitmap Checkpoint):把检查被测试应⽤程序的某个区域当成位图来检查(4)表格检查点(Table Checkpoint):⽤于检查表格信息(5)⽂本检查点(Text Checkpoint):⽤于检查⽂本字符串是否在应⽤程序中的适当位置出现(6)⽂本区域检查点(Text Area Checkpoint):⽤于检查⽂本字符串是否按既定的标准出现在应⽤程序的预定区域(不⽀持Web页⾯⽂字的检查,仅⽀持标准windows、vb、activeX以及插件⽀持的控件的⽂本检查)(7)可访问性检查点(Accessibility Checkpoint):⽤于检查⽹页是否满⾜W3C的⽹页内容可访问性指南的要求(8)页⾯检查点(Page Checkpoint):⽤于检查⽹页的属性(9)数据库检查点(DataBase Checkpoint):⽤于检查应⽤程序所访问的数据库(10)XML检查点(XML Checkpoint):⽤于检查XML⽂档
3.62、检查结果写⼊测试报告中micDone为完成的micFail为失败的micPass为通过的micWarning为警告的Event micPass,"ChecktextBox1 = Pass","被激活"
3.63、判断控件是否存在If Dialog("Login").Exist(3) Then MsgBox("Login窗⼝存在")Else MsgBox("Login窗⼝不存在")End If
3.64、QTP对记事本的操作定位到记事本的窗⼝Window("记事本").Activate最⼤化记事本的窗⼝Window("记事本").Maximize恢复记事本窗⼝⼤⼩Window("记事本").Restore获取记事本窗⼝的标题msgbox Window("记事本").GetROProperty("text")往记事本中输⼊⼀段⽂字Window("记事本").WinEditor("Edit").Type"sdfsdfsfsdfassdfsfsfsdfsdf"键⼊“Enter”键Window("记事本").WinEditor("Edit").Type micReturn
4、⾃动化测试框架
⾃动化测试框架⽬录结构:BizModule:功能模块(测试⽤例所调⽤的操作)FuncLibrary:公共⽅法(脚本所要调⽤的⽅法)Help:帮助⽂档与使⽤说明Log:执⾏出错时,将报错截图⾃动保存到此⽬录⾥TestData:存放测试数据UFTTestCase:测试⽤例(程序执⾏的主流程⼊⼝)
1、测试⽤例,例如:主控流程维护了两条操作:信息拟稿、信息编辑员
脚本代码:按照表格条数进⾏循环执⾏,先登陆,之后匹配Case名称进⾏后续的测试Dim strTestDirstrTestDir = Environment("TestDir") 'E:UFT_FrameworkUFTTestCase主控流程Int PosPos = Instr(1, strTestDir, "UFTTestCase") '18Pos = Pos - 1 '17Dim strRootPathstrRootPath = Left(strTestDir, Pos) + "BizModule" 'E:UFT_FrameworkBizModuleDim strLogFolderPathstrLogFolderPath = Left(strTestDir, Pos) + "Log" 'E:UFT_FrameworkLogDim strTestCaseNameDim strSysNameDim strStepNameDim strNameDim strUserDim strPassWordDim strNextStepDim strNextUserDim strUserDepartmentDim strTestModulePathDim strTitleDim strLoginPathDim strAttachmentPathInt intCount
intCount = et("Global").GetRowCount '2For i = 1 To intCount '流程循环 rentRow(i) strTestCaseName = ("TestCaseName", "Global") If strTestCaseName = Environment("TestName") Then 'Environment("TestName") = 主控流程 strSysName = ("SystemName", "Global") strStepName = ("StepName", "Global") strName = ("Name", "Global") strUser = ("User", "Global") strPassWord = ("PassWord", "Global") strNextStep = ("NextStep", "Global") strNextUser = ("NextUser", "Global") strUserDepartment = ("UserDepartment", "Global") strTestModulePath = Cstr(Trim(strRootPath & "" & strSysName & "" & strStepName)) 'E:UFT_FrameworkBizModule政务信息信息拟稿 strLoginPath = Cstr(Trim(strRootPath & "登录")) 'E:UFT_FrameworkBizModule登录 strAttachmentPath = Cstr(Trim(strRootPath & "上传附件")) 'E:UFT_FrameworkBizModule上传附件 strAttachmentPath = Cstr(Trim(strRootPath & "上传附件")) 'E:UFT_FrameworkBizModule上传附件
LoadAndRunAction strLoginPath, "登录", oneIteration, strUser, strName, strPassWord If tus = micFail Then Event micFail, Environment("ActionName") & "执⾏出错" Qtp_capture(strLogFolderPath) ExitTest End If
If strTitle <> "" Then strDaibanPath = Cstr(Trim(strRootPath & "待办事项")) LoadAndRunAction strDaibanPath, "打开待办事项", oneIteration, strTitle If tus = micFail Then Event micFail, Environment("ActionName") & "执⾏出错" Qtp_capture(strLogFolderPath) ExitTest End If End If
Select Case strStepName Case "信息拟稿" LoadAndRunAction strTestModulePath, "信息拟稿", oneIteration, strTestCaseName, strName, strNextStep, strAttachmentPath, strTitle If tus = micFail Then Event micFail, Environment("ActionName") & "执⾏出错" Qtp_capture(strLogFolderPath) ExitTest End If
Case "信息编辑员" LoadAndRunAction strTestModulePath, "稿纸页⾯", oneIteration, strTitle, strNextStep, strAttachmentPath If tus = micFail Then Event micFail, Environment("ActionName") & "执⾏出错" Qtp_capture(strLogFolderPath) ExitTest Else Event micPass, Environment("TestName") & "执⾏通过" ExitTest End If End Select Else Exit For
End If
Next
2、功能模块,例如:信息拟稿
脚本代码(部分):strTestCaseName = Parameter("strTestCaseName")strName = Parameter("strName")strNextStep = Parameter("strNextStep")strAttachmentPath = Parameter("strAttachmentPath")Browser("Test").Page("Test").webElement("信息拟稿").ClickRunAction "信息拟稿页⾯", oneIteration, strTestCaseName, strName, strTitleParameter("strTitle") = strTitleBrowser("Test").CloseAllTabs
3、公共⽅法,例如:PublicFunction脚本代码:'**********************************************'Description: ⽣成错误⽇志Function Qtp_Capture(strLogFolderPath) Dim strFolderPath, strdate Dim strHour Dim strMinute Dim strSecond Dim strTime Dim strFile1 Dim strFile2 strTime = time() strHour = Hour(strTime) strMinute = Minute(strTime) strSecond = Second(strTime) strTime = Cstr(strHour) & "时" & Cstr(strMinute) & "分" & Cstr(strSecond) & "秒" Set fso = CreateObject("stemObject") strFolderPath = Trim(strLogFolderPath & "") strdate = FormatDateTime(date(), 1) Dim strDesFolder strDesFolder = Cstr(strFolderPath) + Cstr(strdate) If Exists(strDesFolder) Then strFile1 = Cstr(strDesFolder) & "" & Environment("TestName") & "-" & Cstr(strTime) eBitmap strFile1 & ".bmp", true Else Folder(strDesFolder) strFile2 = Cstr(strDesFolder) & "" & Environment("TestName") & "-" & Cstr(strTime) eBitmap strFile2 & ".bmp", true End IfEnd Function'**********************************************'Description: 往EXCEL表中写数据Function WriteFile(sFileName,SheetNum,x,y,Content)Set xlsObj=CreateObject("ation")Set xlsBook=(sFileName)Set xlsSheet=(SheetNum)(x,y) = et xlsSheet = NothingSet xlsBook = NothingSet xlsObj = NothingEnd Function'**********************************************'Description: 读取EXCEL表中的数据Function ReadFile(sFileName,sSheetName) Dim oExcel Dim oSheet Dim oRange Dim arrRange
On Error Resume Next '发⽣错误时 让程序继续执⾏下⼀句代码 Set oExcel = CreateObject("ation") '创建Excel应⽤程序对象 If <> 0 Then MsgBox "未能初始化Excel" & vbCrLf & "请确保Excel已安装", vbCritical Exit Function End If On Error Goto 0 '禁⽌当前过程中任何已启动的错误处理程序也就是关闭错误处理功能
On Error Resume Next
(sFileName) '打开Excel⽂件 If <> 0 Then MsgBox "未能加载Excel⽂件" & vbCrLf & "请确保Excel⽂件路径正确或格式正确", vbCritical Exit Function End If On Error Goto 0
Set oSheet = eets(sSheetName).UsedRange '获取表格的使⽤范围 Set oRange = ("A1:Z1000") '获取从A列到Z列,从第1⾏到第1000⾏的范围i中的所有值 arrRange = '把Excel数据转换到数组 (1).Close '关闭⼯作簿 '退出Excel ReadFile = arrRange '返回包含Excel数据的数组 Set oRange = Nothing Set oSheet = Nothing Set oExcel = NothingEnd Function'***************************************************************************'function:新建⾏'methods:InsertRow Environment("TestDir") + "","sheet1",1'这个是插⼊新⾏的 ⼀般情况下是⽤在写数据不重复的时候 会先新插⼊⼀⾏然后再往⾥⾯写数据'***************************************************************************Function InsertRow(sFileName,SheetNum,x)Set xlsObj=createobject("ation")Set xlsBook=(sFileName)Set xlsSheet=(SheetNum)(x).et xlsSheet = NothingSet xlsBook = NothingSet xlsObj = NothingEnd Function
''读写数据的时候,⼤部分是主要变更⾏值,⽐如你做循环操作的时候,写循环,那个保持变化的就是⾏值,⽐如你在第5⾏开始数据读写,那for就从5开始,列值保持不'For s = 5 to 7' 这个s就是循环的起始值' '讲数据写⼊---实际数据表' WriteFile "D:Test⾃动化测试框架","Sheet1",s,2,"a"' WriteFile "D:Test⾃动化测试框架","Sheet1",s,3,"b"' WriteFile "D:Test⾃动化测试框架","Sheet1",s,4,"c"' WriteFile "D:Test⾃动化测试框架","Sheet1",s,5,"d"' WriteFile "D:Test⾃动化测试框架","Sheet1",s,6,"e"'Next'''写数据到EXCEL中'aa = "123"'result_p = "结果"'WriteFile "D:Test⾃动化测试框架","Sheet1",1,2,aa'WriteFile "D:Test⾃动化测试框架","Sheet1",1,4,result_p
'''读取EXCEL表中的数据'arrRange = ReadFile("D:Test⾃动化测试框架","Sheet1")'name = arrRange(1,2)'Msgbox name
'''新建⾏(sFileName, SheetNum, x)'InsertRow "D:Test⾃动化测试框架","Sheet1",1要获取全部资源,关注我的微信公众号:程序员⼆⿊,即可获取全部资源如果您觉得⽂章还不错,请 点赞、分享、在看、收藏 ⼀下,因为这将是我持续输出更多优质⽂章的最强动⼒!在这⾥推荐⼀个我⾃⼰创建的软件测试交流群,QQ:642830685,群中会不定期的分享软件测试资源,测试⾯试题以及测试⾏业资讯,⼤家可以在群中积极交流技术,还有⼤佬为你答疑解惑。
发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1688019837a67329.html
评论列表(0条)