Constraining and list processing examples

To steer Module Attributes in an unsorted list, use the ActionModes Verify and Constraint. Alternatively, you can set an index, notation or result count on the XTestStep.

You can work with the following types of unsorted lists:

  • Flat lists: simple lists with one hierarchical level of list item elements.

  • Nested lists: lists with sub-lists and different hierarchical levels of list item elements.

This chapter contains examples for constraining and processing different kinds of lists.

Example 1: use explicit constraining

The following example shows how to identify a list item using the ActionMode Constraint. You will verify other list item elements using the ActionMode Verify.

The goal is to identify a specific coffee in a list of several coffees. In this case, you want to identify the list element with the Id of 2. Additionally, you want to verify the coffee's name and description.

List in the Technical View tab of the Module

To set ActionModes on your Module Attributes, select theTestCase.

In the Details tab, uniquely identify your list item by its Id: Set the ActionMode Constraint on the Module Attribute Id with the value 1.

To verify the values of the list item elements, use the ActionMode Verify for the Module Attributes Name and Description.

Set ActionMode Verify in the Details tab of the TestCase

When you run your TestCase, the system searches for the coffee with the Id 1.

Once the system has found the coffee, it verifies that its Name is Bicerin and the value of its Description.

Search result in ScratchBook

Example 2: use auto constraining

If you don't set explicit constraints on specific list item elements, the API Engine searches the list from top to bottom on the first level of the element hierarchy.

If your list has more than one level, you can extend your search query to the other levels of the element hierarchy.

The following example shows how to extend the search to other levels of the element hierarchy.

The goal is to identify a specific order within an unsorted list of several orders. In this case, you want to verify a specific order by its OrderId, but several orders in your list have the same OrderId.

List in the Technical View tab of the Module

If you try to identify your order by simply using the ActionMode Verify on the Module Attribute OrderId, you will receive an error message.

Set ActionMode Verify on OrderId in the Details tab of the TestCase

The error message indicates that there is more than one order with the OrderId 1.

Search result in ScratchBook

To narrow down your search, you need to include a list item element on the second level of the list, such as FuelType.

Make sure to include the list item element on the level above the list item element FuelType in your search. Otherwise the system will continue to search only the first level of the list.

To do so, change the ActionMode on the list item element Vehicle from Select to Verify.

Set ActionMode Verify on Vehicle and FuelType

This changes the way you query the list. The system now searches the first and the second level of your list item elements.

You can identify a unique order that includes the OrderId1 and a Vehicle with the FuelType Diesel.

Search result in ScratchBook