Creating a database query

When you have the data that is useful for creating the test assets is stored in a database, you can import the data from the database and create a database Query in HCL DevOps Test Hub (Test Hub).

Before you begin

You must have completed the following tasks:

About this task

When you want to create any database query, you must have an Edit branch. You can create the Edit branch during the creation of the database query. All your dataset resides in the Edit branch until you publish or discard the changes.

After you create the database query, you can either publish your changes to a remote Git repository or you can discard the changes made to the database query. The Edit branch automatically disappears from the Branch list as well as from the remote Git repository and sets the global branch to the previously selected branch in the following conditions:
  • When you publish changes to the remote Git repository.

  • When you discard the changes made in the dataset.

Procedure

  1. Log in to Test Hub.

    The team space that contains your project is displayed.

  2. Click Active projects > My projects > project_name to open the project that contains the test assets.

    The Overview page of the project is displayed.

  3. Click Author > Data.

    The Data page and the Data navigator panel are displayed.

  4. Select the branch in the project repository from the Branch list.

    The assets and resources in the selected branch are displayed in the Data navigator panel.

  5. Create a folder, if you want to use a new folder to contain the resource by performing the following steps:
    1. Select the project or a logical folder in the Data navigator panel, right-click, and then click Folder.

      Alternatively, select the project or a logical folder in the Data navigator panel, click the Open action menu icon , and then click Folder.

      The Create new folder dialog is displayed.

    2. Enter a name for the folder.

      For example, enter MyFolder as the name of the folder.

    3. Click Create.

      The folder is created under the project and displayed in the Data navigator panel.

  6. Perform any of the following actions:
    • Click the Open action menu icon in the Data navigator panel, and then click Database Query.
    • Click Add files in the right panel, and then click Database Query.

    The Edit branch dialog is displayed.

  7. Select your action to either select an existing Edit branch or create an Edit branch:
    • Perform the following steps to select an existing Edit branch:
      1. Select Use an existing edit branch.
      2. Select an Edit branch from the Select branch list if Edit branches already exist in the selected branch of the repository.
        Note: A warning message is displayed if the Edit branch, which you selected, is behind the source branch. To update the selected edit branch and maintain synchronization with the source branch, you can select the Update branch option when switching checkbox.
      3. Click Ok.
    • Perform the following steps to create the Edit branch:
      1. Select Create new edit branch.
      2. Enter a name for the Edit branch in the Branch Name field.
      3. Click Save.
  8. Perform the following steps in the Create database query dialog:
    1. Enter a name for the database query in the Name field.

      For example, the name of the database query can be my_db_query.

    2. Select a folder.
    3. Click Save.

    A message is displayed that confirms database query is created.

    The database query is displayed in the Data page. The database query is listed under the logical folder Datasets under the physical folder MyFolder that you created. The name of the database query is suffixed with the .dtd.yaml file extension.

    For example, the file name of the database query can be my_db_query.dtd.yaml.

  9. Perform the following steps in the Data page to select the table and query the data from the database:
    1. Select the database from the Connection list.
    2. Select the table in the selected database from the Table list.
      The data from the selected table is displayed.
    3. Select the required column of the table from which you want to import the data.
    4. Click View to switch between the Visual and Code view.
      Note: Note: The default view is Visual view. In the Code view you can type the query to get data from the database.
    5. Click the Preview icon to view the queried data from the database in tabular format in the bottom window.
    6. Click Save icon to save the queried data from the database.

Results

You have created a database query in your project.

What to do next

Publish the database query to the Git repository so that other members of the project can use the database query. See Publishing changes in an Edit branch.

You can create a dataset using the database query. See Creating a dataset by using a database query

You can create a Data definition using the database query. See Creating a Data definition by importing fields from a database query.