Best Practices for AI Command Types
This guide outlines the four primary AI command types in our testing framework. Each section provides clear examples of what works and what doesn't, helping you write more effective test automation.
AI Assertion
Purpose: Verify that the application is in the expected state at specific points in test execution.
AI Assertions check if specific conditions are true in the application's current state. They function as test validation points and always return a boolean result (true/false).
When to use
- After navigation actions to confirm the correct page loaded
- Before critical actions to ensure preconditions are met
- After data operations to verify changes were applied correctly
- To check for the presence or absence of UI elements
Writing effective assertions
| ✅ Do | ❌ Don't |
|---|---|
Use clear, binary questionsIs the account balance displayed as $1,250.00?Simple yes/no question that's easy to evaluate | Ask vague or compound questionsIs everything correct on the page?Too broad and checks multiple conditions |
Include specific reference pointsIn the confirmation dialog, is the deposit amount $100?Provides context since AI lacks step history | Assume context from previous stepsIs the amount correct?AI doesn't know what "amount" or "correct" refers to |
Test one condition per assertionIs the error message visible?Does the error message contain 'Invalid credentials'?Atomic assertions for better error isolation | Combine multiple checksIs the error message visible and does it say 'Invalid credentials'?Harder to debug which condition failed |
Always end with a question markAre there exactly 5 items in the shopping cart?Consistent format improves clarity | Use statements instead of questionsThere are 5 items in the cartNot clearly an assertion |
Include both positive and negative checksIs the success message visible?Is the error message absent from the screen?Comprehensive test coverage | Only test for presenceIs there a message?Doesn't verify the correct state |
Key guidelines
- Formulate binary questions that the AI can evaluate based solely on displayed information
- Be specific about expected values or states you're verifying
- Use consistent formats like "Is [expected condition] true?" for clearer assertions
- Provide context in each assertion since AI lacks memory of previous steps
AI Command
Purpose: Manipulate the application interface by interacting with specific elements or controls.
AI Commands instruct the AI to perform specific, discrete actions within the application interface, similar to how a user would interact with UI elements.
When to use
- For basic UI interactions like clicking, typing, selecting, and scrolling
- When you need precise control over individual steps in a workflow
- For test setup operations that prepare the application state
- To interact with specific UI components that require direct manipulation
Writing effective commands
| ✅ Do | ❌ Don't |
|---|---|
Use descriptive references, not positionsClick on the row where the status shows 'completed'Works even if row order changes | Rely on fixed positionsClick on the third rowBreaks when data changes |
Include distinguishing characteristicsClick the 'Submit' button with the green background in the payment formPrecise targeting reduces ambiguity | Be vague about the targetClick the buttonMultiple buttons may exist |
Add sequencing hints when neededAfter the loading indicator disappears, click the 'Continue' buttonHandles timing issues gracefully | Ignore timing dependenciesClick the 'Continue' buttonMay fail if element isn't ready |
Use semantic identifiersClick on the shopping cart iconReadable and maintainable | Reference technical selectorsClick on element with ID 'btn-cart-123'Brittle and hard to understand |
Specify exact input formatEnter 'test@example.com' in the email fieldType '(555) 123-4567' in the phone number fieldClear expectations for data format | Be ambiguous about inputEnter an emailAI may not know the expected format |
Identify items by content, not positionSelect the product with name 'Wireless Mouse'Resilient to list reordering | Use ordinal positions in listsSelect the second productFragile when list changes |
Key guidelines
- Prepare for dynamic scenarios by using content-based references rather than positions
- Be precise and specific about both the action and the target element
- Include waiting conditions when elements may not be immediately available
- Consider edge cases where elements might be conditionally present
AI Task
Purpose: Execute complete user journeys or business workflows with a single instruction.
AI Tasks represent high-level business operations that may involve multiple steps and decisions. They operate at a higher abstraction level than individual commands.
When to use
- For end-to-end workflow testing that mimics real user journeys
- When you want to abstract away implementation details
- For data setup that requires complex business operations
- To test complete business processes rather than individual UI interactions
Writing effective tasks
| ✅ Do | ❌ Don't |
|---|---|
Write intent-based actions with specific valuesDeposit $100 into Checking AccountClear business workflow with concrete details | Be vague about the operationMake a depositMissing critical details like amount and account |
Include contextual detailsTransfer $500 from Savings to Checking, ensuring sufficient funds are availableReduces ambiguity with preconditions and business rules | Omit important contextTransfer money between accountsUnclear which accounts and validation rules |
Structure complex workflows with GherkinGiven I'm on the booking pageWhen I search for flights from NYC to LondonThen select the cheapest option for next FridayClear preconditions, actions, and outcomes | Write run-on instructionsGo to booking page and search flights NYC to London next Friday and pick cheapestHard to parse and understand |
Break down into focused sub-tasks1. Add three items to cart2. Proceed to checkout3. Select standard shipping4. Complete paymentEasier to understand and execute | Combine too many stepsAdd items, checkout, ship, and payOverwhelming and prone to errors |
Include success criteriaRegister a new user and verify the welcome email is sentAI knows when the task is complete | Leave completion ambiguousRegister a userUnclear what constitutes success |
Specify data requirementsCreate a new customer with email format: firstname.lastname@example.comClear data generation rules | Assume data formatCreate a new customerAI may generate unsuitable data |
Key guidelines
- Author intent-based actions that clearly represent complete business workflows
- Include contextual details like preconditions, account types, or expected outcomes
- Use Gherkin syntax (Given/When/Then) for complex workflows to improve clarity
- Break down complex processes into smaller, focused tasks
- Specify business rules or validation criteria that should be considered
- Define success criteria so the AI knows when the task is complete
AI Extract Data
Purpose: Dynamically retrieve and store data from the application interface for verification or subsequent operations.
AI Extract Data commands capture specific information from the application for storage and later use in test execution.
When to use
- When you need to capture dynamic data generated during test execution
- For retrieving values that need to be verified later in the test
- To gather data needed for subsequent test steps
- For comparing values across different parts of the application
- To extract information for reporting or debugging purposes
Writing effective extract commands
| ✅ Do | ❌ Don't |
|---|---|
Be precise about the data locationCreate parameter ORDER_ID and assign the order number from the confirmation messageSpecific location and clear parameter name | Be vague about where to find dataGet the order numberUnclear where to look and no parameter name |
Specify the expected formatExtract the total amount as a number without currency symbol and store in TOTALClear format expectations | Assume format handlingExtract the total amountUnclear if "$1,234.56" or "1234.56" is expected |
Use descriptive parameter namesCreate parameter USER_EMAIL and assign the email from the profile sectionSelf-documenting parameter name | Use generic namesCreate parameter DATA1Unclear what the parameter contains |
Provide context for identificationExtract the price from the row where product name is 'Wireless Mouse'Handles multiple similar items | Assume uniquenessExtract the priceMay extract wrong value if multiple prices exist |
Clarify single vs multiple valuesExtract all product names from the search results into PRODUCT_LISTClear that multiple values are expected | Be ambiguous about quantityExtract product namesUnclear if one or many values |
Ensure data visibilityScroll to the footer, then extract the copyright year into YEAREnsures data is in viewport | Extract from hidden areasExtract the copyright yearMay fail if footer isn't visible |
Reference structural landmarksFrom the 'Order Summary' section under 'Shipping Address', extract the ZIP codeUses headers to guide extraction | Ignore document structureExtract the ZIP codeAmbiguous in forms with multiple addresses |
Specify fallback behaviorExtract the discount amount, or set to 0 if no discount is appliedHandles edge cases gracefully | Assume data always existsExtract the discount amountFails when discount isn't present |
Key guidelines
- Make commands precise and specific to the data you want to extract
- Ensure data is visible in the viewport and legible before extraction
- Use descriptive parameter names that clearly indicate what data they contain
- Specify the expected format (text, number, date, etc.) and any formatting rules
- Provide context for identifying the correct data when similar items appear multiple times
- Clarify single vs multiple values when extracting from lists or tables
- Reference structural landmarks (headers, sections) in structured documents
- Define fallback behavior if the expected data cannot be found
Summary
Effective AI commands share common characteristics:
- Clarity: Use precise language that leaves no room for ambiguity
- Context: Provide enough information since AI lacks memory of previous steps
- Specificity: Include concrete values, locations, and expected outcomes
- Resilience: Design commands that work even when the application state varies
By following these best practices, you'll create more reliable, maintainable, and effective test automation.