computeruse-rs 2.0.0

A Playwright-style SDK for automating desktop GUI applications
//! Test the fixed browser script functionality
//! This tests the console result extraction with the improved methods

use computeruse::{AutomationError, Desktop};

#[tokio::main]
async fn main() -> Result<(), AutomationError> {
    println!("๐Ÿงช Testing fixed browser script functionality...");

    let desktop = Desktop::new(true, false)?;

    // Find browser window
    match desktop.locator("role:pane").all(None, None).await {
        Ok(windows) => {
            for window in &windows {
                if let Some(name) = window.name() {
                    if name.contains("Chrome") {
                        println!("๐ŸŒ Found Chrome window: {name}");

                        // Test the browser script with a simple command
                        let test_script = "2 + 2";
                        println!("๐Ÿงฎ Testing script: {test_script}");

                        match computeruse::browser_script::execute_script(window, test_script).await
                        {
                            Ok(result) => {
                                println!("โœ… Success! Result: {result}");
                                if result.contains("4") {
                                    println!("๐ŸŽฏ Correct mathematical result!");
                                } else {
                                    println!("โš ๏ธ Unexpected result: {result}");
                                }
                            }
                            Err(e) => {
                                println!("โŒ Error: {e}");
                            }
                        }
                        break;
                    }
                }
            }
        }
        Err(e) => {
            println!("โŒ Failed to find windows: {e}");
        }
    }

    Ok(())
}