• <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自動化測試框架SAFFRON

    發布: 2009-5-25 19:09 | 作者: 網絡轉載 | 來源: 測試時代采編 | 查看: 387次 | 進入軟件測試論壇討論

    領測軟件測試網

    4.7 檢查對象是否存在

    前面的小例子僅僅實現了啟動瀏覽器、導航、點擊鏈接和按鈕的功能,如果要組成一個完整的測試用例,還缺少一些東西,例如檢查指定的對象是否存在,在SAFFRON中,用Verify函數來實現這個功能,Verify函數的定義如下所示:
         ' Verify the Existence of an object
         ' objtype - values should be limited to values in the object array
         ' text    - multi-purpose argument that indicates what to verify
         '         - for a link, or button, it's the text of the control
         '         - for a list, it's the name of the control
         '         - for a frame, it's the name of the frame
         Public Function Verify (objtype, text)
            rval = false
          localDesc = ""
          estr = ""
          If thirdlevel <> "" Then
           localDesc = GenerateDescription(level(2))
          Else
           localDesc = GenerateDescription(level(1))
          End If
         
            AutoSync()
         
          Select Case objtype
          Case "Page"
           Execute "rval = " & GenerateDescription(level(1)) & "Exist (0)"
           If rval Then
            Execute "title = " & GenerateDescription(level(1)) & "GetROProperty(" & Quote("title") & ")"
            If title = text Then
             rval = true
            Else 
             rval = false
            End If
           End If
          Case "CurrentFrame"
           If thirdlevel <> "" Then
            estr = "rval = " & localDesc
           End If
          Case "Link"
           estr =  "rval = " & localDesc & GenerateObjectDescription("Link", "innertext:=" & text)
          Case "WebButton"
           estr = "rval = " & localDesc & GenerateObjectDescription("WebButton", "value:=" & text)
          Case "WebList"
           estr = "rval = " & localDesc & GenerateObjectDescription("WebList", "name:=" & text)
          Case "WebEdit"
           estr = "rval = " & localDesc & GenerateObjectDescription("WebEdit", "name:=" & text)
          End Select
         
          If estr <> "" Then
           Execute estr + "Exist (0)"
          End If
         
          If rval Then
           Report micPass, objtype & " Verification", "The " & objtype & " " & Quote(text) & " was verified to exist"
          Else
           Report micFail, objtype & "  Verification", "The " & objtype & " " & Quote(text) & " was not found"
          End If
         
          If "True" = rval Then
           rval = True
          Else
           rval = False
          End If
         
            Verify = rval
         End Function

    由于判斷不同對象的存在需要采用不同的屬性,因此Verify函數中對不同的對象類型進行判斷、分別處理。例如,對于Link類型的對象,用innertext屬性,對于WebButton,則采用value屬性,但是最后都需要組合成一條語句,后接“Exist”,通過Execute方法執行這個語句,從而實現對象是否存在的判斷。

    對于頁面對象(Page)的存在性檢查有點不一樣,采用的是以下腳本:
          Case "Page"
           Execute "rval = " & GenerateDescription(level(1)) & "Exist (0)"
           If rval Then
            Execute "title = " & GenerateDescription(level(1)) & "GetROProperty(" & Quote("title") & ")"
            If title = text Then
             rval = true
            Else 
             rval = false
            End If
           End If

    通過GetROProperty方法獲取當前頁面的title屬性,然后與傳入的“text”參數進行比較,如果相等,則認為頁面對象是存在的。

    在測試腳本中可以這樣使用Verify函數:
         ' 啟動瀏覽器
         Launch "website","http://127.0.0.1:1080"
         ' 導航到“http://127.0.0.1:1080/WebTours”
         BrowseTo "http://127.0.0.1:1080/WebTours/"
         
         If Verify ("Link","administration")= False then
          Reporter.ReportEvent micFail,"檢查鏈接","鏈接不存在"
          Else
             ' 點擊名為“administration”的鏈接
             Activate "Link","administration"
         End IF

    腳本中先用Verify檢查名為“administration”的鏈接對象是否存在,如果不存在則提示錯誤,如果存在則進一步調用Activate函數點擊鏈接。

    4.8 在文本框輸入字符串

    在SAFFRON中,可以使用EnterTextIn函數來給輸入框(WebEdit對象)輸入字符串。EnterTextIn函數的定義如下所示:
         ' Enters text into an edit field
         ' objname - name of the control -- use Object Spy if you don't know what it is
         ' text    - the text to enter into the control
         Public Function EnterTextIn (objname, text)
          localDesc = ""
          rval = true
          If thirdlevel <> "" Then
           localDesc = GenerateDescription(level(2))
          Else
           localDesc = GenerateDescription(level(1))
          End If
         
          AutoSync()
         
          localDesc = localdesc & GenerateObjectDescription("WebEdit", "name:=" & objname)
          Execute localDesc & "Set (" & Quote(text) & ")"
          Report micPass, "Enter Text", "Text: " & Quote(text) & " was entered into " & Quote(objname)
          EnterTextIn = rval 
         End Function

    例如,如果我們要在如圖所示的登錄界面中輸入用戶名和密碼,則可以使用SAFFRON的EnterTextIn函數來實現。

    測試腳本可以這樣編寫:
         ' 輸入用戶名
         EnterTextIn "username","chennengji" 
         ' 輸入密碼
         EnterTextIn "password","123"

    4.9 讀取文本框的字符串

    在SAFFRON中,可以使用EnterTextIn函數來給輸入框(WebEdit對象)輸入字符串。對應的有一個名為GetTextFrom的函數,用于讀取輸入框和文本列表的字符串,GetTextFrom的定義如下所示:
         ' Obtains text from a control
         ' objtype - is the type of control the get the text from
         ' objname - is the name of the control -- use Object Spy if you don't know the name
         ' returns - the text of the control
         Public Function GetTextFrom (objtype, objname)
          text = ""
          localDesc = ""
          If thirdlevel <> "" Then
           localDesc = GenerateDescription(level(2))
          Else
           localDesc = GenerateDescription(level(1))
          End If
         
          AutoSync()
         
          Select Case objtype
           Case "WebEdit"
            Execute "text = " & localDesc & GenerateObjectDescription("WebEdit", "name:=" & objname) & "GetROProperty (" & Quote("value") & ")"
           Case "WebList"
            Execute "text = " & localDesc & GenerateObjectDescription("WebList", "name:=" & objname) & "GetROProperty (" & Quote("value") & ")"
          End Select
          Report micPass, "Capture Text", "Text: " & Quote(text) & " was captured from the control " & Quote(objname)
          GetTextFrom = text
         End Function

    假設我們需要讀取如圖所示的界面中的“Departure City”和“Arrival City”這兩個文本列表(WebList對象)中的字符串,則可以使用GetTextFrom函數。

    測試腳本可以這樣編寫:
         ' 獲取航班起始城市
         DepartureCity = GetTextFrom( "WebList","depart")
         ' 獲取航班終點城市
         ArrivalCity = GetTextFrom( "WebList","arrive")

    當然,也可以使用相同的函數來讀取文本框(WebEdit對象)的字符串,例如下面的腳本讀取“NO. of Passengers”對應的文本框中的字符串:
         ' 獲取乘客數量
         PassengerNumber = GetTextFrom( "WebEdit","numPassengers")

    延伸閱讀

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

    53/5<12345>

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