HP Man UFT11.53 Tutorial API Testing PDF
HP Man UFT11.53 Tutorial API Testing PDF
Legal Notices
Warranty
The only warranties for HP products and services are set forth in the express warranty statements
accompanying such products and services. Nothing herein should be construed as constituting an
additional warranty. HP shall not be liable for technical or editorial errors or omissions contained
herein.
Copyright Notice
© Copyright 1992 - 2013 Hewlett-Packard Development Company, L.P.
Trademark Notices
Adobe® and Acrobat® are trademarks of Adobe Systems Incorporated.
Intel® and Pentium® are trademarks of Intel Corporation in the U.S. and other countries.
Microsoft®, Windows®, Windows® XP, and Windows Vista ® are U.S. registered trademarks of
Microsoft Corporation.
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
Documentation Updates
The title page of this document contains the following identifying information:
l Document Release Date, which changes each time the document, is updated.
l Software Release Date, which indicates the release date of this version of the software.
To check for recent updates or to verify that you are using the most recent edition of a document, go
to: www.hp.com/go/livenetwork. This site requires that you register for an HP Passport and sign in.
To register for an HP Passport ID, go to: http://h20229.www2.hp.com/passport-
registration.html
Or click the New users - please register link on the HP Passport login page.
Support
Visit the HP Software Support Online web site at:
http://www.hp.com/go/hpsoftwaresupport
This web site provides contact information and details about the products, services, and support
that HP Software offers.
HP Software online support provides customer self-solve capabilities. It provides a fast and
efficient way to access interactive technical support tools needed to manage your business. As a
valued support customer, you can benefit by using the support web site to:
Most of the support areas require that you register as an HP Passport user and sign in. Many also
require a support contract. To register for an HP Passport ID, go to:
http://h20229.www2.hp.com/passport-registration.html
http://h20230.www2.hp.com/new_access_levels.jsp
Contents
Contents 5
About the Tutorial for Testing 7
Topic Types 7
Testing Process 15
UFT Window 17
Using Multiple Data Sources and Custom Code in Your Web Service Tests 61
After completing the tutorial, you can apply the skills you have learned to testing the GUI-less layer
of your own application or Web site.
Note: To learn more about creating and running GUI tests, see the UFT Tutorial for GUI
Testing, available from the < UFT installation folder>\help directory.
Note: This tutorial refers to file system paths that are relevant for Windows 7 operating
systems. The paths in other operating systems may be slightly different.
Topic Types
The content in the UFT guides is organized by topics. Three main topic types are in use: Concepts,
Tasks, and Reference.
Getting to l Readme provides the latest news and information about UFT. Select Start
Know UFT > All Programs > HP Software > HP Unified Functional Testing >
Documentation Readme.
l Tutorials teach you basic UFT skills for GUI testing and API testing and
show you how to design tests for your applications. Select Help > UFT
Tutorial.
l HP Run Results Viewer User Guide describes how to use the Run Results
Viewer to view and analyze the run results from your tests or components.
l HP UFT Object Model Reference for GUI Testing describes UFT test
objects, lists the methods and properties associated with each object, and
provides syntax information and examples for each method and property.
Resource Description
HP Software Opens the HP Software Support Web site. This site enables you to browse
Support Site the HP Software Self-solve knowledge base. You can also post to and
search user discussion forums, submit support requests, download patches
and updated documentation, and more. Choose Help > HP Software
Support. The URL for this Web site www.hp.com/go/hpsoftwaresupport.
Testing Forums Opens the testing forums for GUI Testing, API Testing, and BPT Testing
forums. where you can interact with other users of UFT and discuss topics
related to GUI Testing, API Testing, and BPT.
l GUI Testing: http://h30499.www3.hp.com/t5/Unified-Functional-
Testing/bd-p/sws-Fun_TEST_SF
l BPT: http://h30499.www3.hp.com/t5/Business-Process-Validation/bd-
p/sws-BPT_SF
UFT Product Opens the HP Unified Functional Testing product page, with information and
Page related links about UFT.
Troubleshooting Opens the Troubleshooting page on the HP Software Support Web site
& Knowledge where you can search the HP Software Self-solve knowledge base. Choose
Base Help > Troubleshooting & Knowledge Base. The URL for this Web site
is http://h20230.www2.hp.com/troubleshooting.jsp.
HP Software Opens the HP IT Experts Community site, where you can interact with other
Community Site HP software users, read articles and blogs on HP software and access
downloads of other software products.
Manuals Site Opens the HP Software Product Manuals Web site, where you can search
for the most up-to-date documentation for a selected HP Software product.
The URL for this Web site is
http://support.openview.hp.com/selfsolve/manuals (requires an HP
Passport).
Resource Description
What's New Opens the UFT What's New Help, describing the new features and
enhancements in this version of UFT.
HP Software Opens the HP Software Web site. This site provides you with the most up-
Web site to-date information on HP Software products. This includes new software
releases, seminars and trade shows, customer support, and more. Choose
Help > HP Software Web site. The URL for this Web site is
www.hp.com/go/software.
You can access the following sample applications from the Start menu. These applications are the
basis for many examples in this guide:
l Mercury Tours sample Web site. The URL for this Web site is http://newtours.demoaut.com.
l Mercury Flight application. To access from the Start menu, select All Programs > HP
Software > HP Unified Functional Testing > Sample Applications > Flight API / Flight
GUI.
Note: It is recommended to work with an soft copy of this tutorial because there are sections in
which you will be asked to copy and paste test information into UFT.
If you would like, you can open a PDF of this tutorial from your <Unified Functional Testing
installation folder>\help folder.
You can access the HTML version of this tutorial, by selecting Help > Unified Functional
Testing Tutorial.
Testing Process 15
UFT Window 17
l Does the service/application respond quickly enough for the intended users?
By answering these questions, you can design a test more effectively. An effective automated
testing process helps you make more informed release decisions, reduces system downtime, and
prevents availability problems.
Manual testing is time-consuming and tedious, and requires a heavy investment in human
resources. Worst of all, time constraints often make it impossible to manually test every feature
thoroughly before the application is released. This leaves you wondering whether serious bugs have
gone undetected.
Automated API testing with UFT addresses these problems by dramatically speeding up the testing
process. You can create tests that check all aspects of your application, and then run these tests
every time your application changes.
As UFT runs, it simulates the application running by performing application processes in your
application. However, UFT does this faster than any human user.
Reliable Tests perform precisely the same operations each time they are run, thereby
eliminating human error.
Repeatable You can test how the application reacts after repeated performance of the
same operations.
Programmable You can program sophisticated tests that reveal hidden information.
Comprehensive You can build a set of tests that covers every feature in your application.
Reusable You can reuse tests even if the application being tested changes.
Examples of such resources include WSDL or WADL files, REST Services, external data
sources, or virtualization projects for your service calls. You need to import or create these
resources in UFT.
You also need to configure UFT settings so that UFT will perform any additional tasks you may
need, such as displaying a results report each time you run a test, enabling or disabling
debugging for the test run, or configuring SAP server connection information.
You can create one or more empty tests, add test steps to these tests, and define the input,
output, and checkpoint properties for these steps.
You can also add all your tests (or components) to a single solution. A solution enables you to
store, manage, and edit any related tests together, without having to close one test before
opening another.
n Validate test steps by selecting checkpoint properties and entering expected values for
the step properties
n Broaden the scope of your test and test how your application performs the same activities
with multiple sets of data by replacing fixed values with parameters.
n Add additional functionality to your test steps with custom code activities, event handlers,
or custom activities created using UFT's Activity Wizard.
This tutorial includes a step for creating an event handler. For additional details about custom
code, see the HP Unified Functional Testing User Guide.
6. Reporting defects
If you have ALM installed, you can report defects you discover to a database. ALM is the HP
test management solution.
For details about working with ALM, see the HP Application Lifecycle Management User
Guide. For details about using UFT with ALM, see the section on ALM integration in the
HP Unified Functional Testing User Guide.
The image below shows a UFT window as it would appear right after you create a test, with the test
flow shown in the canvas, and with the toolbar, Toolbox pane, Data pane, and Properties pane
displayed.
Take a few minutes to explore the components of the UFT window. You can then continue to
analyze the application you will be testing in this tutorial.
Document Types
UFT displays open documents in the document pane. Use the document tabs located just below
the toolbar to navigate to open documents and bring them into focus.
l Tests/Business Components. You can create, view, and modify your test or business
component in the canvas, which enables you to edit the flow of your test or component steps.
l User Code Files. Enables you to enter your custom code as an event handler for an existing
test step (in the TestUserCode.cs file) or in other documents you import into UFT.
l Start Page. Welcomes you to UFT and provides links to recent files, descriptions of new
features, product forums, and other support links. You can use the shortcut buttons to open new
and existing documents.
l Internal Browser pages. Enables you to open internet pages for forums and other product
related pages, such as those accessible from the Start Page or the Help menu.
Note: Some menu options that relate to GUI testing functionality are disabled when working
with an API test.
l UFT toolbar. Contains commonly used buttons to assist you in designing your testing
documents.
Note: Some toolbar buttons that relate to GUI testing functionality are disabled when
working with an API test.
Panes
The main UFT window displays the following panes:
Toolbar
Name Button Description Default Location
Solution Displays all tests, components, and user A tab on the left side of the
Explorer code files contained in the currently open UFT window.
solution, and enables you to manage
To display:
these resources.
l Select View >
Solution Explorer.
Toolbox Displays all the activities available to use A tab on the left side of the
in your test, and enables you to drag and UFT window.
drop these activities on the canvas.
To display:
l Select View
> Toolbox.
Document N/A Displays all open documents. Each An unlabeled pane in the
Pane document has a tab that you can click to center of the UFT window.
bring the document into focus. Each document tab is
labeled with the document
name.
Properties Displays all properties for the selected A pane on the right side of
test step or test flow or the properties of the UFT window.
the selected data source (in the Data
To display:
pane).
l Select View
> Properties.
l Double-click a step in
the canvas.
l Right-click a step in
the canvas and select
Properties.
Data Assists you in parameterizing your test. A tab at the bottom of the
UFT window.
To display:
Output N/A Displays the compilation information for A tab at the bottom of the
your test when running or importing UFT window.
custom activities.
To display, select View
> Output.
Errors N/A Displays a list of missing property values A tab at the bottom of the
for test steps, missing references for your UFT window.
current test, or syntax errors found in your
To display, select View
custom code.
> Errors.
Debug Assists you in debugging your test. Tabs at the bottom of the
UFT window. These
There are multiple available debug panes:
panes are not displayed
the Breakpoints pane, Call Stack pane,
by default.
Local Variables pane, Console, Watch
pane, Threads pane, and the Loaded To display:
Modules pane.
l Select View > Debug
Tasks N/A Displays and enables you to manage the A tab at the bottom of the
tasks defined for the current test. UFT window.
Search N/A Displays all occurrences of the search A tab at the bottom of the
Results criteria you define in the Find dialog box or UFT window.
using other Search menu items.
To display:
l Perform a search.
Bookmarks N/A Displays the location of bookmarks in A tab at the bottom of the
your code documents, and enables you to UFT window.
navigate to these bookmarks.
To display, select View
> Bookmarks.
Run Step N/A Displays the run results for a test step run A tab at the bottom of the
Results from the canvas. UFT window.
To display:
UFT applications and files that were accessible from the Start menu in previous versions of
Windows are accessible in Windows 8 from the Start screen or the Apps screen.
l Applications (.exe files). You can access UFT applications in Windows 8 directly from the
Start screen. For example, to start UFT, double-click the HP Unified Functional Testing
shortcut .
n All UFT tools, such as the Password Encoder and the License Validation Utility
l Non-program files. You can access documentation and the link to the Mercury Tours Website
from the Apps screen.
Note: By default, the Start and Apps screens on Windows 8 are set to open Internet Explorer in
Metro Mode. However, if User Account Control is turned off on your computer, Windows 8 will
not open Internet Explorer in Metro mode. Therefore, if you try to open an HTML shortcut from
the Start or Apps screen, such as the UFT Help or Readme file, an error will be displayed.
To solve this, you can change the default behavior of Internet Explorer so that it never opens in
Metro mode. In the Internet Properties dialog box > Programs tab, select Always in Internet
Explorer on the desktop for the in the Choose how you open links option. For more
details, see http://support.microsoft.com/kb/2736601 and
http://blogs.msdn.com/b/ie/archive/2012/03/26/launch-options-for-internet-explorer-10-on-
windows-8.aspx.
In this lesson, you will analyze an application to determine what needs to be tested.
For the purpose of this tutorial, you need to become familiar with the Flight API Application. The
Flight API application is a sample service-based flight reservation application that works with a
flight reservation database. Using this sample application, you can retrieve flights for specific
destinations, create customer orders, update reservations, or delete them. The Flight API
application is available both as a Web Service or a REST Service.
For details about the service's methods and operations, type help in the Flight API application's
command prompt window.
Note: You must have administrator privileges to run the sample API Flights application. If you
are working as a non-administrator user, the application prompts you to run the application as
an administrator.
As you think about how to plan your test, consider the following:
l How is the application organized? Are there separate application processes for each
application task? What are these processes? What are the expected outcomes for each of the
application processes?
l Are there specific operations that are repeated in multiple processes/activities? One
example of such a process is connecting to a login database to verify a user's credentials before
performing application activities. Think of these operations as "reusable" parts.
l What business processes need to be tested? UFT provides a number of API testing
activities technologies. However, if your application uses custom activities not supported out-of-
the-box by UFT, you need to import or create these activities inside UFT.
1. Make sure you have administrator privileges. These are required by Windows to run the sample
HP Flights service.
2. Select Start > (All) Programs > HP Software > HP Unified Functional Testing > Sample
Applications > Flight API > Sample Application. A Command window opens indicating
that the application is available.
Note: When working in Windows 8 or Windows Server 2012, you can access UFT and
UFT tools directly from the Start screen. For more information about working with UFT in
Windows 8, see the HP Unified Functional Testing User Guide.
3. If the window issues a message that the default port 24240 is unavailable, edit the
<installation_directory>SampleApplication\HPFlights_Service.exe.config file in a
text editor. In the appSettings section, replace the 24240 port key with a valid one.
4. Type help in the command window to view the methods included in the application.
As you explore the list of methods included in the application, note the property details provided
for each method. You will need this data later in this tutorial to provide property values for these
methods.
5. Minimize the sample application's Command window. Do not close the Command window, as
this will stop the service.
You are now ready to use this tutorial to create tests on the Flight API application using UFT.
Continue with "Building a Simple Test" on page 29 to create your test.
The solution you create in this exercise will be used for the other tests created as part of
subsequent lessons.
1. Start UFT.
n Select Start > All Programs > HP Software > HP Unified Functional Testing
Note: When the Add-in Manager is displayed, click OK to continue. The Add-in
Manager is relevant for GUI testing only.
The UFT splash screen is displayed while UFT loads. This may take a few seconds.
The Start Page provides links to recent files, information about new features in this version of
UFT, as well as links to helpful support and community forums. In the top-right corner of the
page, you can define options for displaying and closing the Start Page.
a. If it is not already displayed, in the Document pane, click the Start Page tab.
b. In the top-right corner of the Start Page, select the Options drop-down arrow, and then
select Close Start Page after test loads. The Start Page will close automatically after
you create a test.
Click the New button . By default, UFT assumes that you want to create a new test,
and the New Test dialog box opens.
In the Solution Name field, enter the name of your solution. By default, UFT saves the
solution in the same directory as the folder containing your test. If you want to create an
additional directory for solution items, select the Create directory for solution option.
c. Click Create. A blank test opens, with an empty test flow in the canvas.
The test name (Basic Test) and path are displayed in the title bar of the main UFT
window.
In the Solution Explorer, you can see that the test is loaded as part of the Tutorial
Solution solution. Later in this tutorial, you will add additional tests to this solution.
If the Solution Explorer is hidden, click the Solution Explorer button or select View
> Solution Explorer to display it.
This lesson will guide you through the steps of creating tests with standard API activities.
UFT has two different types of activities for use in your test:
UFT supports a number of standard API activities that model common application processes,
including:
n FTP activities for application processes that involve using FTP (File Transfer Protocol)
n JSON and XML string activities for application processes that require conversion of XML and
JSON
n Other Miscellaneous activities, including Custom Code activities, Run and End program
activities, and Report activities.
In addition, there are various common activities directed at testing application processes using
specific technologies, including:
n IBM Websphere MQ activities
n HP Automated Testing Tools activities, which enable you to call a GUI test or action, API
test or action, or Virtual User Generator script from UFT, QuickTest Professional, Service
Test, or LoadRunner to use as part of your test.
l Custom activities
If the standard API activities do not suit your testing needs, you can also create or import
custom activities into your test. You can import a number of different types of custom activities:
n Web Service methods. These activities are stored in a WSDL file that you import into UFT.
n REST Service methods. These activities are created using UFT's REST Service editor and
then used in your test.
n Web Application methods. These activities are stored in a WADL file that you import into
UFT.
n User-designed activities. These activities are user-created using UFT's Activity Wizard,
and then imported into a test.
n .NET Assembly activities. These activities are created when you import a .NET assembly
in a test.
Using these activities, you can create test steps for many different types of application processes.
In this section you will create a simple test step to illustrate the use of the Toolbox and Properties
panes.
b. In the Toolbox pane, expand the String Manipulation category and find the Replace
String string activity.
This activity searches for a specified text string and replaces the string with alternate text.
The text strings to find and replace will be specified in the Properties pane.
2. Create a step.
From the Toolbox pane, drag the Replace String activity onto the canvas and drop it inside the
Test Flow area.
Note: You can also double-click an activity in the Toolbox pane to add it to the canvas.
d. In the Name row, type Change Text and press ENTER. This changes the step name in the
canvas.
In the Properties pane, select the Input/Checkpoints tab. Enter the following values in the
Input section of the Input/Checkpoints tab:
n Case-sensitive: false
a. Click the Run button or press F5 to open the Run dialog box.
b. In the Run dialog box, click Options to expand the dialog box.
a. Select View > Expand All or click the Expand All toolbar button to view all the test steps.
b. In the test step hierarchy in the left pane, click the Change Text node. The step results for
the Change Text step are displayed in the Result Details and Captured Data panes.
c. In the Captured Data pane, view the source and replacement strings and note the result
string, Goodbye world. This is in fact the expected string—the test passed.
d. When you are finished reviewing the results, close the Run Results Viewer.
In the previous step, you manually viewed the output to check if the result of the step matched
the expected value for the step. In this step, you will create a checkpoint for your test step.
Checkpoints allow you to see whether a step is successful without having to manually check
the result. Checkpoints are the means to validate the test—a success or failure is determined
by its checkpoints.
c. In the Checkpoints section (lower section), select the Validate check box in the Results
row to enable the checkpoint.
d. In the Expected value column, type the expected string, Goodbye world.
e. Run the test again. In the Run Results Viewer, expand the test step nodes, and note the
checkmarks by the test step name. This indicates that the checkpoint passed since the
result matched the expected value.
f. When you are finished reviewing the results, close the Run Results Viewer.
Now that you have learned how to create test steps, including adding input and checkpoint
properties for your test steps, you can continue to enhance your tests by linking test steps to one
another. Continue to "Linking Test Steps" on the next page to learn more.
In this section, you will use the output of one step as input for another test step.
In the Toolbox pane, select Concatenate String from the String Manipulation category.
Drag the activity into the canvas and drop it below the Change Text step in the Test Flow.
2. Set the prefix input property for the Concatenate String step.
c. In the Input section (upper section), select the Value cell of the Prefix row.
d. In the Value cell of the Prefix row, click the Link to a data source button . The Select
Link Source dialog box opens.
a. In the Select Link Source dialog box, select the Available steps option.
b. In the left pane, select the Test Flow > Change Text node. The list of available properties
for the Change Text step is displayed in the right pane.
c. In the right pane, double-click the Results node. The canvas now reflects that data is
moving from Change Text to Concatenate String.
Note that the property value for the Prefix step is also displayed as
{Step.OutputProperties.ReplaceStringActivity4.Result}. This indicates that this
property is the result of the output of the Replace String (Change Text) activity.
Note: Although you renamed the Replace String activity in the previous section, UFT
still refers to this activity by its standard (programmatic) name.
a. In the Input section of the Input/Checkpoints tab, select the Suffix row.
b. In the suffix row, enter the text Welcome to the Basic Test. into the property's Value
field.
a. Expand the Run Results tree and select the ConcatenateStringsActivity node. The report
shows the result of the concatenated strings: Goodbye World.Welcome to the Basic
Test.
b. When you are finished reviewing the results, close the Run Results Viewer.
Now that you have learned the basics of linking test steps to one another, you can learn how to link
your test steps to multiple input sources, Continue to "Mapping Test Steps to Multiple Sources" on
the next page to learn more.
In the above section, you used the Available steps source for one value, and manually typed in the
data for another value. In this section, you will create a custom expression to use multiple data
sources as a property value. You will use the Select Link Source dialog box to create an expression
for the Suffix property that uses both manual entry and automatic values from the Available steps
option.
c. In the Input/Checkpoints tab, select the Value cell of the Prefix row.
a. In the Input/Checkpoints tab, select the Value cell of the Suffix row
c. In the Value cell, click the Link data to source button . The Select Link Source dialog
box opens.
a. In the Select Link Source dialog box, click the Custom Expression button to display the
custom expression.
b. In the Expression box, type the following:" was replaced with " (adding a space
before and after the phrase to improve the readability).
a. In the Select Link Source dialog box, select the Available steps option (if not already
selected). A list of available steps for this property is displayed in the left pane.
b. In the left pane, select the Change Text node. The available properties for the Change
Text step are displayed in the right pane.
c. In the right pane, select the Result node in the right pane, and click Add.
The Expression box shows both sources: your manually-entered expression and the
output from the Replace String (Change Text) activity. This string will be added as the
suffix property for the Concatenate Strings step.
d. Click OK to add the custom expression as the Suffix property for the Concatenate String
steps.
b. In the Run Results Viewer, expand the results and select the ConcatenateString node.
The report shows the result of the concatenated strings.
6. When you are done viewing the results, close the Run Results Viewer.
In this section, you will learn how to data drive your test steps.
1. Data drive the input properties for the Change Text step.
c. In the Properties pane, click the Data Drive button. The Data Driving dialog box opens.
o Clear the Configure 'Test Flow' as a ForEach loop using the new data source
option.
This option repeats the Test Flow according to the number of data rows. You will
manually set the number of iterations in a later step.
c. Accept the popup message. The data driving mechanism replaces the constant values
with the new expressions, {DataSource.Change Text_
Input!MainDetails.SourceString}.
b. In the left pane of the Data pane, expand the Change Text_Input node and select the
Change Text_Input!MainDetails node.
The Data pane shows a data table with a column for each input property, and one row of
values corresponding to the input property. In this example, you see the Hello World.
input string and FALSE (or an empty check box if you do not have Excel installed) that you
entered earlier.
In the Change Text_Input!MainDetails sheet, add two additional rows. Make sure to copy the
text exactly, including punctuation where included.
In the Data pane, select the ChangeText_Input!SearchReplaceString node and add two
additional rows to the table. Make sure to copy the text exactly, including punctuation where
included.
1 Hello Goodbye
3 11 12
a. In the Data pane, expand the Change Text_Checkpoints node and select the Change
Text_Checkpoints!MainDetails node.
b. In the first column (under the Result cell), add values to this column as shown below:
Note: In the third row, we will intentionally insert an exclamation point (!) to generate
an error.
Result
Goodbye world.
The number of iterations is the number of times to repeat the step. We will set it to 3,
corresponding to the number of rows of data in our table.
a. Return to the canvas and click inside the Test Flow frame—but not within a test step.
c. In the Input tab, select 'For' Loop and set the Number of Iterations to 3.
Click the Run button or press F5 to compile and run the test. The test runs three times,
using the three lines of data in the table.
When the Run Results Viewer opens, expand the Test Flow node and drill down to the row
with the red X, indicating a failed checkpoint. The checkpoint failed because the expected
result contained an exclamation point, which was not present in the source string.
b. In the third row of the Results column replace the exclamation point with a period.
c. Run the script again and verify that you have no errors in the report.
In the next lesson, you will apply these lessons when working with a custom activity using an
imported Web service.The following lessons will walk you through the process of importing WSDLs
and creating Web service tests.
However, there will also be times where the standard activities do not match the processes your
application performs. In these cases, you will need to use custom activities that you import or
create in UFT, such as Web Services. Using UFT, you can also create tests for your WSDL-based
Web services.
Using Multiple Data Sources and Custom Code in Your Web Service Tests 61
This section shows you how to import the Flight API application's WSDL file.
Make sure that the Flight Application service is available, as described in "Explore the Flight
API Application" on page 25.
b. In the Add New Test to Solution dialog box, select API Test.
The test is added to the Tutorial Solution along with the Basic Test created in the
previous lesson.
In UFT, select Import WSDL > Import WSDL from URL or UDDI from the toolbar. The
Import WSDL from URL or UDDI dialog box opens.
a. In the Import WSDL from URL or UDDI dialog box, Select the URL option.
b. In the address field, enter the URL for the Web Service:
http://localhost:24240/HPFlights_SOAP?wsdl
c. Click OK.
The service is imported into UFT and its methods are displayed in the Toolbox pane under the
Web Services node.
Now that you have imported the service's methods into UFT, you can begin to create test steps
using these methods. Continue to "Building a Web Service Test" on the next page to learn more.
In this section, you will create a new flight order using the HPFlights Web service.
In order to create a flight order, you must first know the available flights. First you will run the
GetFlights step that retrieves all of the flights to your destination. In the next step, you will use the
first flight number returned, as input for the CreateFlightOrder step.
b. In the Properties pane, open the Input/Checkpoints tab and expand the Body >
GetFlights node.
o DepartureCity: Denver
From the Toolbox pane, drag the CreateFlightOrder activity into the Test Flow,below the
GetFlights step.
b. In the Properties pane, open the Input/Checkpoints tab , and fully expand the
CreateFlightOrder > FlightOrder node.
o DepartureDate—use the drop-down to open a calendar and select a date at least two
days in the future.
o FlightNumber—leave this field blank for now. You will set its value in the following
steps.
c. Expand the CreateFlightOrder node and select the Value cell in the FlightNumber row.
d. In the Value cell, click the Link to a data source icon . The Select Link Source dialog
box opens.
e. In the Select Link Source dialog box, select Available steps option.
h. In the Output section, expand all nodes under the Body node by clicking the
GetFlightsResult node and clicking the Add button in the Flight (array) node row to
create the Flight[1] array.
j. Select the FlightNumber element, and click OK. When UFT asks if you want to enclose
the target step in a loop, select No.
a. Return to the canvas and click inside the Test Flow frame but not within a test step.
Click the Run button. Observe the build log in the Output tab.
After the test run is complete, the Run Results Viewer opens automatically.
a. In the Run Results tree (left pane), right- click the parent node and select Expand All.
b. Click the CreateFlightOrder node. The result details for the CreateFlightOrder step are
displayed.
c. In the Captured Data pane, scroll down to the Web service Call HTTP Snapshot section
and look at the Response pane. Note the output of the request—OrderNumber and
TotalPrice. Copy the TotalPrice value to the clipboard for use in the next step.
Tip: Click the Request or Response links to open the SOAP in a separate browser.
When you are finished viewing the results, close the Run Results Viewer.
d. Paste the total price amount from the previous step into the TotalPrice field and select the
Validate check box in the TotalPrice row.
b. When the Run Results Viewer opens after the test run, expand the Run Results tree and
Select the Checkpoints node for CreateFlightOrder step.
The report shows a checkmark and indicates the expected and actual values. If the
expected value was not returned by the server, the report indicates a failure.
When you are finished viewing the results, close the Run Results Viewer.
Now that you have created a test for your Web Service, you can enhance your Web Service test by
using data. Continue to "Integrating Data into Your Web Service Tests" below to learn more.
In the Data pane, click the New Data Source button select Excel. The Add New Excel
Data Source dialog box opens.
b. Enable the Excel file contains header row option, since the sample file contains a header
row.
d. Select Link to the Excel file in its original location as the mode of import. This links to
the Excel file at its original location, so that if data changes, your data source will be
current.
e. Click OK.
2. Link the input properties for the CreateFlightOrder step to the data.
c. In the Input section of the Input/Checkpoints tab, expand all the FlightOrder node and
select the Class row.
d. In the Class row, click the Link to a data source icon . The Select Link Source dialog
box opens.
a. In the Select Link Source dialog box, select the Data source column option. The list of all
available data sheets is displayed.
b. Select the WS_Flights!Input node. The list of all available data columns is displayed.
c. From the list of data columns, select Class in the right pane and click OK. This instructs
the test to refer to this column in the sample data during the test run.
c. In the Checkpoints section (lower section) of the Input/Checkpoints tab, clear the
checkbox in the TotalPrice row. This instructs UFT not to check this property during the
test run.
The navigation settings let you indicate how to use the data in your data source. You can
specify from which row to begin, how many rows to advance, and in what direction to move for
the next set of values. You can also specify what to do when reaching the end of the data
table—wrap around or continue using the last line.
a. In the canvas, click in the Test Flow but not within a step.
c. In the Data Sources tab, select the WS_Flights!Input entry in the table and click Edit to
open the Data Navigation dialog box.
d. In the Data Navigation dialog box, specify the data navigation details:
e. Click OK.
a. Click the Run button and observe the results in the Output window.
b. In the Run Results Viewer, expand the result tree and select the CreateFlightOrder step.
Scroll down within the Captured Data tab and note the data from the Excel file in the
SOAP request (left pane), and the result in the SOAP response (right pane).
When you are finished viewing the results, close the Run Results Viewer.
Now that you have learned how to integrate data into your Web Service tests, you can further
enhance your tests by linking steps to multiple sources and using custom code. Continue with
"Using Multiple Data Sources and Custom Code in Your Web Service Tests" on the next page.
Add a new test called WebServicesCustom to your solution and import the HP Flights Services
WSDL as described in "Importing a Web Service" on page 48.
From the Toolbox pane, drag the activities into the canvas in the following order:
In the Data pane, select New > Excel. In the Add New Excel Data Source dialog box:
d. Select the Link to the Excel file in its original location mode.
c. In the Input/Checkpoints tab, in the Input section, select DepartureCity= Denver, and
ArrivalCity=Los Angeles.
In the Input/Checkpoints tab, expand the FlightOrder node (found under the Body node) and
set the input properties as follows:
n Class: Economy
n CustomerName: Click the Link to a data source button in the right corner of the
CustomerName row. In the Select Link Source dialog box, select Data source column,
and expand the tree to show the WS_Flights!Input node. In the right pane, select the
CustomerName parameter and click OK.
n NumberofTickets. 3
i. Click the Link to a data source button in the right corner of the FlightNumber
row.
ii. In the Link to Source dialog box, select Available steps, expand the Test Flow node,
and click GetFlights.
iv. In the Output section, expand the GetFlightsResult node and click the Add button
in the Flight (array) node row to create the Flight[1] array. Expand the array, select
FlightNumber, and click OK. When prompted to enclose the target step in a loop,
select No.
c. In the Input/Checkpoints tab, click the Add Property button and select Add Input
Property. The Add Input Property dialog box opens.
d. In the Add Property dialog box, create a new String type property called FlightInfo.
In this step you will define a value using multiple sources. In this example, you will set a value
which is a combination of the CustomerName, a constant string, and the OrderNumber:
d. In the Value column of the FlightInfo row, click the Link to a data source button . The
Select Link Source dialog box opens.
e. In the Select Link Source dialog box, click Custom Expression to show the Expression
area.
f. At the top of the Select Link Source dialog box, select the Data source column option.
The list of available data sheets is displayed.
g. In the data sheet list (left pane), select the WS_Flights!Input node. The list of available
data columns is displayed.
i. In the Expression area, type _OrderNumber_ (with the underscores) after the existing
expression.
j. At the top of the dialog box, select the Available steps and expand the Test Flow branch.
The list of available steps is displayed.
m. In the lower pane of the Input/Checkpoints tab, expand the Output Body node, expand the
CreateFlightOrderResponse node, then the CreateFlightOrderResult node, select the
OrderNumber element, and click Add.
{DataSource.WS_Flights!Input.CustomerName}_OrderNumber_{Step.OutputPro
perties.StServiceCallActivity(x).Body.CreateFlightOrderResponse.Create
FlightOrderResult.OrderNumber}
8. Create an event.
In this step you will create an event handler in order to use custom C# code to your test step.
Defining events let you adapt your test to your custom requirements, and perform actions that
are not built-in to UFT. In this example, you will add code that sends a custom string to the
report.
b. In the Properties pane, open the Events tab . A list of default event handlers is
displayed.
c. In the ExecuteEvent row of the Events tab, click the drop down arrow and select Create a
default handler.
In the following example, the index assigned to the event was 12, so the string is
CodeActivity12.Report("Customer and Order
Number",CodeActivity12.Input.FlightInfo);.
In the Run Results Viewer, expand the Test Results tree to the Custom Code step. Note the
new entry in the Captured Data pane: Customer and Order Number.
Tip: You can also use the Report Message activity under the Miscellaneous folder, to
send text and property values to the report.
This section will teach the basic steps in creating your REST Service methods and using them in
your test.
This section describes how to model a REST service activity using the Flight API application. Once
you create a REST Service method, you can reuse the method for different test steps.
Make sure that the Flight Application service is running, as described in "Explore the Flight API
Application" on page 25.
In the Flight API application command window, type h, and press ENTER. A browser opens
with the modeling information for the REST service.
Note: The file containing this information (index.htm) is located in the <installation_
folder>\SampleApplication\Help folder.
a. Copy the Request Body for the FlightOrders > ReserveOrder (POST) method. Only copy
the XML code.
b. Create a new file in a text editor and paste the contents of the clipboard. Make sure to
modify the date in the <DepartureDate> line to a future date.
Add a new test called RESTServiceTest to your solution as described in "Importing a Web
Service" on page 48.
a. Click the Add REST Service toolbar button . The Add REST Service dialog box
opens.
b. In the left pane of the Add REST Service dialog box, click on the New Service node and
rename it to SamplesRESTService.
a. In the Add REST Service dialog box, click the toolbar's Add Resource button . A new
resource is added under your SampleRESTService.
a. In the Add REST Service dialog box, click the Add Method button . A new method is
added under the FlightOrders resource.
d. Return to the left pane and select the FlightOrders node. Note that the value you pasted in
the URL property field for the SampleRESTService node has been passed to the
FlightOrders resource.
e. In the General tab of the right pane, paste /HPFlights_REST in the Relative URL property
row. After you paste this value here and select an area outside the property value row, the
/HPFlights_REST is added to the URL prefix value from the SampleRESTService node.
g. In the HTTP Input/Checkpoints tab of the right pane, paste /FlightOrders/ in the
Relative URL value row. This addition is appended with the URL property value passed
from the FlightOrders node of your REST service.
a. In the Add REST Service dialog box, select the ReserveOrder method node.
b. In the right pane, open the HTTP Input/Checkpoints tab in the right pane.
f. Navigate to the body.xml file you saved in a previous step and click OK to add this XML to
your REST method.
Note that the XML structure saved in the body.xml file is displayed in the Request Body
section (either in Grid form or Text form, depending on which view you have selected).
h. Expand the Request Headers array. The following values are now displayed in the
Request Headers properties:
o Name row: Content-Type
o Value row: text/xml
c. In the Input/Checkpoint tab, select Add > Add Input Property. The Add Input Property
dialog box opens.
d. In the Add Input Property dialog box, add a String type property called Class. You do not
need to provide a default value.
c. Select Add > Add Output Property. The Add Output Property dialog box opens.
d. In the Add Output Property dialog box, add a Int type property called Total_Price.
d. Click the Load XML button and load the body.xml file that you saved earlier.
The property values as defined in the XML from the body.xml file are displayed in the
Request Body grid.
In the Add REST Service dialog box, click the Run Method toolbar button to check the
validity of the method. Scroll through the results and verify that the response body contains an
order number and price.
Click OK in the Add REST Service dialog box. The REST designer adds the REST service,
along with its resource and method to the Toolbox pane, under the Local Activities category.
15. Share the REST activity to make the activity available for all tests.
a. In the Toolbox pane, select the parent node of the REST service, SampleRESTService
b. Right-click the SampleRESTService node and select Move to > File System Activities
from the right-click menu.
The REST service activity is now moved to the File System Activities section in the
Toolbox pane. Any other test can now use this activity.
You have now created a prototype activity for your REST service, complete with input parameters
and the HTTP information. You can now use the methods in your tests. Continue with "Running a
REST Service Test" on the next page to learn how to run the test with these newly-created REST
methods.
This section describes how to run the REST service method created in the previous section. You
will incorporate data into the test, using the sample data file included with the product.
b. In the File System Activities node, expand all the nodes in the SampleRESTService node.
b. In the Properties pane, open the HTTP tab in the Properties pane.
c. Check to make sure that the property values for this step are those which we imported in
the previous section from the body.xml file. These values were used in the test run that we
just performed.
a. In the Run Results tree, click the Expand All button or right-click the Run Results
Tree and select Expand All.
b. In the Run Results tree, select the ReserveOrdernode. The step result details are
displayed for the ReserveOrder step.
c. In the Captured Data pane, click the ResponseBody link to open the response in a
separate browser window.
d. Verify that the Response Body contains values for the OrderNumber and TotalPrice
elements. This corresponds to the operation's description in the REST Service Help page
that indicated the following: It creates a new flight order and returns
OrderNumber and TotalPrice.
Continue to "Assigning Data to a REST Service Test" on the next page to learn how to
enhance your REST method test steps by assigning data values for the method's properties.
a. In the Data pane, expand the Data Source button and select Excel. The New Excel
Data Source dialog box opens.
b. Click the Browse button adjacent to the Excel file path field, and browse to the
sample application's SampAppData Excel file in the <installation
directory>\SampleApplication folder.
c. Select the Excel file contains header row check box, because the sample contains a
header row.
e. Select the Make a copy of the Excel file option. This saves a copy of the data file with
the test.
f. Click OK. The data is imported into the Data pane and the data sheets are displayed in the
Data pane.
2. Link the input properties for the ReserveOrder step to the data source.
c. In the input section (upper section) of the Input/Checkpoints tab, click the Link to a data
source button in the Class row. The Select Link Source dialog box opens.
d. In the Select Link Source dialog box, select the Data source columnoption.
e. In the list of data sources in the left pane, select the REST_FlightsInput node in the left
pane.
f. In the right pane, choose the Class property in the right pane and click OK.
g. Repeat the above step for the other input properties: Customer_Name, Departure_Date,
and Flight_Number.
By setting iterations, we will see how our REST method used multiple sets of data from the
data source.
b. In the Run Results tree, select the ReserveOrder nodes (one under each iteration). The
result details for the ReserveOrder step are display.
c. In the Captured Data pane, scroll down and click the Request Body link. In the browser
window that opens, note that the test used the data from the Data pane for the properties
that we assigned: Class, CustomerName, DepartureDate, and FlightNumber.
We will save the response data from this run for use in future steps.
a. In the Run Results tree, select a ReserveOrder node. Click the Response Body link in
the Captured Data pane. A browser window opens with the XML response.
b. Save the entire contents of the window to a file Response.xml. Close the Run Results
Viewer.
c. The lower section of the HTTP tab contains the output properties or output schema. We
will use these as our checkpoints to check the server response.
d. Click the Load XML button and load the Response.xml file that you saved earlier. The
checkpoint properties and their values from the response.xml file are displayed.
e. In the Checkpoints section (lower section), select the Validate checkbox in the
OrderNumber and TotalPrice rows.
f. Set the value of OrderNumber to Greater than (>) 10, and the value of TotalPrice to
Less than (<) 255.
In the Run Results tree, click the Expand All button . Note that some of the checkpoints
passed, while others did not.
a. In the Run Results tree, select one of the failed checkpoints nodes.
b. In the Captured Data pane, note the Actual Results and Expected Values. In the following
example, the OrderNumber was valid, but the TotalPrice was not valid because it
exceeded 255.
In this lesson, you will learn to use the Resolve Conflict wizard to resolve these differences.
1. In the Toolbox pane, right-click the SampleRESTService node and select Edit Service. The
Edit REST Service dialog box opens.
2. In the Edit REST Service dialog box, select the SampleRESTService node and open the
3. Select the Flight_Number property, and click the Edit Property toolbar button. The Edit
Property dialog box opens.
4. In the Edit Property dialog box, rename the property to Flight_Number_1 and click OK.
5. In the Custom Input/Checkpoints tab, select the Number_of_Tickets property, and click the
Delete Property button in the toolbar. Confirm the warning and click OK.
7. View the canvas. Note the alert icon in the bottom right corner of the ReserveOrder REST
method frame.
8. Click on the drop-down arrow adjacent to the alert icon, and select the text message: This
step should be resolved. Resolve step. The Resolve REST Methods Wizard opens.
9. The wizard's first screen shows the problematic steps. If multiple steps were affected, you
could choose which steps to resolve and which to ignore. In this lesson, there is only one step
in your test, so by default , the ReserveOrder step is selected. Click Next.
10. In the Resolve Conflicts screen, in the Input Properties section (top area of the window), select
the Number_of_Tickets property in the right pane (After changes). Click Keep. This instructs
the existing step to keep the property, even though it was removed from the method's
prototype.
11. In the After changes pane, select the old property Flight_Number and click Remove.
The Flight_Number property is now obsolete. Instead, the method will contain the new,
automatically detected property, Flight_Number_1.
12. Scroll through the lower section of the wizard screen to see a log of all of the conflicts and their
resolutions.
13. Click Next. Click Finish to close the wizard and return to your test.
If no email client is available, copy the information above to a new message in a web mail client,
and send your feedback to DocTeam_UFT@hp.com.