• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    軟件測試工具QTP面向對象的框架

    發布: 2010-9-08 09:48 | 作者: 網絡轉載 | 來源: 領測軟件測試網采編 | 查看: 166次 | 進入軟件測試論壇討論

    領測軟件測試網

    軟件測試工具QTP面向對象的框架

    這種框架的核心思想是把某個窗口的測試對象和相關業務核心操作都封裝在VBS的類中,稱之為GUI層,或者叫GUI-業務橋接層。例如下面的登錄界面類:

      ' 登錄界面類,封裝了界面對象數據以及相關業務操作

      Class Login

      Private m_htChildObjects 'As Scripting.Dictionary

      Public Property Get ChildObjects()

      Set ChildObjects = m_htChildObjects

      End Property

      Public Property Let ChildObjects(ByRef dic)

      Set m_htChildObjects = dic

      End Property

      ' 初始化界面對象并驗證對象是否存在

      Public Function Init()

      ChildObjects = CreateObject("Scripting.Dictionary")

      With ChildObjects

      .Add "LoginDialog", Dialog("text:=Login")

      .Add "AgentName", ChildObjects.Item("LoginDialog").WinEdit("attached text:=Agent Name:")

      .Add "Password", ChildObjects.Item("LoginDialog").WinEdit("attached text:=Password:")

      .Add "Submit", ChildObjects.Item("LoginDialog").WinButton("text:=OK")

      End With

      'IsContextLoaded is a function that iterates through the Dictionary and checks if the GUI objects "exist"

      Init = IsContextLoaded(ChildObjects) ' 檢查界面層對象是否存在

      End Function

      ' 與界面對象綁定的各類業務操作

      ' 測試數據從GlobalDictionary中獲取(放在Data層),這里把測試數據做成函數參數可能會更好?!

      Public Function SetUsername()

      ChildObjects.Item("AgentName").Set GlobalDictionary.Item("AgentName")

      End Function

      Public Function SetPassword()

      ChildObjects.Item("Password").Set GlobalDictionary.Item("Password")

      End Function

      Public Function Submit()

      ChildObjects.Item("Submit").Click

      End Function

      End Class

      Public Function CreateLogin()

      Dim objLogin

      Set objLogin = New Login

      Set CreateLogin = objLogin

      End Function

      在業務層的類中封裝業務操作流程的代碼,例如下面的登錄流程:

      ' 登錄業務類,封裝了登錄過程的業務操作流程

      Class do_login

      Public Default Function Run()

      Dim intStatus

      Set objLogin = CreateLogin() ' 調用GUI層的Login類

      If objLogin.Init() Then ' 如果所需的界面對象都存在,則執行業務操作流程

      objLogin.SetUsername()

      objLogin.SetPassword()

      objLogin.Submit()

      intStatus = micPass 'If login succeeds

      Else

      intStatus = micFail

      End If

      Run = intStatus

      End Function

      End Class

      Public Function Create_do_login()

      Dim bzLogin

      Set bzLogin = New do_login

      Set Create_do_login = bzLogin

      End Function

      這種寫法的好處,除了可以細粒度地抽象、分解業務的測試代碼,提高可重用性外,還可以在業務層的代碼執行前,先讓界面層檢查驗證所需的測試對象是否都存在( 例如上面代碼中的objLogin.Init() ),避免了QTP在運行過程中碰到對象不存在的時候卡住的現象。

      在界面層的Init方法中,通過描述性編程把測試對象都存入Dictionary中,然后用IsContextLoaded方法遍歷對象,檢查是否在運行時都存在:

      ' 檢查界面層對象是否存在并寫入測試報告

      Public Function IsContextLoaded(ByRef htContext)

      Dim ix, items, keys, strDetails, strAdditionalRemarks

      IsContextLoaded=true

      items = htContext.Items

      keys = htContext.Keys

      For ix = 0 To htContext.Count-1

      IsContextLoaded = IsContextLoaded And items(ix).Exist(0)

      strDetails = strDetails & vbNewLine & "Object #" & ix+1 & ": '" & keys(ix) & "' was"

      If IsContextLoaded Then

      intStatus = micPass

      strDetails = strDetails & ""

      strAdditionalRemarks = ""

      Else

      intStatus = micWarning

      strDetails = strDetails & " not"

      strAdditionalRemarks = " Please check the object properties."

      End If

      strDetails = strDetails & " found." & strAdditionalRemarks

      Next

      Reporter.ReportEvent intStatus, "IsContextLoaded", strDetails

      End Function

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/

    TAG: qtp QTP 工具 框架 面向對象 軟件測試


    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備10010545號-5
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>