Segments and Composition
Segments are named sequences of test steps that can be executed within any test. Changes to a Segment are reflected in any test that references it.
Overview
Often the individual test cases throughout a regression suite will share (or duplicate) shorter sequences of actions. For example, a collection of tests related to a webapp’s Settings page will most likely share an initial sequence of logging in to the webapp, and then at some point, navigating to the Settings page. If each test case duplicates those sequences, then a problem arises when the sequences change and each test needs to be updated individually. API Hub for Test uses segments to solve this problem.
A segment is a named sequence of test steps, which can be referenced and executed by any test. If the segment’s steps are updated or changed, then those changes propagate to the dependent tests on their next test run. A segment can be referenced anywhere within a test, which allows you to compose arbitrary test cases from reusable building blocks.
Note
Only tests can reference segments. Segments cannot reference other segments so there is no ability to create nested segments.
Create a Segment
To create a segment, select the neighboring test steps from any test definition and click “Create a Segment” from the bulk action bar that appears at the bottom of the page. You must select two or more test steps to create a segment, but you can edit the segment after it is created (see below).
Enter a name for the new segment into the modal and click Add Segment. Finally, save and run the original test to save the reference to the new segment.
View a Segment
You can view a segment from any test definition that references it, or from the segment’s definition page itself. To load a segment’s definition page, click the “View” link next to the segment from the main Segments list page.
Edit a Segment
Editing a segment is just like editing regular test steps.
Note
When you click the Save button, you are updating both the segment’s definition, as well as any test that references the segment to use the segment’s updated definition. Thus, any future test execution that references the segment will use the updated test steps.
Go to a test that references the segment that you want to edit.
Click on the test step inside of the segment on the left sidebar that you want to edit.
The test step detail pane is displayed. You can make changes to as many test steps inside of the segment as you want. When you are finished creating changes, there will be a message at the bottom of the left sidebar indicating how many test steps were modified.
Click the Save button in the left sidebar.
Unassign a Segment
Unassigning a segment removes the reference to a segment from a test but leaves all of the segment’s literal test steps in the original test. After removing the segment reference, you can (bulk) delete the segment’s test steps if desired. The unassign operation is distinct from deleting a segment, and is useful when creating newer segments from a subset of an existing segment’s steps. Unassigning a segment does not change the segment’s definition or steps.
To unassign a segment, view the definition of a test that references the segment. Click on the right-facing “›” arrow to the right of the segment name in the left sidebar to open the segment detail panel.
Finally, click “Unassign Segment” in the detail panel, and then save the changes in the parent test.
Delete a Segment
To delete a segment, go to the segment’s definition page and click the “Delete” button at the top of the page. You cannot delete a segment that is referenced by any tests. You must unassign the segment reference from within each test before deleting the segment.