QTP11新特性初解
时间:2010-09-26 来源:TIB
下面是TIB自动化测试工作室初步研究QTP11的一些小结,后续仍会深入研究这些新特性的应用情况:
可视化对象关系识别(Visual Relation Identifiers)
You can now use visual relation identifiers to identify application objects based on other objects that are always near them.
This enables you to create a more reliable identification definition for test objects that are otherwise difficult to differentiate, and to ensure that the identification remains reliable even if the user interface design changes.
QTP的对象识别流程(Object Identification Process Workflow):
这个图可在帮助文档中找到。
Web2.0控件的支持(Web2.0 toolkit support)
QuickTest provides support for the following toolkits:
ASP .NET Ajax - http://www.asp.net/ajax/
Google Web Toolkit (GWT) - http://code.google.com/webtoolkit/
Dojo - http://www.dojotoolkit.org
Yahoo User Interface (Yahoo UI) - http://developer.yahoo.com/yui/
The Web 2.0 Toolkit Support Setup is available from the Add-in Extensibility and Web 2.0 Toolkits option in the QuickTest Professional setup.
用Object属性访问Firefox的DOM
The Web Object property can be used only for supported versions of Internet Explorer and Mozilla Firefox.
For details on the Internet Explorer DOM, see
http://msdn.microsoft.com/en-us/library/ms533022.aspx.
For details on the Firefox DOM, see
https://developer.mozilla.org/En/DOM.
嵌入JS并执行(Embed or Run JavaScripts in Your Web Pages)
You can use the new EmbedScript/EmbedScriptFromFile and RunScript/RunScriptFromFile functions to embed JavaScripts in all loaded browser pages and frames or to run JavaScripts in specific pages. Use these scripts to perform operations on, or retrieve data from, the browser pages in your application.
例:
Sub EmbedScriptFromFile_Example()
'The following example uses the EmbedScriptFromFile to embed a jQuery function in the browser,
'and then uses the RunScript method to retrieve the number of search results found in a Web search engine.
'It then calculates the last 10 results, navigates to a new page, and displays the specified results.
'Embed the jQuery script
Browser("MySearchEngine").EmbedScriptFromFile "c:\jquery-1.3.2.js"
searchTerm = "EmbedScript QTP"
Browser("MySearchEngine").Page("MySearchEngine").WebEdit("q").Set searchTerm
Browser("MySearchEngine").Page("MySearchEngine").WebButton("Search the Web").Click
'Find the resultStats element with the 3rd bold tag (zero based) under it, and get the text
resultCount = Browser("MySearchEngine").Page("MySearchEngine").RunScript("$('#resultStats').children('b').eq(2).text()")
'Calculate the location of the 10th to last result
lastPage = CLng(resultCount) - 10
'Navigate to a new page, and instruct the browser to display the last 10 results
Browser("MySearchEngine").Navigate "http://www.MySearchEngine.com/search?hl=en&q=" & searchTerm & "&start=" & lastPage & "&filter=0"
End Sub
自动参数化
You can instruct QuickTest to automatically parameterize the steps in your test's actions at the end of a recording session.
You activate this option by selecting the Automatically parameterize steps option in the General tab of the Options dialog box. You can set the option to use Global Data Table Parameters or Test Parameters.
录制完就自动参数化了,例如:
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set DataTable("WinEdit_Text", dtGlobalSheet)
Dialog("Login").WinEdit("Password:").SetSecure DataTable("WinEdit_Text_1", dtGlobalSheet)
Dialog("Login").WinButton("OK").Click
动态加载函数库
The new LoadFunctionLibrary statement lets you load a function library when a step runs instead of at the beginning of a run session. This means, for example, that you can define conditional steps that use functions from various function libraries, but load only the required function libraries during a run session.
例:
Dim strCurrentLibPath
Const strFrenchLibPath = "[QualityCenter\Resources] Resources\QTP Resources\French\"
Const strEnglishLibPath = "[QualityCenter\Resources] Resources\QTP Resources\English\"
Const strDefaultLibPath = "[QualityCenter\Resources] Resources\QTP Resources\Default\"
' Determine the function libraries to load during the run session
If Environment.Value("Language") = "French" then
strCurrentLibPath = strFrenchLibPath
else if Environment.Value("Language") = "English" then
strCurrentLibPath = strEnglishLibPath
Else
strCurrentLibPath = strDefaultLibPath
End if
' Load the relevant function libraries for the current environment's language
LoadFunctionLibrary strCurrentLibPath + "DialogCrashChecks.qfl", strCurrentLibPath + "DialogL18NChecks.qfl"
' Perform a set of window object checks using the PerformDialogCrashChecks function from the DialogCrashChecks.qfl function library loaded in the previous step
PerformDialogCrashChecks Window("MyApplication")
' Perform a set of window object checks using the PerformL18NDialogChecks function from the DialogL18NChecks.qfl function library loaded previously
PerformL18NDialogChecks Window("MyApplication")