How to populate the Datastore for use as a Scenario Outline data source

How to populate the Datastore for use as a Scenario Outline data source

Cycle 2.5 introduces enhanced Scenario Outline functionality. This enhanced Scenario Outline functionality gives the ability to manage test data across multiple permutations.

An Overview of enhanced Scenario Outlines can be found here.

The Cycle Datastore is one of several available sources for managing Scenario Outline test parameters. The data is created and maintained within the Cycle Datastore.

The Scenario Outline utilizes the Datastore through the use of the Datastore Examples key word. More information regarding the Datastore can be found here.

The purpose of this article is to describe several methods you can use to populate the Datastore with data for your Scenario Outline. The methods described in this article are not the only options for populating the Datastore. Many factors can influence the decision on how to maintain your Datastore. Datastore DB type, available tools, organizational requirements, long term maintenance, and ease of use are some examples of factors that need to be considered when determining how your Datastore will be managed.

Access to the Datastore Database

You will need access to the Datastore database in order to create and maintain test parameter data.

To set up your Datastore conection within Cycle, go to Project Settings > Datastore Settings.

For this article, I will be using a database management tool called DBeaver. DBeaver is a free, multi-platform database manager that includes drivers for the supported Cycle Datastore database types (DB2, Oracle, SQL Server, H2). DBeaver includes the ability to execute SQL statements against the database and also allows for inline editing of database records. 

You can find more information and a link to download DBeaver here.

Maintenance with Inline Editing

Inline editing provides the quickest and most interactive method for maintaining Datastore data. You can easily add, delete, and copy rows in the Datastore table. Rows can be modified by typing directly in the data field or by opening an editor window.

Displaying Table Data

You must display the table data in order to take advantage of inline editing. There are several options for opening a table and displaying its data.

You can display table data by right clicking the table name in the Database Navigator panel and then selecting Edit Table in the context menu.

edit_table_context.PNG

Alternatively, you can double click the table name in the Database Navigator panel and then click the Data tab to view the table contents for reviewing or editing.

edit_data_tab.PNG

The Data grid displays all of the current data within the table (similar to what a 'SELECT *' SQL query would return) and includes several different controls for manipulating the data that we will explore in the next sections. 

We will be maintaining data in the Datastore TEST_DATA_VALUE table as an example for this article.

Adding a Row

Create a New Row

Create a new row by click the green plus sign available in the controls at the bottom of the Data grid.

add_record_button.PNG

Clicking the 'Add new row' button will insert a new row into the data grid. If there is currently no data in the table, the new row will be the first row in the data grid. If data already exists, a new row will be inserted after the currently selected row.

The new row is inserted into the data grid with NULL values in all fields.

mceclip3.png

Populate Row Data

Double click the field you want to edit to open an editable text field.

first_text.PNG

Enter the value into the text box and press Tab to move to the next column. This action records the entered value in the field and then makes the next field in the row editable.

next_text.PNG

Adding Valid Foreign Keys

Some table fields within the Datastore are foreign keys from other tables. For example, when adding a row in the TEST_DATA_VALUE table, you must ensure the TEST_DATA_RECORD_ID is a valid value in the TEST_DATA_RECORD table.

Database integrity is enforced within the Datastore. An invalid foreign key will prevent the row from being committed when you attempt to save it. DBeaver includes a tool for selecting a foreign key value from the related table.

With the data field selected, click the 'Panels' button on the right side of the data grid.

panels_button.PNG

This opens a new panel named 'Value' to the right of the data grid. This panel displays the valid possibilities for the currently selected field based on the foreign key values defined in the related table.

value_panel.PNG

Click on the value you want to add to your new row, and the value will populate the data field.

value_populated.PNG

Save the New Record

Continue populating the data fields until all of the required data is entered and you are ready to save your row to the database. DBeaver includes a change indicator (*) next to the table name on the table tab as well as a highlighted green row to indicate the new row is not committed to the database.

unsaved_row.PNG

Save your changes to the database by clicking the 'Save' button on the bottom of the data grid.

save_button.PNG

The change indicator and green highlighting are removed once the new row is saved to the database. 

new_saved.PNG

You can cancel your edit and discard changes by clicking the 'Cancel' button on the bottom of the data grid. This will revert the table to its previous state.

cancel_button.PNG

Deleting a Row

Select the row you want to delete from the database table by clicking a field on the desired row.

select_for_delete.PNG

Click the 'Delete' button below the data grid.

delete_button.PNG

The row selected for deletion is highlighted and the table tab is marked with the change indicator to identify there are uncommitted changes. DBeaver supports Ctrl+Click and Shift+Click to select multiple cells at a time.

record_for_delete.PNG

Click the 'Save' button to complete the row deletion once all required rows are selected.

save_button.PNG

The selected rows are removed from the database.

record_deleted.PNG

