browser_commander/playwright/protocol/
artifact.rs1#![allow(clippy::all, missing_docs, unused_imports)]
5
6use serde::{Deserialize, Serialize};
7
8use super::*;
9use crate::playwright::connection::{
10 Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
11};
12
13#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct ArtifactInitializer {
16 #[serde(rename = "absolutePath")]
17 pub absolute_path: String,
18}
19
20#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
22pub struct ArtifactPathAfterFinishedResult {
23 #[serde(rename = "value")]
24 pub value: String,
25}
26
27#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
29pub struct ArtifactSaveAsParams {
30 #[serde(rename = "path")]
31 pub path: String,
32}
33
34#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
36pub struct ArtifactSaveAsStreamResult {
37 #[serde(rename = "stream")]
38 pub stream: Ref<Stream>,
39}
40
41#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
43pub struct ArtifactFailureResult {
44 #[serde(rename = "error", default, skip_serializing_if = "Option::is_none")]
45 pub error: Option<String>,
46}
47
48#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
50pub struct ArtifactStreamResult {
51 #[serde(rename = "stream")]
52 pub stream: Ref<Stream>,
53}
54
55#[derive(Debug, Clone, PartialEq)]
57pub enum ArtifactEvent {
58 Unknown {
60 method: String,
62 params: serde_json::Value,
64 },
65}
66
67impl ProtocolEvent for ArtifactEvent {
68 fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
69 match method {
70 _ => Ok(Self::Unknown { method: method.to_string(), params }),
71 }
72 }
73}
74
75#[derive(Debug, Clone)]
77pub struct Artifact {
78 channel: Channel,
79}
80
81impl ChannelType for Artifact {
82 const INTERFACE: &'static str = "Artifact";
83 type Initializer = ArtifactInitializer;
84 type Event = ArtifactEvent;
85
86 fn accepts(interface: &str) -> bool {
87 matches!(interface, "Artifact")
88 }
89
90 fn from_channel(channel: Channel) -> Self {
91 Self { channel }
92 }
93
94 fn channel(&self) -> &Channel {
95 &self.channel
96 }
97}
98
99impl Artifact {
100 pub async fn path_after_finished(&self) -> Result<ArtifactPathAfterFinishedResult, ProtocolError> {
102 self.channel.send("pathAfterFinished", &serde_json::json!({})).await
103 }
104
105 pub async fn save_as(&self, params: ArtifactSaveAsParams) -> Result<(), ProtocolError> {
107 self.channel.send_no_result("saveAs", ¶ms).await
108 }
109
110 pub async fn save_as_stream(&self) -> Result<ArtifactSaveAsStreamResult, ProtocolError> {
112 self.channel.send("saveAsStream", &serde_json::json!({})).await
113 }
114
115 pub async fn failure(&self) -> Result<ArtifactFailureResult, ProtocolError> {
117 self.channel.send("failure", &serde_json::json!({})).await
118 }
119
120 pub async fn stream(&self) -> Result<ArtifactStreamResult, ProtocolError> {
122 self.channel.send("stream", &serde_json::json!({})).await
123 }
124
125 pub async fn cancel(&self) -> Result<(), ProtocolError> {
127 self.channel.send_no_result("cancel", &serde_json::json!({})).await
128 }
129
130 pub async fn delete(&self) -> Result<(), ProtocolError> {
132 self.channel.send_no_result("delete", &serde_json::json!({})).await
133 }
134}