This guide outlines best practices for writing effective prompts when using Stark Vision for mobile test automation.
Basic pattern: Click on [element description]
Examples:
Click on search field
Click on the FreshMenu restaurant
Click on Add item
Tips:
- Be specific about the element you want to click
- Use exact text when available
- For multiple similar elements, add context (e.g., "Click on Add button below Pizza")
- Include location context when needed (e.g., "Click on search icon in navbar")
Basic pattern: Enter [value] in/into [field description]
Examples:
Enter "Fresh Menu" into Search text field
Enter "HSR Layout" in the Drop location field
Tips:
- Always wrap the input text in quotes
- Be specific about which input field to use
- Include context if multiple similar fields exist
Stark Vision supports various gesture types for interacting with mobile applications.
Basic patterns:
// Simple scroll
await ai('Scroll up until you see "Add" text');
await ai('Scroll down until you see "Payment Methods"');
// Scroll with distance
await ai('Scroll up by 50%');
await ai('Scroll down by 75%');
// Scroll in container
await ai('Scroll up in "Menu Items" list until you see "Desserts"');
await ai('Scroll down in product carousel until you see "Last Item"');
Configuration:
{
maxScrolls: 5, // Maximum scroll attempts (default: 3)
scrollSize: "SMALL" // SMALL: 20%, MEDIUM: 50%, LARGE: 80% of screen
}
Tips:
- Use smaller scrolls for dense content
- Increase maxScrolls for long lists
- Reference container elements for precise scrolling
- Include visual markers in scroll targets
Basic patterns:
// Directional swipe
await ai('Swipe left on "Product Card"');
await ai('Swipe right on order item');
// Swipe with context
await ai('Swipe left on first order in list');
await ai('Swipe right on notification below "Today"');
// Swipe to delete
await ai('Swipe left to delete "Cart Item"');
await ai('Swipe to remove address');
Configuration Options:
{
// For scrolling/swiping
maxScrolls: number, // Maximum attempts
scrollSize: "SMALL" | "MEDIUM" | "LARGE", // Gesture distance
// Common options
elementVisibleCheck: boolean, // Verify element before gesture
saveToCache: boolean, // Cache element location
}
Best Practices:
-
Scroll Performance
- Use smaller scroll sizes for precise navigation
- Increase maxScrolls for longer content
- Reference container elements when possible
- Disable elementVisibleCheck after scrolls
-
Gesture Precision
- Include clear source and target elements
- Reference nearby elements for context
- Use visual attributes to disambiguate
- Specify containers for scoped gestures
-
Error Handling
// Retry with different scroll size try { await ai('Scroll up until you see "Add"', { scrollSize: "SMALL" }); } catch { await ai('Scroll up until you see "Add"', { scrollSize: "LARGE" }); } // Verify before gesture const visible = await aiGetInfo('Can you see "Drag Handle"?'); if (visible.conditionSatisfied) { await ai('Drag "Item" to "New Position"'); }
Stark Vision supports various types of assertions to verify UI elements and states. Use aiGetInfo()
for more descriptive assertions.
// Basic presence check
await aiGetInfo('Can you see "Add to Cart" button?');
// With context
await aiGetInfo('Can you see checkout button below total price?');
// Multiple elements
await aiGetInfo('Can you see both minus and plus buttons next to quantity?');
// Enabled/Disabled states
await aiGetInfo('Is the checkout button enabled? Return as boolean'); -> This will return boolean value.
await aiGetInfo('Is the payment button disabled?');
// Selected/Checked states
await aiGetInfo('Is the terms checkbox checked?');
await aiGetInfo('Is dark mode toggle selected?');
// Element properties
await aiGetInfo('Is the continue button in blue color?');
await aiGetInfo('Is the error message in red text?');
// Exact text matching
await aiGetInfo('Does the total price show "$49.99"?');
await aiGetInfo('Is the error message exactly "Please enter valid email"?');
// Partial text matching
await aiGetInfo('Does the product description contain "organic"?');
await aiGetInfo('Does the header include user email address?');
// Relative positioning
await aiGetInfo('Is the search bar above the product list?');
await aiGetInfo('Is the total price displayed at bottom of cart?');
// Alignment checks
await aiGetInfo('Is the logo centered in header?');
await aiGetInfo('Are all product cards aligned in grid?');
// Multiple conditions
await aiGetInfo('Is the order button enabled and showing "Place Order"?');
await aiGetInfo('Are all required fields marked with red asterisk?');
// Dynamic content
await aiGetInfo('Are there exactly 5 items in the cart?');
await aiGetInfo('Is the first restaurant showing "40 mins" delivery time?');
// Element visibility
await aiGetInfo('Is the loading spinner visible?');
await aiGetInfo('Is the error message hidden?');
// Partial visibility
await aiGetInfo('Is the entire product image visible without scrolling?');
await aiGetInfo('Is the bottom navigation bar fully visible?');
{
conditionSatisfied: boolean, // True if assertion passes
explanation: string // Detailed explanation of verification
}
// Element visibility
await ai('Verify the loading spinner visible?');
await ai('Verify the error message hidden?');
-
Be Specific
- Use exact text in quotes when verifying content
- Include relevant context and location
- Specify states clearly (enabled/disabled, checked/unchecked)
-
Element Context
- Reference nearby stable elements
- Use multiple reference points for complex layouts
- Include visual attributes when helpful
-
Verification Strategy
- Start with simple presence checks
- Build up to complex state verification
- Combine multiple conditions when needed
- Use appropriate wait times before assertions
-
Common Patterns
// Wait and verify await driver.pause(2000); const result = await aiGetInfo('Can you see success message?'); // Check and act const {conditionSatisfied} = await aiGetInfo('Is login button enabled?'); if (conditionSatisfied) { await ai('Click on login button'); } // Verify after action await ai('Click on sort button'); const sorted = await aiGetInfo('Are items sorted by price?');
Basic pattern: Clear the [field description]
Examples:
Clear the search field
Clear the text admin in the search field
Basic pattern: Click on the device back button
Example:
Click on the device back button
Use these patterns to identify elements based on their location relative to other elements:
- Near:
Click on search icon near shopping cart
- Next to:
Click on add button next to Margherita Pizza
- Below:
Click on price text below product image
- Above:
Click on menu icon above product list
- Between:
Click on quantity field between minus and plus buttons
Tips:
- Always reference unique, stable elements
- Use multiple proximity indicators for complex layouts
- Combine with visual attributes when helpful
Identify elements using their visual characteristics:
- Color:
Click on blue Continue button
- Size:
Click on large Play button
- Shape:
Click on circular Add button
- Icons:
- Common icons:
Click on shopping cart icon
- Descriptive icons:
Click on heart icon next to favorite items
- System icons:
Click on back arrow icon in top left
- Common icons:
When multiple similar elements exist, use these strategies:
-
Ordinal Position:
Click on first Add button Click on second restaurant in the list Click on last Save button
-
Contextual Reference:
Click on Add button below Pizza description Click on price text next to product name Click on quantity field between - and + buttons
-
Unique Attributes:
Click on blue Order Now button Click on large Play icon in center Click on circular Profile button in header
-
Combined Strategy:
Click on first blue Add button below product image Click on heart icon next to second restaurant Click on Edit button near bottom of product details
-
Element Description
- Use exact text when available
- Include contextual information
- Specify location (top, bottom, below, next to)
- Reference nearby unique elements
-
Command Structure
- Keep instructions clear and concise
- Use consistent terminology
- Include necessary context
- Avoid ambiguous descriptions
-
Configuration Options
Detail Explanation found here
{ elementVisibleCheck: boolean, // Check element visibility before action saveToCache: boolean, // Cache element location maxScrolls: number, // Maximum scroll attempts scrollSize: "SMALL" | "MEDIUM" | "LARGE" // Scroll distance }
-
Performance Optimization
- Disable elementVisibleCheck after scroll operations
- Use saveToCache: false after scroll actions
- Adjust maxScrolls based on content length
- Choose appropriate scrollSize for content density
// Navigate to specific restaurant
await ai("Click on search field");
await ai('Enter "Fresh Menu" into Search text field');
await ai("Click the FreshMenu restaurant", { saveToCache: false });
// Scroll and add item
await ai('Scroll up until you see the "Add" text', {
maxScrolls: 9,
scrollSize: "MEDIUM"
});
await ai("Click on Add", {
elementVisibleCheck: false,
saveToCache: false
});
// Fill address form
await ai("Click on 'Where are you going?'");
await ai("Enter 'HSR Layout' in the Drop location field");
await ai("Click on the 'Heart icon of HSR Layout Police Station below Select on Map'");
// Verify entry
const response = await aiGetInfo("Can you see 'HSR Layout Police Station below Add to favourites'?");
// Scroll through list
await ai("Scroll up until you see 'Made in India'", { maxScrolls: 5 });
await ai("Scroll down until you see 'Address List'", {
maxScrolls: 5,
scrollSize: "SMALL"
});