This version of the documentation is outdated, and features documented here may work differently now. You can see the latest stable version of the docs here.

Manual Testing

Occasionally, the Perseus testing harness may be a little too brittle for your needs, particularly if you'd like to pass custom arguments to the WebDriver (e.g. to spoof media streams). In these cases, you'll want to break out of it entirely and work with Fantoccini manually.

You should do this by wrapping your normal test function in another function and annotating that with [tokio::test], which will mark it as a normal asynchronous test. Then, you can mimic the behavior of the Perseus test harness almost exactly with the following code (adapted from the macro here):

// Only run the test if the environment variable is specified (avoids having to do exclusions for workspace `cargo test`)
if ::std::env::var("PERSEUS_RUN_WASM_TESTS").is_ok() {
    let headless = ::std::env::var("PERSEUS_RUN_WASM_TESTS_HEADLESS").is_ok();
    // Set the capabilities of the client
    let mut capabilities = ::serde_json::Map::new();
    let firefox_opts;
    let chrome_opts;
    if headless {
        firefox_opts = ::serde_json::json!({ "args": ["--headless"] });
        chrome_opts = ::serde_json::json!({ "args": ["--headless"] });
    } else {
        firefox_opts = ::serde_json::json!({ "args": [] });
        chrome_opts = ::serde_json::json!({ "args": [] });
    }
    capabilities.insert("moz:firefoxOptions".to_string(), firefox_opts);
    capabilities.insert("goog:chromeOptions".to_string(), chrome_opts);

    let mut client = ::fantoccini::ClientBuilder::native()
        .capabilities(capabilities)
        .connect(&"http://localhost:4444").await.expect("failed to connect to WebDriver");
    let output = fn_internal(&mut client).await;
    // Close the client no matter what
    client.close().await.expect("failed to close Fantoccini client");
    // Panic if the test failed
    if let Err(err) = output {
        panic!("test failed: '{}'", err.to_string())
    }
}

Then, you can relatively easily modify the properties sent to the WebDriver instance with firefox_opts and chrome_opts. You can see the documentation for their options here (Firefox) and here (Chrome/Chromium).