Add data sources to an API test

Relevant for: API testing only

This topic describes how to add data sources to API tests. Do this to data-drive your tests by pulling property values from your test's data sources.

Note: For details about data handling for GUI tests and the GUI testing Data Pane, see Data Pane.

Add an Excel data source

Add an Excel data source to data drive your test from an Excel spreadsheet.

  1. In the Data pane, click the New Data Source down arrow and select Excel.

  2. In the New/Change Excel Data Source Dialog Box that opens, do the following:

    1. Browse to the file and indicate if the first row is a header row.

      If you add a local Excel data source, you are prompted to convert the Excel file path to a path relative to the current test folder.

      Relative paths are useful if you want other users or products to be able to run this test on other computers.

      If you move the Excel file or test folder, make sure the path that the test uses for the Excel file remains correct.

      Note: Relative paths are not supported for Excel data sources created in ALM.

    2. Specify a name for the data source, or leave the default as the name of your Excel file.

    3. Select whether to link to the Excel in its original location or to create a local copy.

      A local copy is portable with your test, but will not be linked to your original file. Any updates made to the original Excel file are not reflected in the copy.

    4. (Optional) Select Allow other tools to override the data.

      This option enables you to run the test from ALM with different values, or to edit data in a different test or action that's called from your test.

  3. In the Data pane, select the data source under the Excel node. In the right pane, you can view and edit the values.

    Caution: Use the Excel General format for values in the Excel sheet.

Back to top

Add an XML data source

Add an XML data source to data drive your test from an XML file.

  1. In the Data pane, click the New Data Source down arrow and select XML.

  2. In the New XML Data Source Dialog Box, enter a Data Source name and select the file to use as the base for the data source:

    Schema file Browse to an .xsd file.
    XML file Browse to an .xml file.
    Use existing Browse to an existing XML-based data source from another test.
  3. In the Data pane, select the node for your data source. For example:

  4. Edit the XML data in the Data pane grid. Click the Add rows button to add row values.

  5. To load XML values, click the Load data from an XML file button .

Back to top

Add a database data source

Add a database data source to data drive your test from an OleDB or ODBC database.

  1. In the Data pane, click the New Data Source down arrow and select Database.
  2. In the Set Database Connection pane of the Add New Database Data Source Wizard, define the Connection type as OleDB or OCDB, as relevant.

  3. Set the connection string as follows:

    OleDB

    Do one of the following:

    • Paste an OLE DB connection string into the text area.

    • Select a previously defined connection string from the drop down.

    • Click the Build Connection String button to use Microsoft's Data Link Properties dialog box.

    ODBC connections

    Click the Build Connection String button to select a DSN type. Then, select a DSN type and provide the necessary credentials.

    To create or edit a DSN entry, click the Manage ODBC Data Sources button. After you close the administrator dialog box, click the Reload DNS list button to refresh the list.

    For details, click the Help button in the ODBC Data Source Administrator dialog box.

  4. Test the connection to verify your details and then Next or OK to continue.
  5. In the Set SQL Statement page, provide a unique name for the data source, not used by another data source.

    Note: If you do not provide a name, the data source is automatically assigned the table name after you build the query.

    Then, provide an SQL statement in one of the following ways:

    Paste Paste an existing statement into the text area
    Select Select a previously defined statement from the drop-down list.
    Query Designer

    Use the Query Designer as follows:

    1. Click the Build Query Statement button to open the Query Designer Dialog Box.

    2. Select a table or view. The Query Designer lists all of the rows in the pane below and displays the corresponding SQL statement in the preview pane.

    3. Enable Auto execute to view the results of your query as you make changes in the upper pane.

    4. By default, the Query Designer selects all columns in the table. To remove a column from the query, clear the Output check box for that column.

    5. To set a sorting order, select Ascend or Descend from the Sort column drop-down. If you have multiple rows that you are sorting, provide the Sort Order beginning with 1. The Query Designer adds an ORDER BY clause to the preview pane.

    6. To add a GROUP BY or DISTINCT clause to your statements, select the appropriate check box.

    7. Click OK to accept the query and return to the wizard.

  6. In the wizard's Set SQL Statement page, click the Check SQL Statement button.

    After the Query Preview is finished, click Close to return to the wizard.

  7. Click Finish. UFT One shows the query details in the Properties pane's Database Data Source Properties Tab (Properties Pane - API Testing).

    Note: By default the Data pane shows the first ten rows of the query data. To change the number of displayed rows, use the General Pane.

Back to top

Add a local data table

Add a local data table as a data source to data drive your test from a local database.

  1. In the Data pane, click the New Data Source down arrow and select Local Table.

  2. In the New/Edit Local Table Data Source Dialog Box, click the Add button to create a column in the data table.

  3. In the columns list, specify a column name and description. Select a data type from the drop down list.

  4. Repeat step 3 for each column you want to create.

  5. When you are finished, click OK.

  6. In the Data pane, select the table's node in the left pane and move within the table using the keyboard arrows. Type within the cells to manually set values.

Back to top