Parameterize a test

In this exercise, you'll learn how to parameterize your UFT test and run it in multiple iterations, each time with different sets of data.

Create a new test for parameterization

Create a copy of your existing MyFlight test, where you can parameterize data and then see the differences in how UFT runs your test.

Do the following:

  1. Start with the MyFlightApplication solution open in UFT.

    If you've closed and opened UFT, make sure you start it with the WPF Add-in loaded.

  2. In the Solution Explorer, right-click the MyFlight test node, and select Save As.

  3. Save the test in the same location (C:\Users\<username>\Documents\Unified Functional Testing).

    In the File name field, enter MyFlightParameter, and then click Save.

The Solution Explorer switches to display MyFlightParameter test instead, with all the same actions and steps as the original MyFlight test.

Tip: To display both of your tests at the same time, add the MyFlight test back to your solution.

In the Solution Explorer, right click the solution node, and select Add > Add Existing Test. Select the MyFlight test.

Back to top

Add data to your test

In the MyFlightParameter test, update the departure and arrival cities in your test to use parameter values instead of static values. This enables you to test different cities in each test run.

Do the following:

  1. In UFT, display the Data pane. Select View > Data.

  2. Open the FlightFinder action and view it in the Keyword View.

  3. In the fromCity row, click the Value cell, and then click the parameterization button in the right side of the cell.

  4. In the popup displayed, select the DataTable tab.

    Then click + Add New Parameter at the bottom of the popup.

  5. In the Value Configuration Options dialog that opens, leave the default Parameter selection, and define the parameter name as fromCity.

    Leave the Global sheet location selected.

    Click OK to close the dialog box.

    In the Keyword View, the fromCity value is updated to use the new parameter, and the Data Table now lists Los Angeles as the first value in the fromCity column.

  6. Add more data to the fromCity parameter. In the Data table, add the following values under Los Angeles, one value per row:

    • Denver
    • Franfurt
    • London
  7. Create a second parameter for the toCity value. This time, create the parameter directly in the Data table.

    In the Data table, double-click the B column. In the Change Parameter Name dialog, enter toCity as the new parameter name.

    Then, in the Data table toCity column, add the following values, one value per row:

    • Sydney
    • Los Angeles
    • London
    • Frankfurt
  8. Parameterize your toCity step. In the Keyword View, double click the Value cell for the toCity step, and click the parameterization button.

    In the popup, click the DataTable tab, and then double-click the toCity parameter to insert it as the value.

    Press ENTER to complete the step.

    Your Keyword View steps and Data table should now look like this:

  9. Save your test, and continue with Run your parameterized test.

Note: To learn more about UFT data sources and data table types, see More about data sources.

Back to top

Run your parameterized test

Configure UFT to run your test multiple times, each time with a different set of data.

Do the following:

  1. Select Record > Record and Run Settings.

  2. In the Windows Applications tab, select Record and run test on any open Windows application option and click Apply.

  3. Click OK to return to the main UFT window.

  4. Click the MyFlightParameter test tab to display the canvas with your parameterized action.

  5. Do the following to add two new actions to your test, to open and close the MyFlights sample app between test iterations.

    Right-click and select Insert Call to New Action. Name the new actions OpenApp and CloseApp.

  6. Select and drag the OpenApp action to the top of the test.

  7. Open the OpenApp action in the Editor, and add the following step:

    "SystemUtil.Run "C:\Program Files (x86)\Micro Focus\Unified Functional Testing\samples\Flights Application\FlightsGUI.exe"
  8. Open the CloseApp action in the Editor, and add the following step:

    SystemUtil.CloseDescendentProcesses
  9. Select File > Settings > Run node to open the Settings dialog.

  10. In the Data Table iterations section, select Run on all rows. This ensures that UFT runs a test iteration for each row in the Global data sheet.

    Close the dialog box.

  11. Check to see if you need to update
  12. Run your test. Click Run.

    In the Run dialog box:

    • Ensure that MyFlightParameter is selected as the Test Name.
    • On the Results Location tab, select New run results folder.
    • Accept all other defaults.

    Click OK to run your test. The run results open when the test run is complete.

Back to top

Analyze run results

This time, your run results display four different nodes, one for each test iteration. These correspond to the four different rows in the Global data table.

Expand the FlightFinder action nodes for each iteration. Click the fromCity.Select or toCity.Select steps to view step details for each iteration.

Back to top

More about data sources

UFT enables you to add parameter values the following data sources:

  • Global data tables. Data sheets containing parameters and values available to all actions in the test.

    The test runs as many times as there are rows in the data sheet. This is the option used in this exercise.

  • Action data tables. Data sheets containing parameters and values available only to the associated action.

    The action itself will run as many times as there are rows in the data sheet, within a single test iteration.

  • Environment variables. A variable set in your test with a fixed value.

  • Random number. A random number generated by UFT in the test run.

For more details, see Parameterizing Object Values and Value Configuration and Parameterization.

Back to top

Next steps: