ActionConfig Overview
Introductionโ
ActionConfig is the new foundation for configuring automation actions in Brobot. It replaces the monolithic ActionOptions class with a more modular, type-safe hierarchy of configuration classes.
Why ActionConfig?โ
The previous ActionOptions class had several limitations:
- One size fits all: A single class tried to handle configuration for all action types
- Type safety: No compile-time checking for action-specific options
- Complexity: Many fields were only relevant to specific actions
- Maintenance: Adding new actions required modifying the central ActionOptions class
ActionConfig solves these problems by:
- Modularity: Each action has its own configuration class
- Type safety: The compiler ensures you're using the right options for each action
- Clarity: Each configuration class only contains relevant fields
- Extensibility: New actions can be added without modifying existing code
The ActionConfig Hierarchyโ
ActionConfig (abstract base)
โโโ BaseFindOptions (abstract)
โ โโโ PatternFindOptions
โ โโโ HistogramFindOptions
โ โโโ MotionFindOptions
โ โโโ ColorFindOptions
โ โโโ TextFindOptions
โ โโโ VanishOptions
โโโ ClickOptions
โโโ TypeOptions
โโโ MouseMoveOptions
โโโ MouseDownOptions
โโโ MouseUpOptions
โโโ MousePressOptions
โโโ ScrollOptions
โโโ DefineRegionOptions
โโโ HighlightOptions
โโโ DragOptions
โโโ KeyDownOptions
โโโ KeyUpOptions
โโโ TimeOptions
โโโ PlaybackOptions
See ActionConfig Reference for detailed documentation of each class.
Key Conceptsโ
1. Builder Patternโ
All ActionConfig classes use the builder pattern for construction:
import io.github.jspinak.brobot.action.basic.click.ClickOptions;
ClickOptions click = new ClickOptions.Builder()
.setNumberOfClicks(2)
.setPauseBeforeBegin(0.5)
.build();
2. Fluent Chainingโ
Actions can be chained together using the then() method:
import io.github.jspinak.brobot.action.basic.find.PatternFindOptions;
import io.github.jspinak.brobot.action.basic.click.ClickOptions;
BaseFindOptions findAndClick = new PatternFindOptions.Builder()
.setSimilarity(0.9)
.then(new ClickOptions.Builder()
.setNumberOfClicks(1)
.build())
.build();
See Action Chaining for advanced chaining patterns.
3. Composition Over Inheritanceโ
Shared configurations like MousePressOptions are composed rather than inherited:
import io.github.jspinak.brobot.action.basic.click.ClickOptions;
import io.github.jspinak.brobot.action.basic.mouse.MousePressOptions;
import io.github.jspinak.brobot.manageStates.mouse.MouseButton;
ClickOptions rightClick = new ClickOptions.Builder()
.setNumberOfClicks(1)
.setPressOptions(MousePressOptions.builder()
.setButton(MouseButton.RIGHT)
.build())
.build();
Common Base Propertiesโ
All ActionConfig classes inherit these properties from the base class:
pauseBeforeBegin- Delay before starting the actionpauseAfterEnd- Delay after completing the actionillustrate- Whether to create visual feedback for debuggingsuccessCriteria- Custom success validation logicsubsequentActions- Chained actions to execute after this action
See ActionConfig Base Class for complete property documentation.
Getting Startedโ
To start using ActionConfig:
Option 1: Convenience Methods (Recommended for Simple Operations)โ
As of Brobot 1.1.0, the simplest way to perform common actions is through convenience methods:
import org.springframework.beans.factory.annotation.Autowired;
import io.github.jspinak.brobot.action.Action;
import io.github.jspinak.brobot.datatypes.primitives.region.Region;
import org.sikuli.script.Pattern;
import org.sikuli.script.Location;
@Autowired
private Action action;
// Direct actions without ObjectCollection
action.click(region);
action.type("text");
action.find(pattern);
action.move(location);
These methods handle the ObjectCollection creation for you. See Convenience Methods for details.
Option 2: Traditional ActionConfig Approachโ
For more complex operations or when you need fine control:
- Choose the appropriate Options class for your action
- Use the builder to configure it
- Pass it to the
action.perform()method - Process the
ActionResult
Example:
import org.springframework.beans.factory.annotation.Autowired;
import io.github.jspinak.brobot.action.Action;
import io.github.jspinak.brobot.action.ActionResult;
import io.github.jspinak.brobot.action.basic.find.PatternFindOptions;
import io.github.jspinak.brobot.action.basic.click.ClickOptions;
import io.github.jspinak.brobot.datatypes.state.stateObject.stateImage.StateImage;
@Autowired
private Action action;
// Define the button image to find
StateImage buttonImage = new StateImage.Builder()
.withPattern(new Pattern("button.png"))
.build();
// Find and click the button with custom similarity
ActionResult result = action.perform(
new PatternFindOptions.Builder()
.setSimilarity(0.85)
.then(new ClickOptions.Builder()
.setNumberOfClicks(1)
.build())
.build(),
buttonImage
);
if (result.isSuccess()) {
System.out.println("Button clicked successfully!");
}
See ActionResult Components for details on processing results.
Next Stepsโ
- Upgrading to Latest - Learn how to migrate from ActionOptions
- Code Examples - See ActionConfig in action
- Action Chaining - Master action chaining patterns
- API Reference - Detailed API documentation
Related Documentationโ
- Action Hierarchy - Understanding the Action system
- States Guide - Working with states and state images
- Builder Performance Guide - Advanced builder techniques
- Configuration Properties - Application-level configuration