use std::time::Duration;
use computeruse::{AutomationError, Desktop, FontStyle, TextPosition};
use tokio::time::sleep;
#[tokio::main]
async fn main() -> Result<(), AutomationError> {
println!("🎯 Testing Highlight Functionality");
println!("{}", "=".repeat(50));
let desktop = Desktop::new(false, false)?;
println!("\n1. Finding Calculator application...");
let apps = desktop.applications()?;
let calculator = apps
.iter()
.find(|app| {
app.name()
.unwrap_or_default()
.to_lowercase()
.contains("calculator")
})
.ok_or_else(|| {
AutomationError::PlatformError(
"Calculator not found. Please open Calculator first.".to_string(),
)
})?;
println!(
"✅ Found Calculator: {}",
calculator.name().unwrap_or("Unknown".to_string())
);
println!("\n2. Finding Calculator buttons to highlight...");
let button = match calculator.locator("role:Button") {
Ok(locator) => match locator.first(None).await {
Ok(button) => {
println!(
"✅ Found a button: {}",
button.name().unwrap_or("Unknown".to_string())
);
button
}
Err(e) => {
println!("❌ No buttons found: {e}");
match calculator.locator("role:*") {
Ok(locator) => match locator.first(None).await {
Ok(element) => {
println!(
"✅ Found a clickable element: {} ({})",
element.name().unwrap_or("Unknown".to_string()),
element.role()
);
element
}
Err(e) => {
println!("❌ No clickable elements found: {e}");
return Ok(());
}
},
Err(e) => {
println!("❌ Failed to create locator: {e}");
return Ok(());
}
}
}
},
Err(e) => {
println!("❌ Failed to create locator for buttons: {e}");
return Ok(());
}
};
println!("\n3. Testing highlight with different font colors...");
let black_font_style = FontStyle {
size: 16, bold: true, color: 0x000000, };
println!(" 🔸 Test 1: Top position with black text");
match button.highlight(
Some(0x0000FF), Some(Duration::from_millis(2000)), Some("BLACK TEXT"), Some(TextPosition::Top), Some(black_font_style), ) {
Ok(handle) => {
println!(" ✅ Black text highlight started - should be readable!");
sleep(Duration::from_millis(2500)).await;
drop(handle);
println!(" 📝 Top highlight completed");
}
Err(e) => {
println!(" ❌ Failed to highlight button: {e}");
}
}
sleep(Duration::from_millis(500)).await;
let red_font_style = FontStyle {
size: 16, bold: true, color: 0x0000FF, };
println!(" 🔸 Test 2: Text color matching border color (red)");
match button.highlight(
Some(0x0000FF), Some(Duration::from_millis(2000)), Some("RED TEXT"), Some(TextPosition::Inside), Some(red_font_style), ) {
Ok(handle) => {
println!(" ✅ Red text highlight started - matching border color!");
sleep(Duration::from_millis(2500)).await;
drop(handle);
println!(" 📝 Inside highlight completed");
}
Err(e) => {
println!(" ❌ Failed to highlight button: {e}");
}
}
println!("\n🎉 Highlight test completed!");
println!("\nFeatures tested:");
println!(" ✅ Element highlighting with custom colors");
println!(" ✅ TOP-LEFT aligned text positioning");
println!(" ✅ Text inside element positioning");
println!(" ✅ Black text for readability");
println!(" ✅ Text color matching border color");
println!(" ✅ Custom font styling (size, bold)");
Ok(())
}