Function goose_eggs::validate_and_load_static_assets
source · pub async fn validate_and_load_static_assets<'a>(
user: &mut GooseUser,
goose: GooseResponse,
validate: &'a Validate<'a>
) -> Result<String, Box<TransactionError>>
Expand description
Validate the HTML response, extract and load all static elements on the page, and return the HTML body.
What is validated is defined with the Validate
structure.
If the page doesn’t load, an empty String
will be returned. If the page does load
but validation fails, an Error is returned. If the page loads and there are no
errors the body is returned as a String
.
To only validate the page without also loading static elements, use instead validate_page.
Example
use goose::prelude::*;
use goose_eggs::{validate_and_load_static_assets, Validate};
transaction!(load_page).set_on_start();
async fn load_page(user: &mut GooseUser) -> TransactionResult {
let mut goose = user.get("/").await?;
validate_and_load_static_assets(
user,
goose,
// Validate title and other arbitrary text on the response html.
&Validate::builder()
.title("my page")
.texts(vec!["foo", r#"<a href="bar">"#])
.build(),
).await?;
Ok(())
}