browser-commander 0.14.0

Universal browser automation library that supports multiple browser engines with a unified API
Documentation
// @generated by scripts/generate-playwright-protocol.mjs from
// rust/protocol/playwright/*.yml. Do not edit by hand.

#![allow(clippy::all, missing_docs, unused_imports)]

use serde::{Deserialize, Serialize};

use super::*;
use crate::playwright::connection::{
    Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
};

/// Initializer the driver sends when it creates a `Artifact`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ArtifactInitializer {
    #[serde(rename = "absolutePath")]
    pub absolute_path: String,
}

/// Result of `Artifact.pathAfterFinished`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ArtifactPathAfterFinishedResult {
    #[serde(rename = "value")]
    pub value: String,
}

/// Parameters of `Artifact.saveAs`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ArtifactSaveAsParams {
    #[serde(rename = "path")]
    pub path: String,
}

/// Result of `Artifact.saveAsStream`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ArtifactSaveAsStreamResult {
    #[serde(rename = "stream")]
    pub stream: Ref<Stream>,
}

/// Result of `Artifact.failure`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ArtifactFailureResult {
    #[serde(rename = "error", default, skip_serializing_if = "Option::is_none")]
    pub error: Option<String>,
}

/// Result of `Artifact.stream`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ArtifactStreamResult {
    #[serde(rename = "stream")]
    pub stream: Ref<Stream>,
}

/// Events a `Artifact` channel can emit.
#[derive(Debug, Clone, PartialEq)]
pub enum ArtifactEvent {
    /// An event this binding does not know (a newer driver).
    Unknown {
        /// Event name.
        method: String,
        /// Raw event parameters.
        params: serde_json::Value,
    },
}

impl ProtocolEvent for ArtifactEvent {
    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
        match method {
            _ => Ok(Self::Unknown { method: method.to_string(), params }),
        }
    }
}

/// Channel for the `Artifact` interface (`artifact.yml`).
#[derive(Debug, Clone)]
pub struct Artifact {
    channel: Channel,
}

impl ChannelType for Artifact {
    const INTERFACE: &'static str = "Artifact";
    type Initializer = ArtifactInitializer;
    type Event = ArtifactEvent;

    fn accepts(interface: &str) -> bool {
        matches!(interface, "Artifact")
    }

    fn from_channel(channel: Channel) -> Self {
        Self { channel }
    }

    fn channel(&self) -> &Channel {
        &self.channel
    }
}

impl Artifact {
    /// `Artifact.pathAfterFinished` (internal).
    pub async fn path_after_finished(&self) -> Result<ArtifactPathAfterFinishedResult, ProtocolError> {
        self.channel.send("pathAfterFinished", &serde_json::json!({})).await
    }

    /// `Artifact.saveAs` (internal).
    pub async fn save_as(&self, params: ArtifactSaveAsParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("saveAs", &params).await
    }

    /// `Artifact.saveAsStream` (internal).
    pub async fn save_as_stream(&self) -> Result<ArtifactSaveAsStreamResult, ProtocolError> {
        self.channel.send("saveAsStream", &serde_json::json!({})).await
    }

    /// `Artifact.failure` (internal).
    pub async fn failure(&self) -> Result<ArtifactFailureResult, ProtocolError> {
        self.channel.send("failure", &serde_json::json!({})).await
    }

    /// `Artifact.stream` (internal).
    pub async fn stream(&self) -> Result<ArtifactStreamResult, ProtocolError> {
        self.channel.send("stream", &serde_json::json!({})).await
    }

    /// `Artifact.cancel` (internal).
    pub async fn cancel(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("cancel", &serde_json::json!({})).await
    }

    /// `Artifact.delete` (internal).
    pub async fn delete(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("delete", &serde_json::json!({})).await
    }
}