#![cfg(feature = "integration")]
use std::sync::Once;
use viewpoint_core::Browser;
static TRACING_INIT: Once = Once::new();
fn init_tracing() {
TRACING_INIT.call_once(|| {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::from_default_env()
.add_directive(tracing::Level::INFO.into()),
)
.with_test_writer()
.try_init()
.ok();
});
}
#[tokio::test]
async fn test_aria_snapshot_includes_refs_for_buttons() {
init_tracing();
let browser = Browser::launch()
.headless(true)
.launch()
.await
.expect("Failed to launch browser");
let context = browser
.new_context()
.await
.expect("Failed to create context");
let page = context.new_page().await.expect("Failed to create page");
page.set_content(
r#"
<html><body>
<button id="btn1">Click me</button>
<button id="btn2">Submit</button>
</body></html>
"#,
)
.set()
.await
.expect("Failed to set content");
let snapshot = page.aria_snapshot().await.expect("Failed to get snapshot");
let yaml = snapshot.to_yaml();
println!("Snapshot with refs:\n{yaml}");
assert!(
yaml.contains("[ref=c") && yaml.contains('p') && yaml.contains('e'),
"Snapshot should contain refs for buttons in format c{{ctx}}p{{page}}e{{counter}}, got: {yaml}"
);
browser.close().await.expect("Failed to close browser");
}
#[tokio::test]
async fn test_aria_snapshot_includes_refs_for_headings() {
init_tracing();
let browser = Browser::launch()
.headless(true)
.launch()
.await
.expect("Failed to launch browser");
let context = browser
.new_context()
.await
.expect("Failed to create context");
let page = context.new_page().await.expect("Failed to create page");
page.set_content(
r"
<html><body>
<h1>Main Title</h1>
<h2>Subtitle</h2>
</body></html>
",
)
.set()
.await
.expect("Failed to set content");
let snapshot = page.aria_snapshot().await.expect("Failed to get snapshot");
let yaml = snapshot.to_yaml();
println!("Snapshot with heading refs:\n{yaml}");
assert!(
yaml.contains("[ref=c") && yaml.contains('p') && yaml.contains('e'),
"Snapshot should contain refs for headings in format c{{ctx}}p{{page}}e{{counter}}, got: {yaml}"
);
browser.close().await.expect("Failed to close browser");
}