Click the 'Cancel' button to cancel the delete action before saving and retain the row in the database.

cancel_button.PNG

Copying Rows

Creating new rows by copying existing rows and modifying key values can save time and effort when populating the Datastore. DBeaver provides functionality for copying existing rows.

Begin by selecting the row(s) that you want to copy. DBeaver supports Ctrl+Click and Shift+Click to select multiple rows.

selected_for_copy.PNG

Click the 'Duplicate current row' button on the control row at the bottom of the data grid.

duplicate_row.PNG

This inserts new rows (highlighted green) below the selected records in the data grid. Note that the new rows include duplicated data from the originally selected rows.

duplicated_rows.PNG

Modify the rows with appropriate data while keeping in mind any primary and foreign key constraints.

duplicate_rows_modified.PNG

Click the 'Save' button to save the rows to the database.

save_button.PNG

The copied rows are saved to the database with the updated values.

duplicates_saved.PNG

Click the 'Cancel' button to remove the duplicated rows before saving and revert to the previous state.

cancel_button.PNG

Modifying a Field

Individual fields can be modified using inline editing. You can modify a field's value directly in the data grid or by using an editor window.

Modifying Data Using the Data Grid

Double click the field you want to modify within the data grid. The field will become an editable text box. 

field_pre_edit.PNG

Enter the new field value and press Enter, or you can press Tab to move to the next editable field on the row. Note that clicking another cell or pressing tab shows that the edited field is highlighted. This indicates the field value has changed, but it is not committed to the database.

edit_pre_save.PNG

Press the 'Save' button to save the edited row to the database.

save_button.PNG

The updated row is saved to the database.

edit_saved.PNG

Modifying Modifying Data using the Editor Window

Right click the field you want to modify and select 'Edit' -> 'Edit cell' in the context menu.

edit_context.PNG

This opens a new window that allows you to edit the contents of the data grid field.

edit_window_pre_change.PNG

Make the necessary modifications in the window and click the Save button.

edit_window_post_change.PNG

The editor window disappears, and you are taken back to the data grid. Note that the change indicator on the table tab as well as the highlighted cell indicate the new field value has not been saved to the database.

edit_window_pre_commit.PNG

Click the 'Save' button to save the modified row to the database.

save_button.PNG

The new field value is saved to the database.

edit_window_post_commit.PNG

Click the 'Cancel' button to discard changes and revert to the previous state.

cancel_button.PNG

Maintenance with SQL Statements

In addition to inline editing, you can maintain the Datastore with SQL statements using DBeaver. This allows you to write SQL statements to insert, update, and delete rows in the Datastore tables. You may find this approach useful when cloning already created data from one Datastore to another Datastore using insert statements or if you need to make mass updates to records within the Datastore.

Open the SQL Editor by selecting 'SQL Editor' -> 'SQL Editor' on the menu bar.

sql_editor_open.PNG

You can open previously saved scripts in the SQL Editor or you can open a new editor window. For this example, I am opening a new SQL Editor window. You can enter SQL statements in the top portion of the editor. Results are displayed in the bottom portion of the editor.

mceclip20.png

Enter the SQL you want to execute against the Datastore into the editor.

sql_editor_insert.PNG

Click the 'Execute SQL Statement' button when ready to execute the SQL statement.

sql_editor_execute.PNG

Results are displayed in the bottom portion of the SQL Editor.

sql_editor_results.PNG

Return to the data grid and refresh the grid to see the changes after running the SQL statement in the SQL Editor.

sql_editor_post_refresh.PNG

    • Related Articles

    • How to use Datastore Examples as a Scenario Outline data source

      With the enhancements to Scenario Outlines, it is now possible to use multiple sources for test parameter data. Previously, parameters were set in the Feature in an Examples section specified and maintained by the user. The addition of Example Row, ...
    • How to populate the Data Store for use as a Scenario Outline data source using the Bundle

      Cycle 2.5 introduces enhanced Scenario Outline functionality. This enhanced functionality provides several different options for managing test parameters across multiple permutations of the Scenario Outline. An Overview of enhanced Scenario Outlines ...
    • How to use a CSV file as a Scenario Outline data source

      With the enhancements to Scenario Outlines, it is now possible to use multiple sources for test parameter data. Previously, parameters were set in the Feature in an Examples section specified and maintained by the user. The addition of Example Row, ...
    • How to use a SQL query as a Scenario Outline data source

      With the enhancements to Scenario Outlines, it is now possible to use multiple sources for test parameter data. Previously, parameters were set in the Feature in an Examples section specified and maintained by the user. The addition of Example Row, ...
    • How to use Example Row as a Scenario Outline data source

      With the enhancements to Scenario Outlines, it is now possible to use multiple sources for test parameter data. Previously, parameters were set in the Feature in an Examples section specified and maintained by the user. The addition of Example Row, ...