Function goose_eggs::validate_and_load_static_assets[][src]

pub async fn validate_and_load_static_assets<'a>(
    user: &mut GooseUser,
    goose: GooseResponse,
    validate: &'a Validate<'a>
) -> Result<String, GooseTaskError>
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.

Example

use goose::prelude::*;
use goose_eggs::{validate_and_load_static_assets, Validate};

task!(load_page).set_on_start();

async fn load_page(user: &mut GooseUser) -> GooseTaskResult {
    let mut goose = user.get("/").await?;
    validate_and_load_static_assets(
        user,
        goose,
        // Validate title and other arbitrary text on the response html.
        &Validate::title_texts("my page", vec!["foo", r#"<a href="bar">"#]),
    ).await?;

    Ok(())
}