Quick Migration Reference: ActionOptions to ActionConfig
This guide helps you migrate your existing Brobot automation code from ActionOptions
to the new ActionConfig
hierarchy.
Quick Reference
Action Type Mapping
ActionOptions.Action | New ActionConfig Class |
---|---|
FIND | PatternFindOptions , BaseFindOptions |
CLICK | ClickOptions |
TYPE | TypeOptions |
DRAG | DragOptions |
MOVE | MouseMoveOptions |
MOUSE_DOWN | MouseDownOptions |
MOUSE_UP | MouseUpOptions |
DEFINE | DefineRegionOptions |
HIGHLIGHT | HighlightOptions |
SCROLL_MOUSE_WHEEL | ScrollMouseWheelOptions |
VANISH | VanishOptions |
CLICK_UNTIL | ClickUntilOptions |
Field Mapping
ActionOptions Field | New Location |
---|---|
minScore | similarity in find options |
clickType | numberOfClicks + MousePressOptions |
textToType | text in TypeOptions |
dragToOffsetX/Y | Removed (use target locations) |
moveMouseAfterAction | Action-specific option |
Migration Examples
Find Action
Before (ActionOptions)
ActionOptions findOptions = new ActionOptions.Builder()
.setAction(ActionOptions.Action.FIND)
.setSimilarity(0.8)
.setSearchRegions(searchRegions)
.build();
action.perform(findOptions, stateImage);
After (ActionConfig)
PatternFindOptions findOptions = new PatternFindOptions.Builder()
.setSimilarity(0.8)
.setSearchRegions(searchRegions)
.build();
action.perform(findOptions, stateImage);
Click Action
Before
ActionOptions clickOptions = new ActionOptions.Builder()
.setAction(ActionOptions.Action.CLICK)
.setClickType(ActionOptions.ClickType.DOUBLE_LEFT)
.setPauseBeforeMouseDown(0.5)
.build();
After
ClickOptions clickOptions = new ClickOptions.Builder()
.setNumberOfClicks(2)
.setPressOptions(new MousePressOptions.Builder()
.setButton(MouseButton.LEFT)
.setPauseBeforeMouseDown(0.5)
.build())
.build();
Type Action
Before
ActionOptions typeOptions = new ActionOptions.Builder()
.setAction(ActionOptions.Action.TYPE)
.setTextToType("Hello World")
.setModifierKeys(new String[]{"ctrl", "a"})
.build();
After
TypeOptions typeOptions = new TypeOptions.Builder()
.setText("Hello World")
.setModifierKeys("ctrl", "a")
.build();
Drag Action
Before
ActionOptions dragOptions = new ActionOptions.Builder()
.setAction(ActionOptions.Action.DRAG)
.setDragToOffsetX(100)
.setDragToOffsetY(50)
.build();
After
DragOptions dragOptions = new DragOptions.Builder()
.setFromOptions(new PatternFindOptions.Builder()
.setSimilarity(0.9)
.build())
.setToOptions(new PatternFindOptions.Builder()
.setSimilarity(0.9)
.build())
.build();
Key Changes
1. Mouse Button Separation
Mouse button and click count are now separate:
// Before: Combined in ClickType enum
.setClickType(ActionOptions.ClickType.DOUBLE_RIGHT)
// After: Separate configuration
.setNumberOfClicks(2)
.setPressOptions(new MousePressOptions.Builder()
.setButton(MouseButton.RIGHT)
.build())
2. Action Chaining
The new API supports fluent chaining:
ActionConfig findAndClick = new PatternFindOptions.Builder()
.setSimilarity(0.9)
.then(new ClickOptions.Builder()
.setNumberOfClicks(1)
.build())
.build();
3. Verification as Composition
Verification is now composed, not inherited:
ClickOptions clickWithVerification = new ClickOptions.Builder()
.setNumberOfClicks(1)
.setVerificationOptions(new VerificationOptions.Builder()
.setEvent(VerificationOptions.Event.OBJECTS_VANISH)
.setObjectCollection(verifyCollection)
.build())
.build();
4. Drag Returns Movement
Drag operations now return Movement
objects instead of regions:
ActionResult result = action.perform(dragOptions, source, target);
Movement movement = result.getMovement().orElse(null);
Step-by-Step Migration
1. Update Imports
Replace:
import io.github.jspinak.brobot.action.ActionOptions;
With specific imports:
import io.github.jspinak.brobot.action.basic.click.ClickOptions;
import io.github.jspinak.brobot.action.basic.find.PatternFindOptions;
import io.github.jspinak.brobot.action.basic.type.TypeOptions;
// ... other specific options
2. Replace Builders
Find all new ActionOptions.Builder()
and replace with specific builders:
// Find all instances of:
new ActionOptions.Builder().setAction(ActionOptions.Action.CLICK)
// Replace with:
new ClickOptions.Builder()
3. Update Field Names
minScore
→similarity
textToType
→text
- Remove
dragToOffsetX/Y
(use proper drag configuration)
4. Handle Special Cases
Wait Operations
Wait is no longer an action. Use conditions or pauses:
// Before
ActionOptions wait = new ActionOptions.Builder()
.setAction(ActionOptions.Action.WAIT)
.setMaxWait(5)
.build();
// After - use VanishOptions or pause
VanishOptions waitForVanish = new VanishOptions.Builder()
.setTimeout(5.0)
.build();
Custom Find Operations
Replace tempFind
with proper find configurations:
// Before
actionOptions.setTempFind(customCollection);
// After
CustomFindOptions customFind = new CustomFindOptions.Builder()
.setCustomCriteria(...)
.build();
Common Pitfalls
- Don't instantiate abstract builders:
BaseFindOptions.Builder
is abstract - MousePressOptions is composed: Don't try to extend it
- Check method names: Some have changed (e.g.,
setTimeoutInSeconds
→setTimeout
) - Verify imports: Make sure you're using the right Options class
Testing Your Migration
After migrating:
- Compile: Fix any compilation errors
- Test: Run your test suite
- Verify: Check that actions behave as expected
- Performance: Ensure no performance degradation
Gradual Migration
If you can't migrate everything at once:
- The
ActionOptionsAdapter
provides backward compatibility - Migrate one action type at a time
- Test thoroughly after each migration
- Remove adapter once fully migrated
Need Help?
- Check the API Reference for detailed documentation
- Review Code Examples for usage patterns
- Consult the Fluent API Guide for chaining patterns