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.
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. Reflect 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.
To create a segment, simply select the contiguous test steps from any test definition and click “Create a Segment” from the bulk action bar that appears at the bottom of the page.
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.
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.
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 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.
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.
To record a new test and use segments as the initial test steps, there must be at least one segment in your Reflect account. Click “Create Test” to open the test recording modal. Enter a name, a starting URL and a device profile for your new test.
Next, select as many segments as you’d like from the Segments dropdown. Only segments that match the test’s device profile can be selected. Furthermore, keep in mind that the segments will execute in succession within the same browser tab. So, each segment’s first action should operate on the same URL as the prior segment’s last action. Otherwise, your test may fail due to an element not being found on mismatched URLs. This requirement includes entering the starting URL for the test. The first segment you select must operate on the same URL as the test’s starting URL.
Finally, click “Begin Recording” to initiate the test. Reflect will initialize a new browser and execute the test steps in sequence from all of the segments. Then, it will enable the normal recording experience where you can record new test steps.