fix: dedup text content in snapshot (#909)

* fix: dedup text content in snapshot

* fix: format

---------

Co-authored-by: 羲洋 <lipengyang.lpy@alibaba-inc.com>
This commit is contained in:
Lppy
2026-03-18 10:59:56 -05:00
committed by GitHub
co-authored by 羲洋
parent d03f6431ea
commit 4be4605543
2 changed files with 64 additions and 1 deletions
+63
View File
@@ -2210,3 +2210,66 @@ async fn e2e_snapshot_cursor_many_elements() {
let resp = execute_command(&json!({ "id": "99", "action": "close" }), &mut state).await;
assert_success(&resp);
}
/// Test that InlineTextBox nodes are filtered from snapshot output while preserving
/// the actual text content from parent elements.
#[tokio::test]
#[ignore]
async fn e2e_snapshot_inline_text_box_filtered() {
let mut state = DaemonState::new();
let resp = execute_command(
&json!({ "id": "1", "action": "launch", "headless": true }),
&mut state,
)
.await;
assert_success(&resp);
// Simple HTML with text content that would generate InlineTextBox nodes
let html =
"data:text/html,<html><body><div><span>Hello</span> <span>World</span></div></body></html>";
let resp = execute_command(
&json!({ "id": "2", "action": "navigate", "url": html }),
&mut state,
)
.await;
assert_success(&resp);
// Take snapshot to capture full output and verify InlineTextBox filtering
let start = std::time::Instant::now();
let resp = execute_command(&json!({ "id": "3", "action": "snapshot" }), &mut state).await;
assert_success(&resp);
let elapsed = start.elapsed();
let snapshot_output = get_data(&resp)["snapshot"].as_str().unwrap();
// Verify that InlineTextBox does not appear in the output
assert!(
!snapshot_output.contains("InlineTextBox"),
"Snapshot output should not contain InlineTextBox: {}",
snapshot_output
);
// Verify that the actual text content is preserved
assert!(
snapshot_output.contains("Hello"),
"Snapshot should contain 'Hello': {}",
snapshot_output
);
assert!(
snapshot_output.contains("World"),
"Snapshot should contain 'World': {}",
snapshot_output
);
// Must complete quickly
assert!(
elapsed.as_secs() < 5,
"snapshot with InlineTextBox filtering took {:?}, expected < 5s",
elapsed,
);
let resp = execute_command(&json!({ "id": "99", "action": "close" }), &mut state).await;
assert_success(&resp);
}