use crate::test_server::TestServer;
use playwright_rs::expect_page;
#[tokio::test]
async fn test_page_assertion_matches() -> Result<(), Box<dyn std::error::Error>> {
let server = TestServer::start().await;
let (_pw, browser, page) = crate::common::setup().await;
let url = server.url();
page.goto(&url, None).await?;
expect_page(&page).to_have_title("Test Index").await?;
expect_page(&page)
.not()
.to_have_title("Wrong Title")
.await?;
expect_page(&page).to_have_title_regex("Test.*").await?;
expect_page(&page).to_have_url(&format!("{}/", url)).await?;
expect_page(&page)
.to_have_url_regex("http://127\\.0\\.0\\.1:\\d+/")
.await?;
browser.close().await?;
server.shutdown();
Ok(())
}
#[tokio::test]
async fn test_page_assertion_mismatches() -> Result<(), Box<dyn std::error::Error>> {
let server = TestServer::start().await;
let (_pw, browser, page) = crate::common::setup().await;
page.goto(&server.url(), None).await?;
let result = expect_page(&page)
.with_timeout(std::time::Duration::from_millis(500))
.to_have_title("Wrong Title")
.await;
assert!(result.is_err(), "Should fail when title doesn't match");
let result = expect_page(&page)
.with_timeout(std::time::Duration::from_millis(500))
.to_have_url("https://wrong.example.com")
.await;
assert!(result.is_err(), "Should fail when URL doesn't match");
browser.close().await?;
server.shutdown();
Ok(())
}