Skip to content

JJsoprano/JavaRobotProject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java Robot and WebDriver Automation Project

This project combines the capabilities of Java Robot class with Selenium WebDriver for comprehensive automation tasks. It demonstrates desktop automation using Robot class and web browser automation using Selenium WebDriver.

Project Structure

JavaRobotProject/
├── pom.xml                              # Maven configuration
├── testng.xml                           # TestNG test suite configuration
├── src/
│   ├── main/
│   │   └── java/
│   │       └── com/
│   │           └── robotexamples/
│   │               ├── RobotMain.java           # Basic Robot functionality demo
│   │               ├── KeyboardAutomation.java  # Advanced keyboard automation
│   │               ├── MouseAutomation.java     # Mouse movement and clicking
│   │               ├── ScreenCapture.java       # Screenshot and image analysis
│   │               ├── RobotUtils.java          # Utility functions and helpers
│   │               └── WebDriverUtils.java      # Selenium WebDriver utilities
│   └── test/
│       └── java/
│           └── com/
│               └── robotexamples/
│                   └── WebDriverTest.java       # WebDriver test examples
└── test-results/                        # Test output and screenshots

Dependencies

  • Java 17+
  • Selenium WebDriver 4.24.0 - Web browser automation
  • WebDriverManager 5.6.2 - Automatic driver management
  • TestNG 7.8.0 - Testing framework
  • Apache Commons IO - File operations
  • Log4j2 - Logging

Features

Desktop Automation (Java Robot)

1. RobotMain.java

  • Basic text typing automation
  • Simple mouse movement and clicking
  • Keyboard shortcuts (Ctrl+A, Ctrl+C, etc.)
  • Introduction to Robot class concepts

2. KeyboardAutomation.java

  • Advanced text input with special characters
  • Complex keyboard shortcuts and combinations
  • Function key support
  • Arrow key navigation
  • Window switching (Alt+Tab)

3. MouseAutomation.java

  • Precise mouse movement and positioning
  • Smooth mouse motion between points
  • Different types of clicks (left, right, double)
  • Drag and drop operations
  • Mouse wheel scrolling
  • Drawing shapes and patterns

4. ScreenCapture.java

  • Full screen and partial screen capture
  • Screenshot saving with timestamps
  • Time-lapse screenshot sequences
  • Pixel color detection and analysis
  • Color-based screen searching
  • Image comparison and similarity detection
  • Screen region monitoring for changes

5. RobotUtils.java

  • Human-like typing with variable delays
  • Natural mouse movement with curves
  • Convenient shortcut methods
  • Color and image matching utilities
  • Wait functions for UI synchronization
  • Common automation sequences

Web Automation (Selenium WebDriver)

6. WebDriverUtils.java

  • Chrome WebDriver initialization (normal and headless modes)
  • Automatic driver management with WebDriverManager
  • Element finding strategies (ID, CSS Selector, XPath)
  • Smart wait conditions for reliable automation
  • Screenshot capture integration
  • Common web interactions (click, type, navigate)

7. WebDriverTest.java

  • Example test cases using TestNG framework
  • Integration of WebDriver with Robot automation
  • Demonstration of web and desktop automation combination

Requirements

  • Java 17+
  • Maven 3.6+
  • GUI environment (for Robot class functionality)
  • Web browsers (Chrome recommended for WebDriver tests)

Setup and Usage

1. Clone the repository:

git clone https://github.com/yourusername/JavaRobotProject.git
cd JavaRobotProject

2. Compile the project using Maven:

mvn clean compile

3. Run tests:

# Run all tests
mvn test

# Run specific test class
mvn test -Dtest=WebDriverTest

# Run with TestNG configuration
mvn surefire:test

4. Run individual Robot examples:

# Basic Robot functionality
mvn exec:java -Dexec.mainClass="com.robotexamples.RobotMain"

# Keyboard automation demo
mvn exec:java -Dexec.mainClass="com.robotexamples.KeyboardAutomation"
# Mouse automation demo
mvn exec:java -Dexec.mainClass="com.robotexamples.MouseAutomation"

# Screen capture demo
mvn exec:java -Dexec.mainClass="com.robotexamples.ScreenCapture"

Important Notes

Security Considerations

  • Robot class requires appropriate permissions
  • Some antivirus software may flag Robot-based applications
  • WebDriver may require browser permissions
  • Always test in a safe environment
  • Be careful with automated input

Platform Differences

  • Key codes may vary between operating systems
  • Some special characters require different handling
  • Mouse behavior might differ across platforms
  • WebDriver behavior may vary between browsers

Best Practices

  • Always include appropriate delays between actions
  • Use try-catch blocks for exceptions
  • Test automation scripts thoroughly
  • Consider user interruption mechanisms
  • Validate screen coordinates and web element locations
  • Use WebDriverWait for reliable web automation

Example Use Cases

Desktop Automation

  • UI Testing: Automate desktop application testing
  • Form Filling: Automatically fill out repetitive forms
  • Screen Monitoring: Monitor screen changes for alerts
  • Data Entry: Automate data entry between applications
  • Gaming Automation: Automate repetitive gaming tasks
  • Accessibility Tools: Create assistive technology

Web Automation

  • Web Testing: Automated testing of web applications
  • Data Scraping: Extract data from websites
  • Form Submission: Automate web form submissions
  • Performance Testing: Test web application performance
  • Cross-browser Testing: Test across different browsers
  • E2E Testing: End-to-end workflow testing

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Java Robot class documentation
  • Selenium WebDriver community
  • TestNG testing framework
  • Maven build tool

Troubleshooting

Common Issues

  1. AWTException: Robot cannot be created

    • Check if running in GUI environment
    • Verify Java permissions
    • Some systems require special privileges
  2. SecurityException: Access denied

    • Run with appropriate permissions
    • Check security manager settings
  3. Inconsistent Behavior: Actions don't work as expected

    • Increase delays between actions
    • Verify screen coordinates
    • Check for resolution differences

Tips

  • Start with simple examples and gradually increase complexity
  • Use robot.setAutoDelay() to add consistent delays
  • Test on your target environment before deployment
  • Consider screen resolution and scaling factors

Contributing

Feel free to extend these examples with additional functionality:

  • Add more complex automation sequences
  • Implement error handling and recovery
  • Add support for more file formats in screen capture
  • Create configuration files for customizable behavior

License

This project is provided as educational examples for learning Java Robot class automation.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages