# Midscene Java [](https://zread.ai/Master-Frank/midscene-java)
[](https://opensource.org/licenses/MIT)
[](https://www.oracle.com/java/technologies/javase-jdk17-downloads.html)
[](https://search.maven.org/artifact/com.midscene/midscene-java-parent)
AI-powered automation framework for Web and Android with natural language-driven UI operations - Java version
## ๐ Language Version
- [ไธญๆ็ๆฌ (Chinese Version)](README-zh.md)
## ๐ Project Overview
Midscene Java is a revolutionary AI-powered automation framework designed for UI automation operations on Web and Android platforms. It is the Java implementation of Midscene Python, inheriting its core philosophy: **making automation as simple as speaking**.
### ๐ฏ Core Features
- **Natural Language Operations** - Describe operation intentions in everyday language, and AI will automatically understand and execute them
- **Intelligent Element Locating** - Multi-strategy fusion, automatically selects the optimal positioning method, adapts to page changes
- **Structured Data Extraction** - Use natural language to extract complex structured data
- **Intelligent Assertion Verification** - Describe verification conditions in natural language, AI automatically judges
- **Multi-Platform Support** - Unified interface supports Web and Android platforms
- **Visual Debugging** - Detailed execution screenshots and decision process recording
- **Code Optimization and Refactoring** - Systematically refactored for more modular and maintainable code
## ๐๏ธ Project Structure
```
midscene-java/
โโโ packages/
โ โโโ core/ # Core module, providing Agent and AI engine
โ โโโ web/ # Web automation module
โ โ โโโ playwright/ # Playwright implementation
โ โ โโโ selenium/ # Selenium implementation
โ โโโ android/ # Android automation module
โ โโโ cli/ # Command line tool
โ โโโ examples/ # Example code
โ โโโ playground/ # Development testing environment
โ โโโ tests/ # Test cases
โโโ apps/ # Application examples
โโโ docs/ # Project documentation and optimization plans
โโโ wiki/ # Project wiki documentation
```
## ๐ Quick Start
### Prerequisites
- Java 17+
- Maven 3.6+ or Gradle 7.0+
- Browser (Chrome/Firefox/Edge, for Web automation)
- AI model API Key (Choose one from OpenAI, Claude, Qwen, or Gemini)
### Installation
Add Midscene Java dependencies to your `pom.xml` file:
```xml
com.midscene
midscene-core
0.1.1
com.midscene
midscene-web-playwright
0.1.1
com.midscene
midscene-web-selenium
0.1.1
com.midscene
midscene-android
0.1.1
```
### Configure AI Model
Create an `application.properties` or `application.yml` file to configure the AI model:
```properties
# application.properties
midscene.ai.provider=openai
midscene.ai.model=gpt-4-vision-preview
midscene.ai.api-key=your_openai_api_key_here
```
### Example Code
#### Web Automation Example
```java
package com.example;
import com.midscene.core.Agent;
import com.midscene.web.playwright.PlaywrightPage;
import com.midscene.web.playwright.PlaywrightUIContextProvider;
import com.microsoft.playwright.Playwright;
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.Page;
public class SearchExample {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
// Create browser instance
Browser browser = playwright.chromium().launch();
Page page = browser.newPage();
// Create PlaywrightPage wrapper
PlaywrightPage playwrightPage = new PlaywrightPage(page);
// Create Agent
Agent agent = new Agent(new PlaywrightUIContextProvider(playwrightPage));
// Navigate to website
page.navigate("https://www.baidu.com");
// Use natural language for search
agent.aiAction("Type 'Java tutorial' in the search box");
agent.aiAction("Click the search button");
// Verify search results
agent.aiAssert("The page displays search results for Java tutorials");
System.out.println("โ
Search operation completed!");
// Close browser
browser.close();
}
}
}
```
#### Data Extraction Example
```java
package com.example;
import com.midscene.core.Agent;
import com.midscene.web.playwright.PlaywrightPage;
import com.midscene.web.playwright.PlaywrightUIContextProvider;
import com.microsoft.playwright.Playwright;
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.Page;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ExtractExample {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch();
Page page = browser.newPage();
PlaywrightPage playwrightPage = new PlaywrightPage(page);
Agent agent = new Agent(new PlaywrightUIContextProvider(playwrightPage));
// Visit news website
page.navigate("https://news.example.com");
// Extract structured data
Map schema = new HashMap<>();
schema.put("articles", List.of(
Map.of(
"title", "News title",
"time", "Publish time",
"summary", "News summary"
)
));
Map newsData = agent.aiExtract(schema);
// Output results
List