Function goose_eggs::validate_page

source ·
pub async fn validate_page<'a>(
    user: &mut GooseUser,
    goose: GooseResponse,
    validate: &'a Validate<'a>
) -> Result<String, Box<TransactionError>>
Expand description

Validate the HTML response 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.

This function is invoked by validate_and_load_static_assets, which then also invokes load_static_elements to better simulate a web browser loading a page.

Example

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

transaction!(load_page).set_on_start();

async fn load_page(user: &mut GooseUser) -> TransactionResult {
    let mut goose = user.get("/").await?;
    validate_page(
        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(())
}