Skip to main content
Version: Latest

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 action
  • pauseAfterEnd - Delay after completing the action
  • illustrate - Whether to create visual feedback for debugging
  • successCriteria - Custom success validation logic
  • subsequentActions - Chained actions to execute after this action

See ActionConfig Base Class for complete property documentation.

Getting Startedโ€‹

To start using ActionConfig:

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:

  1. Choose the appropriate Options class for your action
  2. Use the builder to configure it
  3. Pass it to the action.perform() method
  4. 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โ€‹