DEV Community

Suresh Ayyanna
Suresh Ayyanna

Posted on

πŸš€ Karate Robot Desktop Automation: Installation Guide

Karate Robot extends the popular Karate Framework to enable desktop automation for Windows, macOS, and Linux. This guide will walk you through installing and configuring Karate Robot, ensuring you have everything you need to get started.

πŸ› οΈ System Requirements
Before we dive into the installation, make sure your system meets the following requirements:

Java Development Kit (JDK): Version 11 or higher
Apache Maven: Version 3.6 or higher
Karate: Version 1.5.0 or later
Operating System: Windows, macOS, or Linux
πŸ“₯ Step 1: Install Java JDK
Karate requires Java to run. If you don't have Java installed, follow these steps:

πŸ”— Download Java JDK
Go to the Oracle JDK download page or AdoptOpenJDK.
Download the JDK version compatible with your operating system (JDK 11 or higher).
Run the installer and follow the prompts.
πŸ› οΈ Set up Java Environment Variables (Windows Only)
Open System Properties β†’ Advanced β†’ Environment Variables.
Add a new system variable:
Variable Name: JAVA_HOME
Variable Value: Path to your Java installation (e.g., C:\Program Files\Java\jdk-11.0.16).
Edit the Path variable and add: %JAVA_HOME%\bin.
Open a terminal and verify the installation:
bash
Copy code
java -version
πŸ“¦ Step 2: Install Apache Maven
Karate uses Maven for build automation. If Maven is not installed, follow these steps:

πŸ”— Download Apache Maven
Go to the Apache Maven download page.
Download the binary .zip or .tar.gz file for your OS.
Extract the files to a directory of your choice (e.g., C:\apache-maven-3.9.5).
πŸ› οΈ Set up Maven Environment Variables (Windows Only)
Open System Properties β†’ Advanced β†’ Environment Variables.
Add a new system variable:
Variable Name: MAVEN_HOME
Variable Value: Path to your Maven installation (e.g., C:\apache-maven-3.9.5).
Edit the Path variable and add: %MAVEN_HOME%\bin.
Verify the installation:
bash
Copy code
mvn -version
πŸ“ Step 3: Create a Karate Project
Now that Java and Maven are installed, let's create a Karate project.

πŸ› οΈ Generate a Karate Project using Maven
Open a terminal and run the following Maven command:
bash
Copy code
mvn archetype:generate -DgroupId=com.example.karate -DartifactId=karate-robot-demo -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Navigate to the project directory:
bash
Copy code
cd karate-robot-demo
πŸ“„ Add Karate Dependencies to pom.xml
Open the pom.xml file in your favorite editor and add the following dependencies:

xml
Copy code

<!-- Karate Core for API and Web Testing -->

com.intuit.karate
karate-core
1.5.1

<!-- Karate Robot for Desktop Automation -->

com.intuit.karate
karate-robot
1.5.1


πŸ”„ Update Maven Project
Save the pom.xml file.
Run the following command to update the dependencies:
bash
Copy code
mvn clean install
πŸ”§ Step 4: Setting Up Karate Robot
Karate Robot requires some additional configurations to work effectively with desktop applications.

πŸ“„ Create a karate-config.js file
In your src/test/java folder, create a karate-config.js file:

javascript
Copy code
function fn() {
var config = {
baseUrl: 'https://example.com', // Placeholder URL
robot: karate.robot() // Initialize Karate Robot
};
return config;
}
πŸ“„ Create a Karate Feature File for Desktop Automation
Create a folder named features in src/test/java.
Create a new file named DesktopAutomation.feature:
gherkin
Copy code
Feature: Desktop Automation using Karate Robot

Scenario: Launch Notepad and Type Text
* def robot = karate.robot()
* robot.winRun('notepad.exe')
* robot.waitForWindow('Untitled - Notepad')
* robot.type('Hello from Karate Robot!')
* robot.screenshot()
* robot.key('ALT+F4')
* robot.key('ENTER')
▢️ Step 5: Running Your Karate Robot Test
To run your test:

Open a terminal in your project directory.

Run the following Maven command:

bash
Copy code
mvn test -Dkarate.options="classpath:features/DesktopAutomation.feature"
βœ… Expected Output
You should see output in the console indicating that the Notepad application was launched, text was typed, and a screenshot was captured.

πŸ“š Additional Tips
Enable Windows Developer Mode: For better control over desktop automation, enable developer mode on Windows:
Go to Settings β†’ Update & Security β†’ For Developers β†’ Developer Mode.
Run as Administrator: If you encounter permission issues, try running your terminal or IDE as an administrator.
Capture Screenshots for Debugging: Use robot.screenshot() frequently to capture the state of your desktop during test runs.
πŸŽ‰ Conclusion
Congratulations! You've successfully set up Karate Robot for desktop automation. This powerful tool allows you to automate not just web and API interactions but also native desktop applications, expanding your testing capabilities.

Feel free to explore more advanced features like image recognition, mouse drag-and-drop, and file manipulations. Happy testing! πŸš€

πŸ“š Further Reading
Karate GitHub Repository
Karate Robot Documentation

Top comments (0)