Group context

Learn how to maximize reuse by assigning entire groups to different elements of the page and across pages

The Group Context feature enables you to run groups of steps on other, slightly different, elements (contexts), without the need to manually reconfigure the steps. When setting a context for a group step, the locators in its steps are automatically and dynamically changed to fit the new context.
For example, if you created a group of steps for booking a reservation to Madan and you want to run that group for booking a reservation to Shenji, instead of manually changing the step details, Group Context will automatically make the appropriate adjustments for you.

📘

For background information about Groups _and _Shared Groups, see Groups.

Examples of when you may want to use this feature include:

  • Repeating elements – when you have similar elements repeating in the page and want to execute the same steps on each of them.
  • Table rows – when you want to execute the same steps on each row in a table.
  • Tabs or frames – when you want to use a group of steps, which were recorded on one tab, in another tab. In this case you should group all the steps that involve using the second tab in a group and then set the group context by following the instructions below.

📘

In case of multi tab application, when a step is recorded, the specific tab (e.g., tab #3) is stored. When the step is played, as part of test run, the Testim application looks for the tab based on two parameters: tab number and tab URL. The decision to run on a specific tab is based on these two parameters – so, the actual playing can result in a different tab number (e.g. tab #2) if both tabs URLs are identical.

Setting a context for a group

When assigning custom context, it is recommended to assign the largest element in the DOM (e.g., the Body element). For detailed instructions see - Selecting the largest element in the DOM. The following procedure assumes that you have already created a shared group step that you would like to reuse in a new context. The procedure for creating a group is described here.
To set a context for a group:

  1. Hover over the > (arrow symbol) where you want to add your step.

The action options are displayed.

  1. Click on the folder (Shared steps).
    The Shared steps menu opens.
300
  1. Select the desired group from the list of existing group steps.
    The group is added to your test.

  1. Hover over the > (arrow symbol) to the left of that group step.
    The action options are displayed.
  2. Click on the Toggle Breakpoint button.
400
  1. Click on the Play Scenario button, to run the test until the breakpoint.

  1. Hover over the group step you just added and click on the Show Properties () icon.

The Properties panel opens on the right-hand side.

  1. Click the down arrow next to Context, and select Custom.
275

The AUT browser opens.

  1. In the AUT browser, identify the relevant element (context) you would like your group to run on, and click on it to select it. It is important to select the largest element in the DOM. For detailed instructions see - Selecting the largest element in the DOM

📘

By default, when selecting context for a group, the application will be in "Context selection mode". In this mode the repeating elements on the page will be highlighted to help with the selection. To exit this mode and return to the normal selection mode, click Q on your keyboard.

  1. The selected element is shown in the Target element box in the Context section of the Properties panel.

The new context is automatically applied to the group step, with no additional need for you to reassign the step.

  1. Click on the Toggle Breakpoint button to remove the breakpoint.

📘

Testim automatically identifies which steps in the group should run on the provided context, and which should run outside of it.

Selecting the largest element in the DOM

When performing the context selection, select the largest element in the DOM (e.g., Body), so that all the steps will be included in the context.

To select the largest element in the DOM:

  1. After selecting the Custom option in the Context section of the Properties panel, press Q (on your keyboard) to enter into the Context selection mode.
  2. On the designated browser tab (for which the group was created) select any element on the page.
  3. On your keyboard, press the Up arrow multiple times until you reach the largest element in the DOM (e.g., Body).
  4. When you have reached the body element, press Enter to select it.

Try it yourself

Click here to view a test where a group step has been applied to more than one context. Use the shared group step “book” to create a new booking for a different destination in the app by changing the Context of the group step.