



版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、QTP自動化測試腳本' Simple Automation Framework For Remarkably Obvious Notes ' Copyright ? 2006 Mercury Interactive Corporation '' Notes:'' Requires QuickTest Professional 9.1'' Author : Adam Gensler' Created : July 12, 2006' Last Updated : September 11, 2006''
2、; This prototype framework is provided AS IS, and is meant ' to be used for instructional purposes.'' This framework is a prototype, and is not supported ' by Mercury Interactive.''* initialized = falsethirdlevel = "" level = ""desc = ""object =
3、""objectDescription = ""levelsubdescriptiondelimiter = ","leveldescdelimiter = "|"objectdelimiter = "|"leveldelimiter = "|"objectsDescriptiondelimiter = "|"webLevels = "Browser|Page|Frame"webLevelsDesc = "micclass:=
4、Browser|micclass:=Page|micclass:=Frame|"' 擴展對 Image,WebRadioGroup對象的支持 objects ="Link|WebButton|WebList|WebEdit|Image|WebElement|WebCheckBox|WebRadioGroup|"objectsDescription ="micclass:=Link|micclass:=WebButton|micclass:=WebList|micclass:=WebEdit|micclass:=Image|micclass:=We
5、bElement|micclass:=WebCheckBox|micclass:=WebRadioGroup|"' Generates a generic description based up on the "level" viarable ' levelstr - will be one of the values that is in the level array' returns - string representative of the object hierarchy Public Function GenerateDes
6、cription (levelstr)l = IndexOf(level, levelstr)If l >=0 Thenfdesc = level(0) & "(" & Quote(desc(0) & ")."If l >= 1 Thenfdesc = fdesc + level(1) & "(" & Quote(desc(1) & ")."If 2 >= l ThenIf thirdlevel <> "" Thenf
7、desc = fdesc + level(2) & "(" & Quote(desc(2) & "," & Quote("name:=" & thirdlevel) & ")."End IfEnd IfEnd IfEnd IfGenerateDescription = fdescEnd Function' Generates an object description based upon the object, and objectDescription a
8、rrays' obj - name of the object in the object array ' prop - additional property to help uniquely identify the object ' returns - a string representative of the object description Public Function GenerateObjectDescription (obj, prop)i = IndexOf(object, obj) ndesc = ""If i <&
9、gt; -1 Thenndesc = obj & "(" & Quote(objectDescription(i) & "," & Quote(prop)& ")." End IfGenerateobjectDescription = ndesc End Function' given an array, returns the index of the value to search for ' ary - an array' str - value to search
10、 for in an array' returns - index in arrayPublic Function IndexOf (ary, str)val = -1val = iEnd IfNextIndexOf = valEnd Function' configures framework to work within the context of a specific frame ' val - the Name of the frame to work within - use Object Spy if you don't ' already
11、 know the frame namePublic Function WorkInFrame (val)Report micPass, "Enter Frame", "Entered scope of frame " & Quote(val) thirdlevel = valEnd Function' configures the framework to work outside the context of a specific frame Public Function StopWorkingInFrameReport micPa
12、ss, "Exit Frame", "Exited scope of frame " & Quote(thirdlevel)thirdlevel = "" End Function' generates a string with embedded/surrounding quotesPublic Function Quote (txt)Quote = chr(34) & txt & chr(34)End Function' navigate to a site if the browser i
13、s already opened, otherwise run initialization打開指定 URLPublic Function BrowseTo (url)thirdlevel = ""Report micPass, "Navigate to URL", "Navigating to URL: " & Quote(url)If initialized ThenExecute GenerateDescription("Browser") & "Navigate " &a
14、mp; Quote(url)ElseLaunch "website", urlEnd IfReporter.Filter = rfDisableAllEnd Function' waits for the web page to finish loading等待 WEB頁面打開完全后再繼續(xù)執(zhí)行程序Public Function AutoSyncExecute GenerateDescription("Browser") & "Sync"End Function' close all opened browser
15、s關(guān)閉頁面Public Function CloseBrowsers' prepares the framework for usage, and configures all internal framework' variables and structures' apptype - used to launch different types of applications based ' upon different technologies - currently there is only web ' val - string that re
16、presents what to launch ' returns - always returns truePublic Function Launch (apptype, val)If "website" = apptype Thenthirdlevel = ""Report micPass, "Initialize", "Initializing Framework"level = split(webLevels, leveldelimiter, -1, 1)desc = split(webLevel
17、sDesc, leveldescdelimiter, -1, 1) object = split(objects, objectdelimiter, -1, 1) objectDescription = split(objectsDescription,objectsDescriptiondelimiter,-1, 1)CloseBrowsersSet IE = CreateObject("InternetExplorer.Application")IE.visible = trueIE.Navigate valWhile IE.Busywait 1WendEnd Ifin
18、itialized = trueLaunch = trueEnd Function' 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,
19、 it's thename of the control ' - for a frame, it's the name of the frame Public Function Verify (objtype, text)rval = falselocalDesc = ""estr = ""If thirdlevel <> "" ThenlocalDesc = GenerateDescription(level(2)ElselocalDesc = GenerateDescription(level(
20、1)End IfAutoSync()Select Case objtypeCase "Page"Execute "rval = " & GenerateDescription(level(1) & "Exist (0)"If rval ThenExecute "title = " & GenerateDescription(level(1) & "GetROProperty(" & Quote("title") & "
21、)"If title = text Thenrval = trueElserval = falseEnd IfEnd IfCase "CurrentFrame"If thirdlevel <> "" Thenestr = "rval = " & localDescEnd IfCase "Link"estr = "rval = " & localDesc & GenerateObjectDescription("Link", &qu
22、ot;innertext:=" & text)Case "WebButton"estr = "rval = " & localDesc & GenerateObjectDescription("WebButton", "value:=" & text)Case "WebList"estr = "rval = " & localDesc & GenerateObjectDescription("WebList&
23、quot;, "name:=" & text)Case "WebEdit"estr = "rval = " & localDesc & GenerateObjectDescription("WebEdit", "name:=" & text)End SelectIf estr <> "" ThenExecute estr + "Exist (0)"End IfIf rval ThenReport micPass,
24、 objtype & " Verification", "The " & objtype & " " & Quote(text)& " was verified to exist" ElseReport micFail, objtype & " Verification", "The " & objtype & " " & Quote(text) & " was no
25、t found"End IfIf "True" = rval Thenrval = TrueElserval = FalseEnd IfVerify = rvalEnd Function' 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 lin
26、k,it's the text of the link Public Function Activate (objtype, text) localDesc = ""If thirdlevel <> "" ThenlocalDesc = GenerateDescription(level(2) ElselocalDesc = GenerateDescription(level(1) End IfAutoSync()Select Case objtype Case "Link"Execute localDesc &a
27、mp; GenerateObjectDescription("Link","innertext:=" & text) & "Click"Report micPass, "Link Activation", "The Link " & Quote(text) & " was clicked."Case "WebButton"Execute localDesc & GenerateObjectDescription(&q
28、uot;WebButton", "value:="& text) & "Click"Report micPass, "WebButton Activation", "The WebButton " & Quote(text) & " was clicked."' 擴展對 Image 類型的按鈕的支持Case "Image"Execute localDesc & GenerateObjectDescription(&qu
29、ot;Image", "name:=" & text) & "Click"Report micPass, "ImageButton Activation", "The ImageButton" & Quote(text) & " was clicked."' 擴展對 WebCheckBOX選中或撤銷選中支持Case "WebCheckBox"Execute "texts = " & localDes
30、c & GenerateObjectDescription("WebCheckBox","name:=" & text) & "GetROProperty (" &Quote("checked") & ")"If texts=0 ThenExecute localDesc & GenerateObjectDescription("WebCheckBox","name:="&text) & &q
31、uot;Set"&Quote("ON")ElseExecute localDesc & GenerateObjectDescription("WebCheckBox","name:="&text) & "Set"&Quote("OFF")End IfReport micPass, "WebCheckBox Activation", "The WebCheckBox " & Quote(text)&a
32、mp; " was clicked."End SelectEnd Function' 判斷 WebCheckBox當前狀態(tài),如果是 0 則位選中, 1 為選中Public Function isWebchecked(text)localDesc = ""If thirdlevel <> "" ThenlocalDesc = GenerateDescription(level(2)ElselocalDesc = GenerateDescription(level(1)End IfAutoSync()Execute &
33、quot;texts = " & localDesc & GenerateObjectDescription("WebCheckBox","name:=" & text) &"GetROProperty (" &Quote("checked") & ")"isWebchecked=textsEnd Function' 根據(jù) Index:=N 的值進行 Click, 目前只實現(xiàn)了 WebCheckBox Public Functio
34、n ActivateForIndex(objtype,i)localDesc = ""If thirdlevel <> "" ThenlocalDesc = GenerateDescription(level(2) ElselocalDesc = GenerateDescription(level(1)End IfAutoSync()Execute "texts = " & localDesc &GenerateObjectDescription("WebCheckBox","
35、index:=" & i) & "GetROProperty(" & Quote("checked") & ")"If texts=0 ThenExecute localDesc &GenerateObjectDescription("WebCheckBox","index:=" & i) &"Set"&Quote("ON")ElseExecute localDesc &Ge
36、nerateObjectDescription("WebCheckBox","index:=" & i) &"Set"&Quote("OFF")End IfReport micPass, "WebCheckBox Activation", "The WebCheckBox " & Quote(i) & " was clicked."End Function' 點擊 WebRadioGroup'valu
37、e為 WebRadioGroup Value'index為單選框索引,從0 開始Public Function ActivateWebRadioGroup(value,i)localDesc = ""If thirdlevel <> "" ThenlocalDesc = GenerateDescription(level(2)ElselocalDesc = GenerateDescription(level(1)End IfAutoSync()Execute localDesc &GenerateObjectDescripti
38、on("WebRadioGroup","Value:=" & value) & "Select(" & Quote("#"&i) & ")"Report micPass, "WebRadioGroup Activation", "The WebCheckBox "&Quote(value)&" 的"& Quote(i) & " was clicked.&q
39、uot;End Function' 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 selectPublic Function SelectFromList (objname, text)localDesc = ""rv = ""
40、;rval = falseIf thirdlevel <> "" ThenlocalDesc = GenerateDescription(level(2)ElselocalDesc = GenerateDescription(level(1)End IfAutoSync()localDesc = localdesc & GenerateObjectDescription("WebList", "name:=" &objname)Execute "cnt = " & localDe
41、sc & "GetROProperty(" & Quote("items count") & ")"For i = 1 to cntExecute "rv = " & localDesc & "GetItem (" & i & ")"If rv = text Thenrval = trueEnd IfNextIf rval ThenExecute localDesc & "Select " &
42、amp; Quote(text)End IfIf rval ThenReport micPass, "WebList Selection", "The WebList item " & Quote(text) & "was selected."ElseReport micFail, "WebList Selection", "The WebList item " & Quote(text) & "was NOT found."End IfSel
43、ectFromList = rvalEnd Function' 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 = trueIf thirdlevel <>
44、 "" ThenlocalDesc = GenerateDescription(level(2) ElselocalDesc = GenerateDescription(level(1) End IfAutoSync()localDesc = localdesc & GenerateObjectDescription("WebEdit", "name:=" &objname)Execute localDesc & "Set (" & Quote(text) & ")
45、"Report micPass, "Enter Text", "Text: " & Quote(text) & " was entered into " &Quote(objname)EnterTextIn = rvalEnd Function' 根據(jù) index 給指定 WebEdit 賦值Public Function EnterTextInI (text,i)localDesc = ""rval = trueIf thirdlevel <> "&
46、quot; ThenlocalDesc = GenerateDescription(level(2)ElselocalDesc = GenerateDescription(level(1)End IfAutoSync()localDesc = localdesc&"WebEdit("&Quote("micclass:=WebEdit")&","&Quote("index:="&i)&")."Execute localDesc & "
47、;Set (" & Quote(text) & ")"Report micPass, "Enter Text", "Text: " & Quote(text) & " was entered into " &Quote(objname)EnterTextIn = rvalEnd Function' Obtains text from a control' objtype - is the type of control the get the tex
48、t from ' objname -is the name of the control - use Object Spy if you don't know the name ' returns - the text of the controlPublic Function GetTextFrom (objtype, objname)text = ""localDesc = ""If thirdlevel <> "" ThenlocalDesc = GenerateDescription(lev
49、el(2)ElselocalDesc = GenerateDescription(level(1)End IfAutoSync()Select Case objtypeCase "WebEdit"Execute "text = " & localDesc & GenerateObjectDescription("WebEdit", "name:=" & objname) & "GetROProperty (" & Quote("value&quo
50、t;) & ")" Case "WebList"Execute "text = " & localDesc & GenerateObjectDescription("WebList", "name:=" & objname) & "GetROProperty (" & Quote("value") & ")" End SelectReport micPass, "Capt
51、ure Text", "Text: " & Quote(text) & " wascaptured from thecontrol " & Quote(objname)GetTextFrom = textEnd Function' 獲取 DIV 中 WebElement的值'classNames,DIV的 Class 值。Public Function GetFromWebElement(classNames)text = ""localDesc = ""If th
52、irdlevel <> "" ThenlocalDesc = GenerateDescription(level(2)ElselocalDesc = GenerateDescription(level(1)End IfAutoSync()Execute "set doc="& localDesc&"object"for each element in doc.allinnerText=element.InnerTextclassName=element.ClassNameIf className=class
53、Names thentext=innerTextEnd IfNext' MsgBox InStr(text,Chr(13)'If InStr(text,Chr(13)>0 Then' Report micFail,"提交結(jié)果提示信息 ",text' Else' Report micPass,"提交結(jié)果提示信息 ",text' End If GetFromWebElement=textEnd Function' 如果頁面中存在多個需要點擊的對象時,需要指定順序,一般默認第一次點擊是 0,后續(xù)為
54、1,2,3.N'objtypes,點擊的對象名, WebButton、LinkPublic Function ActivateMoreSameObject(objtypes, texts,i) text = ""localDesc = ""If thirdlevel <> "" ThenlocalDesc = GenerateDescription(level(2)ElselocalDesc = GenerateDescription(level(1)End IfAutoSync()Execute "se
55、t oDesc=Description.Create"If objtypes="WebButton" ThenoDesc( "micclass" ).value = "WebButton"oDesc( "value" ).value = textsExecute "Set colObject =" & localDesc & " ChildObjects( oDesc )"Execute "colObject(i).Click"E
56、nd IfIf objtypes="Link" ThenoDesc( "micclass" ).value = "Link"oDesc( "innertext" ).value = textsExecute "Set colObject =" &localDesc & " ChildObjects( oDesc )"Execute "colObject(i).Click"End IfIf objtypes="WebElement&
57、quot; ThenoDesc("micclass").value = "WebElement"oDesc("innertext").value = textsExecute "Set colObject =" &localDesc & " ChildObjects( oDesc )"'Execute "colObject(i).FireEvent"&Quote("onmousedown")&""
58、Execute "colObject(i).Click"End IfIf objtypes="WebTable" ThenoDesc("micclass").value = "WebTable"oDesc("tagName").value = textsExecute "Set colObject =" &localDesc & " ChildObjects( oDesc )" 'Execute "colObject(i)
59、.FireEvent"&Quote("onmousedown")&"" Execute "colObject(i).ChildItem(1,5,"&Quote("Link")&",0).Click" EndIfReport micPass, "ActivateMoreSameObject", Quote(objtypes) &":" & Quote(texts) & "was ca
60、ptured from the control "End Function' 雙擊網(wǎng)頁對話框中 WebTable中指定行列 , 該行列為 WebElement,Window對象沒有運行時屬性,需要手工將對象加入 object 庫中。Public Function DblclickWindTable(classname,i,text)'className'dblclickExecute "set WinDesc=" & "Window(" & Quote("Windows InternetExpl
61、orer") & ").Window(" & Quote("micclass:=Window") & ").Page(" &Quote("micclass:=Page")&")"Execute "setobjWebElement=WinDesc.WebTable("&Quote("className:="&classname)&","&Quote(&quo
62、t;index:="&i)&")"&".WebElement("&Quote("innerText:="&text)&")" Execute "objWebElement.FireEvent"&" "&Quote("ondblclick") Report micPass, "WebTable CellData", "TableRow: " &a
63、mp;Quote(TableRow)&" , TableColumn:" & Quote(TableColumn) & " be dblCliked "End Function' 獲取網(wǎng)頁對話框中的 WebTable中指定行列值Public Function GetWindTable(classname,i,TableRow,TableColumn)text = ""Execute "set WinDesc=" & "Window(" & Quot
64、e("Windows InternetExplorer") & ").Window(" & Quote("micclass:=Window") & ").Page(" &Quote("micclass:=Page")&")"Execute"text=WinDesc.WebTable("&Quote("className:="&classname)&","
65、&Quote("index:="&i)&")"&".GetCellData("&TableRow&","&TableColumn&")"Report micPass, "WebTable CellData", "TableRow: " &Quote(TableRow)&" , TableColumn:" & Quote(TableColumn) &a
66、mp; " be dblCliked "GetWindTable=textEnd Function' 給網(wǎng)頁對話框中的 WebEdit 賦值Public Function WindowEnterTextIn (objname, text)rval = trueExecute "set WinDesc=" & "Window(" & Quote("Windows InternetExplorer") & ").Window(" & Quote("micclass:=Window") & ").Page(" &Quote("micclass:=Page")&")"Execute "texts= WinDesc.WebEdit("&Quote("name:="&objname)&").Set ("& Quote(text) & ")"Report micPass, "Enter Text", "
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年商業(yè)、飲食、服務業(yè)專用設備項目建議書
- 環(huán)保之道生活之美
- 商務會合同范本
- 醫(yī)療人才引進合同范本
- 2025年衛(wèi)星整流罩項目合作計劃書
- 入學申請書格式范文大全
- 茶藝師競賽練習測試卷
- 大暑節(jié)氣營銷策略
- 農(nóng)村建房手續(xù)辦理委托書范本模板
- 吊籃借用合同范例
- 公司內(nèi)部辦公用品采購預算表
- 四川省南充市2025屆高三下學期高考適應性考試(二診)語文試題(含答案)
- 湖北省2025屆高三下學期2月調(diào)考語文試題及參考答案
- 2025年湖南國防工業(yè)職業(yè)技術(shù)學院單招職業(yè)技能測試題庫完整版
- 2025年《地陪導游服務程序》公開課標準教案
- 愛耳日完整課件
- 2025年國電投核能限公司招聘高頻重點模擬試卷提升(共500題附帶答案詳解)
- 云南省2025年中考化學第三次模擬考試試題含答案
- 系統(tǒng)集成項目售后服務方案
- 2024年南寧市良慶區(qū)招聘專職化城市社區(qū)工作者筆試真題
- 蘇科版(2025新版)八年級下冊物理第七章 力 單元測試卷(含答案)
評論
0/150
提交評論