1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! 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(())
}