The component interaction contract
For every control, apply these five stages. The first three are always present; the last two appear only when the interaction needs them.
1. Identify
Use the most stable user-facing identity available, in this order of preference:
- Visible field label.
- Accessible control name.
- Exact button, link, tab, or option text.
- Business key of the surrounding row or card.
- Section, modal, or panel heading.
- Relative landmark, such as next to the "Company" field.
2. Scope
Add scope whenever the same label appears more than once:
When I click the "Save" button in the "New Contact" modal
When I check "Primary" in the row for contact [$.testdata.contact.email]3. Act
Use the verb that matches the component:
| Component | Correct verbs |
|---|---|
| Text field, textarea, rich text | fill, replace, clear |
| Search field or search bar | search |
| Picklist or dropdown | set, select |
| Searchable combobox or autocomplete | search and select |
| Checkbox | check, uncheck |
| Radio group | select the option |
| Toggle or switch | set to on, set to off |
| Button or link | click |
| Mobile control | tap, swipe, long-press |
| Slider | set to a value |
| File input | upload |
| Table row | find the row, then act within it |
4. Synchronise
After an action that changes the page, wait for an observable state:
And I wait until the loading spinner disappears
And I wait until the "Save" button becomes enabled
And I wait until the "Status" field shows "Completed"Use fixed waits only when the application provides no observable completion state.
5. Assert when required
Use Then when the control's final state is an acceptance criterion of the
testcase:
Then the "Industry" picklist should show "Healthcare"
Then the "Active" checkbox should be checked
Then the "Description" rich-text editor should contain "Priority customer"Do not repeat these assertions mechanically after every interaction:
- If the value is only needed to continue the workflow, perform the next action.
- If the application needs time to become ready, use an operational wait.
- The final business assertion is what determines the testcase result.