老李分享:qtp自动化测试框架赏析-关键字自动化测试框架

    QTP从2005年继winrunner,robot逐渐退出历史舞台之后,占领主流自动化测试工具市场已经10年之久。当初为了提高在自动化测试工具市场的竞争力,通过vbs脚本语言讨好自动化测试(专指脚本开发人员)工程师,通过关键字视图讨好业务(这里主要是指对自业务很熟,能找出问题的人员)测试人员。

     自动化测试工具选型:这是重要的两个评估维度,工具所用的脚本能完成自动化测试,如ajax技术出现后,qtp在某些环境需要调用js脚本才能完成自动化测试,qtp脚本的扩展要求对qtp自动化测试工程师提出了更高的要求。关键字视图只能完成机械的对象选择,我们有的时候对象可能是一套脚本,这样qtp本身提供的关键字视图的框架功能就无法完成。

     在这里我提供一个简单的关键字自动化测试框架的模型,核心引擎我实现了,如果你感兴趣,可以根据公司的情况,进一步扩展。

     一.首先设计的表驱动的数据形式

         

   二.实现对象映射引擎

Option Explicit
Public WebBrowserDesc
public WebPageDesc
public WebEditDesc,
public WebButtonDesc
public WebObjDesc ' ...............................

Dim arrObjProperty
Dim arrObjValue
Dim strObjProperty
Dim strObjValue

Public Function fnApplicationMap(strBrowser,strObjName)
  Set WebBrowserDesc=Description.Create
  WebBrowserDesc("application version").Value="internet explorer6"
  If strBrowser<>"" Then
    WebBrowserDesc("name").value=strBrowser
  End If
  Set WebPageDesc=Description.Create
  WebPageDesc("title").Value=strBrowser

  Select Case strObject
    Case "WebEdit"
      Set WebEditDesc=Description.Create
      WebEditDesc ("html tag").Value="INPUT"
      WebEditDesc("name").Value=strObjName
    Case "WebButton"
      Set WebButtonDesc=Description.Create
      WebButtonDesc ("html tag").Value="INPUT"
      WebButtonDesc("name").Value=strObjName
    Case "WebElement"
      Set WebObjDesc=Description.Create
      arrObjProperty=Split(strObjName,",")
      For each strObjProperty in arrObjProperty
        arrObjValue=Split(strObjProperty,"=")
        strObjValue=trim(arrObjValue(0))
        WebObjDesc(strObjValue).Value=trim(arrObjValue(1))

      Next
   End Select

End Function