淺談QTP中的測試對象

發表于:2009-05-04來源:作者:點擊數: 標簽:qtpQTP對象
在功能的 自動化測試 中 QTP 被人們廣泛的使用著,關于使用 qtp 自身的對象倉庫的方法來管理測試對象的方式,本人認為存在著很大的局限性,在這里介紹一種通過函數的方式來管理和使用測試對象的方法,該方法的思想是基于利用函數來實現的,把要測試的每一類對
在功能的自動化測試QTP被人們廣泛的使用著,關于使用qtp自身的對象倉庫的方法來管理測試對象的方式,本人認為存在著很大的局限性,在這里介紹一種通過函數的方式來管理和使用測試對象的方法,該方法的思想是基于利用函數來實現的,把要測試的每一類對象通過一個或幾個公用的函數來實現,下面通過具體的code來說明,先建立一個 TestObject.qfl的文件,用來模擬對象倉庫的功能。

Function getWindow

    Set win = description.Create
    win("class description").value = "window"

    Set getWindow = win

End Function

Function getWindowByTitle(title)

    Set win = description.Create
    win("class description").value = "window"
    win("title").value = title

    Set getWindowByTitle = win

End Function

Function getDialog

    Set dia = description.Create
    dia("class description").value = "window"

    Set getDialog = dia

End Function

Function getDialogByTitle(title)

    Set dia = description.Create
    dia("class description").value = "window"
    dia("title").value = title

    Set getDialogByTitle = dia

End Function

Function getEdit

    Set edt = description.Create
    edt("class description").value = "edit"

    Set getEdit = edt

End Function

Function getEditByText(text)

    Set edt = description.Create
    edt("class description").value = "edit"
    edt("attached text").value = text

    Set getEditByText = edt

End Function

Function getEditByIndex(index)

    Set edt = description.Create
    edt("class description").value = "edit"
    edt("index").value = index

    Set getEditByIndex = edt

End Function

Function getButton

    Set btn = description.Create
    btn("class description").value = "push_button"

    Set getButton = btn

End Function

Function getButtonByText(text)

    Set btn = description.Create
    btn("class description").value = "push_button"
    btn("attached text").value = text

    Set getButtonByText = btn

End Function

  我們通過以上這種方式,可以把我們測試項目中用到的所有的測試對象加入到這個“對象倉庫”中來,在使用的時候,只需要調用相應的函數即可實現,如下面的coad所示。

SystemUtil.Run "fileName","","filePath"

If JavaWindow(getWindow).JavaDialog(getDialog).Exist(30) Then

    With JavaWindow(getWindow).JavaDialog(getDialog)

        .JavaEdit(getEditByText("User Name")).Set "userName"
        .JavaEdit(getEditByText("Password")).Set "userPwd"
        .JavaButton(getButtonByText("Ok")).Click
    End with
Else
    Reporter.ReportEvent micFail,"lauch error","launch error, please check the application!"
    ExitTest
End If

  通過這種方式實現了測試對象的過度復用,更符合自動化測試的思想,在項目的測試過程中,我們只要不斷的加入新類型的測試對象即可,關鍵是這些測試對象基本不需要怎么維護,便可以很好的進行復用,這些對象不僅僅在一個項目中可以使用,只要是同一類型的項目,我們都可以來使用這些對象,而不需要隨著不同的項目我們還要去重復的去維護一個個的對象倉庫了。這樣大大的提高了我們的測試效率,也便于多人集體合作。

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97