BrobotProperties Usage Guide
This guide explains how to configure and use BrobotProperties in your Brobot applications.
Overviewโ
BrobotProperties is the Spring-based configuration system for Brobot, providing type-safe, validated configuration management with excellent IDE support and testing capabilities.
Related Documentation:
- For a complete reference of all available properties, see the Configuration Properties Reference
- To understand how Brobot auto-configures these properties, see the Auto-Configuration Guide
- For testing patterns, see the Testing Introduction
Quick Start: Complete Working Exampleโ
Here's a minimal, fully functional example showing BrobotProperties in action:
Project Structureโ
my-brobot-app/
โโโ src/main/java/com/example/
โ โโโ MyBrobotApp.java
โโโ src/main/resources/
โ โโโ application.properties
โโโ src/test/java/com/example/
โโโ MyBrobotAppTest.java
MyBrobotApp.javaโ
package com.example;
import io.github.jspinak.brobot.config.core.BrobotProperties;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(basePackages = {
"com.example",
"io.github.jspinak.brobot"
})
public class MyBrobotApp {
public static void main(String[] args) {
SpringApplication.run(MyBrobotApp.class, args);
}
@Bean
public CommandLineRunner demo(BrobotProperties properties) {
return args -> {
System.out.println("=== Brobot Configuration ===");
System.out.println("Mock mode: " + properties.getCore().isMock());
System.out.println("Headless: " + properties.getCore().isHeadless());
System.out.println("Mouse delay: " + properties.getMouse().getMoveDelay());
System.out.println("Screenshot path: " + properties.getScreenshot().getPath());
};
}
}
application.propertiesโ
# Core configuration
brobot.core.mock=false
brobot.core.headless=false
# Mouse behavior
brobot.mouse.move-delay=0.3
# Screenshots
brobot.screenshot.path=screenshots
brobot.screenshot.save-snapshots=true
MyBrobotAppTest.javaโ
package com.example;
import io.github.jspinak.brobot.config.core.BrobotProperties;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
@TestPropertySource(properties = {
"brobot.core.mock=true",
"brobot.mouse.move-delay=0.01"
})
class MyBrobotAppTest {
@Autowired
private BrobotProperties properties;
@Test
void propertiesAreLoaded() {
assertTrue(properties.getCore().isMock(), "Mock mode should be enabled in tests");
assertEquals(0.01, properties.getMouse().getMoveDelay(), "Mouse delay should be overridden");
}
}
Expected Outputโ
=== Brobot Configuration ===
Mock mode: false
Headless: false
Mouse delay: 0.3
Screenshot path: screenshots
Next: For detailed configuration options, continue reading the sections below.
Configuration in application.propertiesโ
All Brobot configuration properties use the brobot. prefix and are organized into logical groups:
Core Propertiesโ
# Mock mode for testing without screen interaction
# Note: Can be set as either brobot.mock or brobot.core.mock
# Accessed in code via: brobotProperties.getCore().isMock()
brobot.core.mock=false
# Headless mode (no display available)
# Accessed in code via: brobotProperties.getCore().isHeadless()
brobot.core.headless=false
# Package name for state discovery
brobot.core.package-name=com.example.myapp
Mouse Propertiesโ
# Mouse movement delays
brobot.mouse.move-delay=0.5
brobot.mouse.pause-before-down=0.1
brobot.mouse.pause-after-down=0.1
Mock Timing Propertiesโ
These properties control simulated operation times when running in mock mode:
# Simulated operation times (in seconds)
brobot.mock.time-find-first=0.01
brobot.mock.time-find-all=0.04
brobot.mock.time-click=0.01
See Also: Mock Mode Guide for complete mock configuration options
Screenshot Propertiesโ
# Screenshot configuration
brobot.screenshot.save-snapshots=false
brobot.screenshot.path=images
Using BrobotProperties in Your Codeโ
Basic Usage with Dependency Injectionโ
import io.github.jspinak.brobot.config.core.BrobotProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class MyAutomationService {
@Autowired
private BrobotProperties brobotProperties;
public void performAction() {
if (brobotProperties.getCore().isMock()) {
// Execute mock behavior
System.out.println("Running in mock mode");
} else {
// Execute real automation
System.out.println("Running real automation");
}
}
public void configureMouseBehavior() {
double moveDelay = brobotProperties.getMouse().getMoveDelay();
System.out.println("Mouse move delay: " + moveDelay);
}
}
Accessing Nested Propertiesโ
BrobotProperties provides structured access to configuration groups:
import io.github.jspinak.brobot.config.core.BrobotProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class ConfigurationExample {
@Autowired
private BrobotProperties brobotProperties;
public void showConfiguration() {
// Core properties - accessed via getCore()
boolean mockMode = brobotProperties.getCore().isMock();
boolean headless = brobotProperties.getCore().isHeadless();
// Mouse configuration
BrobotProperties.Mouse mouse = brobotProperties.getMouse();
double moveDelay = mouse.getMoveDelay();
double pauseBeforeDown = mouse.getPauseBeforeDown();
// Mock timing configuration
BrobotProperties.Mock mock = brobotProperties.getMock();
double findFirstTime = mock.getTimeFindFirst();
double clickTime = mock.getTimeClick();
// Screenshot configuration
BrobotProperties.Screenshot screenshot = brobotProperties.getScreenshot();
boolean saveSnapshots = screenshot.isSaveSnapshots();
String screenshotPath = screenshot.getPath();
}
}
Configuration in Testsโ
Testing Resources:
- Mock Mode Guide - Comprehensive testing with mock mode
- Unit Testing Guide - Unit testing patterns with BrobotTestBase
- Integration Testing Guide - Integration testing patterns
- Profile-Based Testing - Advanced profile usage
Using @TestPropertySourceโ
import io.github.jspinak.brobot.config.core.BrobotProperties;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@SpringBootTest
@TestPropertySource(properties = {
"brobot.core.mock=true",
"brobot.mock.time-find-first=0.001",
"brobot.screenshot.save-snapshots=false"
})
class MyIntegrationTest {
@Autowired
private BrobotProperties brobotProperties;
@Test
void testInMockMode() {
assertTrue(brobotProperties.getCore().isMock());
assertEquals(0.001, brobotProperties.getMock().getTimeFindFirst());
}
}
Using application-test.propertiesโ
Create src/test/resources/application-test.properties:
# Test-specific configuration
brobot.mock=true
brobot.headless=true
brobot.screenshot.save-snapshots=false
brobot.mock.time-find-first=0.001
brobot.mock.time-click=0.001
Then activate the test profile:
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
@SpringBootTest
@ActiveProfiles("test")
class MyTest {
// Tests will use application-test.properties
}
Using BrobotTestBaseโ
For unit tests, extend BrobotTestBase which automatically configures mock mode:
import io.github.jspinak.brobot.test.BrobotTestBase;
import org.junit.jupiter.api.Test;
public class MyUnitTest extends BrobotTestBase {
@Test
public void testSomething() {
// Mock mode is automatically enabled
// No need to configure BrobotProperties manually
}
}
Learn More: For detailed information on unit testing with BrobotTestBase, see the Unit Testing Guide.
Working with Non-Spring Classesโ
Option 1: Convert to Spring Componentโ
import io.github.jspinak.brobot.config.core.BrobotProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
// Before: Static utility class
public class ImageUtils {
public static boolean shouldSaveScreenshot() {
return FrameworkSettings.saveSnapshots; // OLD WAY
}
}
// After: Spring component
@Component
public class ImageUtils {
@Autowired
private BrobotProperties brobotProperties;
public boolean shouldSaveScreenshot() {
return brobotProperties.getScreenshot().isSaveSnapshots();
}
}
Option 2: Pass as Parameterโ
import io.github.jspinak.brobot.config.core.BrobotProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
public class ImageUtils {
public static boolean shouldSaveScreenshot(BrobotProperties properties) {
return properties.getScreenshot().isSaveSnapshots();
}
}
// Usage
@Component
public class MyService {
@Autowired
private BrobotProperties brobotProperties;
public void process() {
if (ImageUtils.shouldSaveScreenshot(brobotProperties)) {
// Save screenshot
}
}
}
Option 3: Use ApplicationContextโ
import io.github.jspinak.brobot.config.core.BrobotProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class BrobotPropertiesProvider implements ApplicationContextAware {
private static ApplicationContext context;
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
context = applicationContext;
}
public static BrobotProperties getProperties() {
return context.getBean(BrobotProperties.class);
}
}
// Usage in non-Spring class
public class NonSpringClass {
public void someMethod() {
BrobotProperties props = BrobotPropertiesProvider.getProperties();
if (props.getCore().isMock()) {
// Mock behavior
}
}
}
Environment-Specific Configurationโ
Use Spring profiles to maintain different configurations for each environment. See Profile-Based Testing for advanced testing scenarios.
Development Environmentโ
application-dev.properties:
brobot.mock=false
brobot.screenshot.save-snapshots=true
brobot.debug.image.enabled=true # See: Image Find Debugging Guide
brobot.logging.verbosity=VERBOSE # See: Auto-Configuration Guide
Learn More: Image Find Debugging for debugging configuration
Production Environmentโ
application-prod.properties:
brobot.mock=false
brobot.screenshot.save-snapshots=false
brobot.debug.image.enabled=false
brobot.logging.verbosity=NORMAL
CI/CD Environmentโ
application-ci.properties:
brobot.mock=true
brobot.core.headless=true
brobot.gui-access.continue-on-error=true
brobot.gui-access.check-on-startup=false
CI/CD Tips: See Mock Mode Guide for headless testing strategies
Activating Profilesโ
Command line:
java -jar myapp.jar --spring.profiles.active=dev
Environment variable:
export SPRING_PROFILES_ACTIVE=prod
java -jar myapp.jar
Gradle:
./gradlew bootRun --args='--spring.profiles.active=ci'
Programmatically (for tests):
@SpringBootTest
@ActiveProfiles("test")
class MyTest {
// Uses application-test.properties
}
Best Practice: Use the
testprofile for all automated tests - it's automatically optimized with fast mock timings. See Auto-Configuration Guide for details.
Property Precedence and Validationโ
Property Loading Orderโ
Spring Boot loads properties in this order (highest priority first):
- @TestPropertySource in tests (highest priority)
- Command line arguments:
--brobot.core.mock=true - Java system properties:
-Dbrobot.core.mock=true - OS environment variables:
BROBOT_CORE_MOCK=true application-{profile}.propertiesfor active profiles- application.properties in your project
brobot-{profile}-defaults.propertiesfrom Brobot library- brobot-defaults.properties from Brobot library (lowest priority)
Example of precedence:
# brobot-defaults.properties (Brobot library)
brobot.mouse.move-delay=0.5
# application.properties (your project)
brobot.mouse.move-delay=0.3 # Overrides default
# application-dev.properties (when dev profile is active)
brobot.mouse.move-delay=0.1 # Overrides application.properties
# @TestPropertySource in test
brobot.mouse.move-delay=0.01 # Overrides everything
Result: In this scenario, tests use 0.01, dev environment uses 0.1, production uses 0.3.
Learn More: See Auto-Configuration Guide for detailed explanation of property loading
Property Validationโ
BrobotProperties uses Spring Boot's @ConfigurationProperties for type-safe property binding:
@ConfigurationProperties(prefix = "brobot")
public class BrobotProperties {
// Properties are bound at startup
// Type mismatches will cause startup failures
}
Validation behavior:
- Type checking: Spring Boot validates property types automatically
- Startup failure: Invalid properties cause application to fail fast
- Clear error messages: Type mismatches show helpful error messages
Note: The current implementation does not include JSR-303 validation annotations (
@Validated,@Min,@Max, etc.). Properties are validated through Spring Boot's type system and will fail at startup if types don't match. Future versions may add explicit validation constraints.
Common Configuration Patternsโ
Conditional Bean Creationโ
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ConditionalConfig {
@Bean
@ConditionalOnProperty(name = "brobot.core.mock", havingValue = "true")
public MockActionExecutor mockActionExecutor() {
return new MockActionExecutor();
}
@Bean
@ConditionalOnProperty(name = "brobot.core.mock", havingValue = "false", matchIfMissing = true)
public RealActionExecutor realActionExecutor() {
return new RealActionExecutor();
}
}
Configuration Profilesโ
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
@Component
@Profile("!mock")
public class RealScreenCapture implements ScreenCapture {
// Implementation for real screen capture
}
@Component
@Profile("mock")
public class MockScreenCapture implements ScreenCapture {
// Mock implementation
}
Troubleshootingโ
Properties Not Loadingโ
Symptoms: Properties have default values instead of configured values
Diagnosis:
import io.github.jspinak.brobot.config.core.BrobotProperties;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.core.env.Environment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class PropertyDiagnostics {
@Autowired
private Environment environment;
@Autowired
private BrobotProperties properties;
public void diagnose() {
// Check if property is in environment
String mockValue = environment.getProperty("brobot.core.mock");
System.out.println("Property brobot.core.mock from environment: " + mockValue);
// Check bound value
System.out.println("Property from BrobotProperties: " + properties.getCore().isMock());
// List all property sources
System.out.println("\n=== Property Sources (in order) ===");
if (environment instanceof org.springframework.core.env.ConfigurableEnvironment) {
org.springframework.core.env.ConfigurableEnvironment env =
(org.springframework.core.env.ConfigurableEnvironment) environment;
env.getPropertySources().forEach(ps ->
System.out.println("- " + ps.getName())
);
}
}
}
Solutions:
- Ensure
application.propertiesis insrc/main/resources - Check property names use correct prefix:
brobot.(notbrobot-) - Verify Spring Boot is properly configured with
@SpringBootApplication - Check for typos in property names (case-sensitive)
- Ensure
@ComponentScanincludesio.github.jspinak.brobot
See Also: Auto-Configuration Guide explains property loading order
Cannot Access in Static Contextโ
Problem: Cannot inject BrobotProperties into static methods or non-Spring classes
Solutions: See the Working with Non-Spring Classes section above for three different approaches.
Test Properties Not Appliedโ
Symptoms: Test runs with production properties instead of test properties
Diagnosis:
import io.github.jspinak.brobot.config.core.BrobotProperties;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.env.Environment;
@SpringBootTest
class PropertyLoadingTest {
@Autowired
private Environment environment;
@Autowired
private BrobotProperties properties;
@Test
void verifyTestPropertiesLoaded() {
// Check active profiles
String[] profiles = environment.getActiveProfiles();
System.out.println("Active profiles: " + String.join(", ", profiles));
// Check property value
String mockValue = environment.getProperty("brobot.core.mock");
System.out.println("brobot.core.mock = " + mockValue);
// Verify bound value
System.out.println("Actual mock mode: " + properties.getCore().isMock());
}
}
Solutions:
- Use
@TestPropertySourceannotation (see Configuration in Tests) - Use
@ActiveProfiles("test")withapplication-test.properties - For unit tests, extend BrobotTestBase
- Ensure test properties file is in
src/test/resources - Check that profile is actually activated (see diagnosis above)
IDE Auto-completion Not Workingโ
Problem: No auto-completion for brobot.* properties in application.properties
Solution:
- Add Spring Boot Configuration Processor dependency:
Gradle (build.gradle):
dependencies {
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
}
Maven (pom.xml):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
-
Enable annotation processing in your IDE:
- IntelliJ IDEA: Settings โ Build โ Compiler โ Annotation Processors โ Enable annotation processing
- Eclipse: Project Properties โ Java Compiler โ Annotation Processing โ Enable project specific settings
- VS Code: Install Spring Boot Extension Pack
-
Rebuild project to generate metadata
Note: This dependency is not currently in the Brobot project but is recommended for improved developer experience.
Property Value Type Mismatchโ
Symptoms: Application fails to start with property binding error
Example Error:
Failed to bind properties under 'brobot.mouse.move-delay' to double:
Reason: failed to convert java.lang.String to double
Solution: Check property value types match expectations:
# โ
CORRECT
brobot.mouse.move-delay=0.5
# โ WRONG - not a number
brobot.mouse.move-delay=slow
See Also: Properties Reference for expected types of all properties
Benefitsโ
- Type Safety: Properties are validated at startup
- IDE Support: Auto-completion and documentation
- Testing: Easy to override for different test scenarios
- No Static State: Better for concurrent testing
- Spring Integration: Works with profiles, conditions, and validation
- Environment Flexibility: Different configs per environment
Summaryโ
BrobotProperties provides a modern, flexible configuration system that integrates seamlessly with Spring Boot. By using dependency injection and property files, you get type-safe, testable, and maintainable configuration management for your Brobot automation projects.
Next Stepsโ
- Complete Properties Reference: See Configuration Properties Reference for all available properties and their default values
- Auto-Configuration Details: Learn how Brobot configures itself automatically in the Auto-Configuration Guide
- Testing Setup: Get started with testing using the Testing Introduction
- Mock Mode: Understand mock mode testing with the Mock Mode Guide
- Getting Started: New to Brobot? Check out the Quick Start Guide