browser-commander 0.18.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 `Android`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AndroidInitializer {}

/// Parameters of `Android.devices`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AndroidDevicesParams {
    #[serde(rename = "host", default, skip_serializing_if = "Option::is_none")]
    pub host: Option<String>,
    #[serde(rename = "port", default, skip_serializing_if = "Option::is_none")]
    pub port: Option<i64>,
    #[serde(rename = "omitDriverInstall", default, skip_serializing_if = "Option::is_none")]
    pub omit_driver_install: Option<bool>,
}

/// Result of `Android.devices`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AndroidDevicesResult {
    #[serde(rename = "devices")]
    pub devices: Vec<Ref<AndroidDevice>>,
}

/// Events a `Android` channel can emit.
#[derive(Debug, Clone, PartialEq)]
pub enum AndroidEvent {
    /// 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 AndroidEvent {
    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 `Android` interface (`android.yml`).
#[derive(Debug, Clone)]
pub struct Android {
    channel: Channel,
}

impl ChannelType for Android {
    const INTERFACE: &'static str = "Android";
    type Initializer = AndroidInitializer;
    type Event = AndroidEvent;

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

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

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

impl Android {
    /// `Android.devices` (internal).
    pub async fn devices(&self, params: AndroidDevicesParams) -> Result<AndroidDevicesResult, ProtocolError> {
        self.channel.send("devices", &params).await
    }
}