QTP11新特性初解

 

下面是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")

 

Web对象识别之CSS和XPath

 

某些测试工具早就开始应用XPath来进行对象定位了,例如Ranorex(http://www.ranorex.com/)。在新版本的QTP中,对于Web对象的定位,也开始支持使用XPath,还有CSS。

 

下面是一个完整的应用CSS和XPath进行对象定位和识别的例子:

 

How to Use Web Object Identifiers - Exercise

In this exercise, you use XPath and CSS identifiers in a test object description to help locate the correct button in an HTML table.

 

Prerequisites 

Open QuickTest and create a new test.

Disable Smart Identification for the Button test object class by selecting Tools > Object Identification, selecting the Web environment in the Object Identification dialog box, and then selecting the Button test object class from the Test Object classes list.

Disable automatic XPath by selecting Tools > Options > Web > Advanced, and then making sure that the Learn and run using automatic XPath identifiers checkbox is not selected.

 

Create a sample Web application 

Copy the following syntax content into a text document, and save the document with an .html extension. The document is saved as an HTML page.

 

<html>

<head>

<style type="text/css">

body { background: green; color: blue; }

.SelectedRow { color: #22444; background: #ebcbeb; width: 450px; }

.RegularRow { color: #444; background: #cbebeb; width: 450px; }

.BPTRow { color: #D9660E; background: #cbebeb; width: 450px; }

</style>

</head>

<body>

<br><br>

<table onclick="javascript:change();" id="maintab">

<tr class="BPTRow" id=BPT>

<td>

HP Business Process Testing

</td>

<td>

<input type="button" value="Buy">

</td>

</tr>

<tr class="RegularRow" id=QC>

<td>

HP Quality Center

</td>

<td>

<input type="button" value="Buy">

</td>

</tr>

<tr class="SelectedRow" id=QTP>

<td >

HP QuickTest Professional

</td>

<td>

<input type="button" value="Buy">

</td>

</tr>

</table>

</body

</html>

 

 

Learn the button objects in the Web application 

In QuickTest, open the Object Repository Manager, and select Object > Navigate and Learn. QuickTest is hidden, and the cursor changes to a pointing hand.

To verify that QuickTest learned the objects correctly, in the object repository, select each Button object and select View > Highlight in Application. QuickTest highlights each button object in the HTML page.

Rename the Button objects to make them more clear:

Rename Buy to Buy_BPT.

Rename Buy_2 to Buy_QC.

Rename Buy_3 to Buy_QTP.

Remove the ordinal identifiers from the button objects 

Because all of the Button objects have identical property values, when QuickTest learned the objects it assigned an ordinal identifier to each test object based on the location of each object in the application. This may cause QuickTest to identify the objects incorrectly if the sorting order of the buttons in the application changes.

 

Select the first button object to display its object properties on the right side of the object repository window.

In the Ordinal Identifier section, select the Browse button. The Ordinal Identifier dialog box opens.

In the Identifier type drop-down list, select None and close the dialog box. The ordinal identifier is removed from the test object's identification properties.

Repeat steps a- c above for each of the buttons.

Verify that the test object descriptions are no longer unique by selecting each test object and selecting View > Highlight in Application. QuickTest cannot identify the objects.

Add a CSS identifier based on the object's parent-container 

Select the Buy_BPT button. The test object details are displayed on the right side of the object repository window.

In the Object Description section, click the Add button, and add the css property to the test object description.

Copy and paste the following syntax into the Value edit box:

 

 tr.BPTRow input

 

Add an XPath identifier based on the object's parent-container 

Select the Buy_QTP button. The test object details are displayed on the right side of the object repository window.

In the Object Description section, click the Add button, and add the xpath property to the test object description.

Copy and paste the following syntax into the Value edit box:

 

 //TR[@id='QTP']/*/INPUT

 

 

Add an XPath identifier based on the object's sibling-element 

Select the Buy_QC button. The test object details are displayed on the right side of the object repository window.

In the Object Description section, click the Add button, and add the xpath property to the test object description.

Copy and paste the following syntax into the Value edit box:

 

 //td[contains(concat(' ',text(),' '),'Quality')]/../*/INPUT

 

 

Results 

Select each object and select View > Highlight in Application. QuickTest can now identify each button based on the Web object identifiers you added.

 

 

通过Attribute访问Web对象的自定义属性(Accessing Custom Properties of Web-Based Objects

You can use the attribute/* notation to access custom native properties of Web-based objects or events associated with Web-based objects. You can then use these properties or events to identify such objects by adding the notation to the object's description properties using the Object Identification dialog box, or by using programmatic descriptions.

 

Example of using attribute/<property> to identify a Web object 

 

Suppose a Web page has the same company logo image in two places on the page:

<IMG src="logo.gif" LogoID="122">

<IMG src="logo.gif" LogoID="123">

 

You could identify the image that you want to click by adding the attribute/LogoID notation to the object's description properties and using a programmatic description to identify the object:

 

Browser("Mercury Tours").Page("Find Flights").Image("src:=logo.gif","attribute/LogoID:=123").Click 68, 12

 

 

 

Example of using attribute/<event> to identify a Web object 

 

Suppose a Web page has an object with an onclick event attached to it:

 

`'alert('OnClick event for edit.');"

 

You can identify the object by adding the attribute/onclick notation to the object's description properties and using a programmatic description to identify the object:

 

Browser("Simple controls").Page("Simple controls").WebEdit("attribute/onclick:= alert\('OnClick event for edit\.'\);").Set "EditText"

 

  

 

posted on 2010-09-26 21:34  TIB  阅读(2722)  评论(0编辑  收藏  举报

导航