#![cfg(feature = "integration")]
mod common;
use std::collections::HashMap;
use std::time::Duration;
use viewpoint_core::Permission;
#[tokio::test]
async fn test_context_offline_mode() {
common::init_tracing();
let browser = common::launch_browser().await;
let context = browser
.new_context()
.await
.expect("Failed to create context");
let _page = context.new_page().await.expect("Failed to create page");
context
.set_offline(true)
.await
.expect("Failed to go offline");
context
.set_offline(false)
.await
.expect("Failed to go online");
browser.close().await.expect("Failed to close browser");
}
#[tokio::test]
async fn test_context_extra_http_headers() {
common::init_tracing();
let browser = common::launch_browser().await;
let context = browser
.new_context()
.await
.expect("Failed to create context");
let _page = context.new_page().await.expect("Failed to create page");
let mut headers = HashMap::new();
headers.insert("X-Custom-Header".to_string(), "test-value".to_string());
headers.insert("Authorization".to_string(), "Bearer token123".to_string());
context
.set_extra_http_headers(headers)
.await
.expect("Failed to set extra headers");
browser.close().await.expect("Failed to close browser");
}
#[tokio::test]
async fn test_context_timeout_configuration() {
common::init_tracing();
let browser = common::launch_browser().await;
let mut context = browser
.new_context()
.await
.expect("Failed to create context");
let default = context.default_timeout();
assert_eq!(default, Duration::from_secs(30));
context.set_default_timeout(Duration::from_secs(60));
context.set_default_navigation_timeout(Duration::from_secs(120));
assert_eq!(context.default_timeout(), Duration::from_secs(60));
assert_eq!(
context.default_navigation_timeout(),
Duration::from_secs(120)
);
browser.close().await.expect("Failed to close browser");
}
#[tokio::test]
async fn test_context_with_options() {
common::init_tracing();
let browser = common::launch_browser().await;
let context = browser
.new_context_builder()
.geolocation(40.7128, -74.0060) .permissions(vec![Permission::Geolocation])
.has_touch(true)
.locale("en-US")
.timezone_id("America/New_York")
.default_timeout(Duration::from_secs(45))
.build()
.await
.expect("Failed to create context with options");
assert_eq!(context.default_timeout(), Duration::from_secs(45));
browser.close().await.expect("Failed to close browser");
}
#[tokio::test]
async fn test_custom_test_id_attribute() {
common::init_tracing();
let browser = common::launch_browser().await;
let context = browser
.new_context()
.await
.expect("Failed to create context");
context.set_test_id_attribute("data-test").await;
let attr = context.test_id_attribute().await;
assert_eq!(attr, "data-test");
browser.close().await.expect("Failed to close browser");
}
#[tokio::test]
async fn test_default_test_id_attribute() {
common::init_tracing();
let browser = common::launch_browser().await;
let context = browser
.new_context()
.await
.expect("Failed to create context");
let attr = context.test_id_attribute().await;
assert_eq!(attr, "data-testid");
browser.close().await.expect("Failed to close browser");
}
#[tokio::test]
async fn test_timezone_emulation() {
common::init_tracing();
let browser = common::launch_browser().await;
let _context = browser
.new_context_builder()
.timezone_id("Europe/London")
.build()
.await
.expect("Failed to create context with timezone");
browser.close().await.expect("Failed to close browser");
}
#[tokio::test]
async fn test_locale_emulation() {
common::init_tracing();
let browser = common::launch_browser().await;
let _context = browser
.new_context_builder()
.locale("fr-FR")
.build()
.await
.expect("Failed to create context with locale");
browser.close().await.expect("Failed to close browser");
}