• <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-10-21 10:15 | 作者: 李剛 | 來源: 本站原創 | 查看: 773次 | 進入軟件測試論壇討論

    領測軟件測試網

    由于判斷不同對象的存在需要采用不同的屬性,因此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")

    4.10 選擇列表中的一項
      在SAFFRON 中,可以使用SelectFromList 函數從下拉框列表(WebList 對象)中選擇指定的一項。SelectFromList 的定義如下所示:
         ' Selects a specific value from a listbox, or combobox
         ' objname - name of the control -- use Object Spy if you don't know the name property
         ' text    - the item in the combobox to select
         Public Function SelectFromList (objname, text)
          localDesc = ""
          rv = ""
          rval = false
          If thirdlevel <> "" Then
           localDesc = GenerateDescription(level(2))
          Else
           localDesc = GenerateDescription(level(1))
          End If
        
          AutoSync()
        
          localDesc = localdesc & GenerateObjectDescription("WebList", "name:=" & objname)
        
          Execute "cnt = " & localDesc & "GetROProperty(" & Quote("items count") & ")"
          For i = 1 to cnt
           Execute "rv = " & localDesc & "GetItem (" & i & ")"
           If rv = text Then
            rval = true
           End If
          Next
        
          If rval Then
           Execute localDesc & "Select " & Quote(text)
          End If
          If rval Then
           Report micPass, "WebList Selection", "The WebList item " & Quote(text) & " was selected."
          Else
           Report micFail, "WebList Selection", "The WebList item " & Quote(text) & " was NOT found."
          End If
        
          SelectFromList = rval
         End Function

      假設我們需要從如圖所示的界面中的“Departure City ”的下拉框中選擇其中一項,則可使用SelectFromList 函數來實現。

     

      測試腳本可以這樣寫:
         ' 選擇航班起始城市為"San Francisco"
         SelectFromList  "depart","San Francisco"

    4.11 關閉瀏覽器
      Web 頁面測試的最后一個步驟一般都是關閉瀏覽器,在SAFFRON 中,也把這個過程封裝成了一個名為“CloseBrowsers ”的函數,該函數的定義如下:
         ' close all opened browsers
         Public Function CloseBrowsers
          If Browser("micclass:=Browser").Exist (0) Then
           Browser("micclass:=Browser").Close
          End If
          While Browser("micclass:=Browser", "index:=1").Exist (0)
           Browser("index:=1").Close
          Wend
          If Browser("micclass:=Browser").Exist (0) Then
           Browser("micclass:=Browser").Close
          End If
         End Function

      CloseBrowsers 函數會把當前所有打開的瀏覽器都關閉,腳本中采用描述性編程的方式獲取所有對象類型為“Browser ”的測試對象,然后循環逐個關閉所有這種類型的測試對象。

    5 、對SAFFRON 框架進行擴展

      SAFFRON 是一個基本的框架,它封裝了瀏覽器的相關測試操作、封裝了一些基本對象的測試操作,例如Link 、WebButton 、WebEdit 、WebList 等控件,可用于基本的WEB 頁面的測試,并且簡化了測試腳本的編寫,可以讓代碼的可讀性和可維護性得到增強。

      但是SAFFRON 僅僅是一個基礎框架,我們還需要進一步地對其擴展才能應用到實際的WEB 自動化測試項目中去,例如擴展對更多的控件的支持。下面是一個對Activate 函數擴展Image 對象的點擊操作的過程:

    (1 )首先打開SAFFRON 框架的VBS 文件,找到開頭的變量定義處,添加Image 對象,讓框架可以識別和支持Image 對象:
         ' 擴展對Image 對象的支持
         objects = "Link|WebButton|WebList|WebEdit|Image"
         objectsDescription = "micclass:=Link|micclass:=WebButton|micclass:=WebList|micclass:=WebEdit|micclass:=Image"

    (2 )修改Activate 方法,添加對Image 對象的Click 操作的支持,腳本修改成如下所示:
         ' Activates an object based upon its object type
         ' objtype - the type of object should be limited to values in the object array
         ' text    - identifying text for the control - for a link, it's the text of the link
         Public Function Activate (objtype, text)
          localDesc = ""
          If thirdlevel <> "" Then
           localDesc = GenerateDescription(level(2))
          Else
           localDesc = GenerateDescription(level(1))
          End If
        
          AutoSync()
        
          Select Case objtype
          Case  "Link"
           Execute localDesc & GenerateObjectDescription("Link","innertext:=" & text) & "Click"
           Report micPass, "Link Activation", "The Link " & Quote(text) & " was clicked."
          Case "WebButton"
           Execute localDesc & GenerateObjectDescription("WebButton", "value:=" & text) & "Click"
           Report micPass, "WebButton Activation", "The WebButton " & Quote(text) & " was clicked."
          ' 擴展對Image 類型的按鈕的支持
          Case "Image"
           Execute localDesc & GenerateObjectDescription("Image", "alt:=" & text) & "Click"
           Report micPass, "ImageButton Activation", "The ImageButton " & Quote(text) & " was clicked."
          End Select
         End Function

    (3 )調試和測試修改后的腳本,例如采用下面的腳本來看對Activate 函數的擴展是否生效:
         ' 啟動瀏覽器
         Launch "website","http://127.0.0.1:1080 "
         ' 導航到“http://127.0.0.1:1080/WebTours ”
         BrowseTo "http://127.0.0.1:1080/WebTours/ "
        
         ' 輸入用戶名
         EnterTextIn "username","chennengji"
         ' 輸入密碼
         EnterTextIn "password","123"
        
         ' 單擊Login 按鈕
         Activate "Image","Login"
        
         ' 單擊"Flights" 按鈕
         Browser("Web Tours").Page("Web Tours").Frame("navbar").Image("Search Flights Button").Click
        
         ' 獲取航班起始城市
         DepartureCity = GetTextFrom( "WebList","depart")
         ' 獲取航班終點城市
         ArrivalCity = GetTextFrom( "WebList","arrive")
         ' 獲取乘客數量
         PassengerNumber = GetTextFrom( "WebEdit","numPassengers")
        
         ' 選擇航班起始城市為"San Francisco"
         SelectFromList  "depart","San Francisco"
        
         If Verify ("Link","administration")= False then
          Reporter.ReportEvent micFail," 檢查鏈接"," 鏈接不存在"
          Else
             ' 點擊名為“administration ”的鏈接
             Activate "Link","administration"
         End IF

      腳本的測試結果如圖所示:

     


     

    延伸閱讀

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

    22/2<12

    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(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>