Class InitialStates
InitialStates implements a sophisticated probabilistic approach to establishing the starting position in the GUI state space. Rather than assuming a fixed starting point, it maintains a weighted set of possible initial state configurations and uses intelligent search strategies to determine which states are actually active when automation begins.
Key features:
- Probabilistic State Sets: Associates probability weights with potential state combinations
- Intelligent Search: Searches only for likely states, avoiding costly full scans
- Mock Support: Simulates initial state selection for testing without GUI interaction
- Fallback Strategy: Searches all states if no predefined sets are found
- Recovery Capability: Can re-establish position when automation gets lost
State selection process:
- Define potential initial state sets with probability weights
- In mock mode: Randomly select based on probability distribution
- In normal mode: Search for states in order of likelihood
- If no states found: Fall back to searching all known states
- Update StateMemory with discovered active states
Probability management:
- Each state set has an integer probability weight (not percentage)
- Weights are cumulative for random selection algorithm
- Higher weights indicate more likely initial configurations
- Sum can exceed 100 as these are relative weights, not percentages
Use cases:
- Starting automation from unknown GUI position
- Handling multiple possible application entry points
- Recovering from navigation failures or unexpected states
- Testing automation logic with simulated state configurations
- Supporting applications with variable startup sequences
Example usage:
// Define possible initial states with probabilities initialStates.addStateSet(70, "LoginPage"); // 70% chance initialStates.addStateSet(20, "Dashboard"); // 20% chance initialStates.addStateSet(10, "MainMenu"); // 10% chance // Find which states are actually active initialStates.findInitialStates();
In the model-based approach, InitialStates embodies the framework's adaptability to uncertain starting conditions. Unlike rigid scripts that assume fixed entry points, this component enables automation that can begin from various GUI positions and intelligently determine its location before proceeding with tasks.
This probabilistic approach is essential for:
- Web applications with session-based navigation
- Desktop applications with persistent state
- Mobile apps with deep linking or notifications
- Any GUI where the starting position varies
- Since:
- 1.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionInitialStates
(BrobotProperties brobotProperties, StateDetector stateFinder, StateMemory stateMemory, StateService allStatesInProjectService) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addStateSet
(int probability, State... states) Adds a potential initial state set with its probability weight.void
addStateSet
(int probability, String... stateNames) Adds a potential initial state set using state names.void
Discovers and activates the initial states for automation.Gets the names of all states that have been registered as initial states.boolean
Checks if any initial states have been registered.
-
Constructor Details
-
Method Details
-
addStateSet
Adds a potential initial state set with its probability weight.Registers a combination of states that might be active when automation begins, along with a weight indicating how likely this combination is. Higher weights make the state set more likely to be selected in mock mode or searched first in normal mode.
- Parameters:
probability
- Weight for this state set (must be positive)states
- Variable number of State objects forming the set
-
addStateSet
Adds a potential initial state set using state names.Convenience method that accepts state names instead of State objects. Names are resolved to states through StateService. Invalid names are silently ignored, allowing flexible configuration.
- Parameters:
probability
- Weight for this state set (must be positive)stateNames
- Variable number of state names forming the set- See Also:
-
findInitialStates
public void findInitialStates()Discovers and activates the initial states for automation.Main entry point that determines which states are currently active. Behavior depends on BrobotProperties configuration:
- Mock mode: Randomly selects from defined state sets
- Normal mode: Searches screen for actual states
Side effects:
- Updates StateMemory with discovered active states
- Resets state probabilities to base values
- Prints results to Report for debugging
- See Also:
-
getRegisteredInitialStates
Gets the names of all states that have been registered as initial states. This includes states added via @State(initial = true) annotations.- Returns:
- List of state names registered as initial states
-
hasRegisteredInitialStates
public boolean hasRegisteredInitialStates()Checks if any initial states have been registered.- Returns:
- true if initial states are registered, false otherwise
-