webdriverbidi 0.2.2

WebDriver BiDi client implementation in Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
use crate::model::browsing_context::BrowsingContext;
use crate::model::common::{JsInt, JsUint};
use crate::model::script::SharedReference;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum InputCommand {
    PerformActions(PerformActions),
    ReleaseActions(ReleaseActions),
    SetFiles(SetFiles),
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum InputEvent {
    FileDialogOpened(FileDialogOpened),
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ElementOrigin {
    #[serde(rename = "type")]
    pub element_origin_type: String,
    pub element: SharedReference,
}

impl ElementOrigin {
    pub fn new(element: SharedReference) -> Self {
        Self {
            element_origin_type: "element".to_string(),
            element,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PerformActions {
    pub method: String,
    pub params: PerformActionsParameters,
}

impl PerformActions {
    pub fn new(params: PerformActionsParameters) -> Self {
        Self {
            method: "input.performActions".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PerformActionsParameters {
    pub context: BrowsingContext,
    pub actions: Vec<SourceActions>,
}

impl PerformActionsParameters {
    pub fn new(context: BrowsingContext, actions: Vec<SourceActions>) -> Self {
        Self { context, actions }
    }
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SourceActions {
    NoneSourceActions(NoneSourceActions),
    KeySourceActions(KeySourceActions),
    PointerSourceActions(PointerSourceActions),
    WheelSourceActions(WheelSourceActions),
}

#[derive(Debug, Serialize, Deserialize)]
pub struct NoneSourceActions {
    #[serde(rename = "type")]
    pub none_source_actions_type: String,
    pub id: String,
    pub actions: Vec<NoneSourceAction>,
}

impl NoneSourceActions {
    pub fn new(id: String, actions: Vec<NoneSourceAction>) -> Self {
        Self {
            none_source_actions_type: "none".to_string(),
            id,
            actions,
        }
    }
}

pub type NoneSourceAction = PauseAction;

#[derive(Debug, Serialize, Deserialize)]
pub struct KeySourceActions {
    #[serde(rename = "type")]
    pub key_source_actions_type: String,
    pub id: String,
    pub actions: Vec<KeySourceAction>,
}

impl KeySourceActions {
    pub fn new(id: String, actions: Vec<KeySourceAction>) -> Self {
        Self {
            key_source_actions_type: "key".to_string(),
            id,
            actions,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum KeySourceAction {
    PauseAction(PauseAction),
    KeyDownAction(KeyDownAction),
    KeyUpAction(KeyUpAction),
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PointerSourceActions {
    #[serde(rename = "type")]
    pub pointer_source_actions_type: String,
    pub id: String,
    pub parameters: Option<PointerParameters>,
    pub actions: Vec<PointerSourceAction>,
}

impl PointerSourceActions {
    pub fn new(
        id: String,
        parameters: Option<PointerParameters>,
        actions: Vec<PointerSourceAction>,
    ) -> Self {
        Self {
            pointer_source_actions_type: "pointer".to_string(),
            id,
            parameters,
            actions,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum PointerType {
    Mouse,
    Pen,
    Touch,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PointerParameters {
    #[serde(rename = "pointerType", skip_serializing_if = "Option::is_none")]
    pub pointer_type: Option<PointerType>,
}

impl PointerParameters {
    pub fn new(pointer_type: Option<PointerType>) -> Self {
        Self { pointer_type }
    }
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PointerSourceAction {
    PauseAction(PauseAction),
    PointerDownAction(PointerDownAction),
    PointerUpAction(PointerUpAction),
    PointerMoveAction(PointerMoveAction),
}

#[derive(Debug, Serialize, Deserialize)]
pub struct WheelSourceActions {
    #[serde(rename = "type")]
    pub wheel_source_actions_type: String,
    pub id: String,
    pub actions: Vec<WheelSourceAction>,
}

impl WheelSourceActions {
    pub fn new(id: String, actions: Vec<WheelSourceAction>) -> Self {
        Self {
            wheel_source_actions_type: "wheel".to_string(),
            id,
            actions,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WheelSourceAction {
    PauseAction(PauseAction),
    WheelScrollAction(WheelScrollAction),
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PauseAction {
    #[serde(rename = "type")]
    pub pause_action_type: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub duration: Option<JsUint>,
}

impl PauseAction {
    pub fn new(duration: Option<JsUint>) -> Self {
        Self {
            pause_action_type: "pause".to_string(),
            duration,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct KeyDownAction {
    #[serde(rename = "type")]
    pub key_down_action_type: String,
    pub value: String,
}

impl KeyDownAction {
    pub fn new(value: String) -> Self {
        Self {
            key_down_action_type: "keyDown".to_string(),
            value,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct KeyUpAction {
    #[serde(rename = "type")]
    pub key_up_action_type: String,
    pub value: String,
}

impl KeyUpAction {
    pub fn new(value: String) -> Self {
        Self {
            key_up_action_type: "keyUp".to_string(),
            value,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PointerUpAction {
    #[serde(rename = "type")]
    pub pointer_up_action_type: String,
    pub button: JsUint,
}

impl PointerUpAction {
    pub fn new(button: JsUint) -> Self {
        Self {
            pointer_up_action_type: "pointerUp".to_string(),
            button,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PointerDownAction {
    #[serde(rename = "type")]
    pub pointer_down_action_type: String,
    pub button: JsUint,
    #[serde(flatten)]
    pub pointer_common_properties: PointerCommonProperties,
}

impl PointerDownAction {
    pub fn new(button: JsUint, pointer_common_properties: PointerCommonProperties) -> Self {
        Self {
            pointer_down_action_type: "pointerDown".to_string(),
            button,
            pointer_common_properties,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PointerMoveAction {
    #[serde(rename = "type")]
    pub pointer_move_action_type: String,
    pub x: f64,
    pub y: f64,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub duration: Option<JsUint>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub origin: Option<Origin>,
    #[serde(flatten)]
    pub pointer_common_properties: PointerCommonProperties,
}

impl PointerMoveAction {
    pub fn new(
        x: f64,
        y: f64,
        duration: Option<JsUint>,
        origin: Option<Origin>,
        pointer_common_properties: PointerCommonProperties,
    ) -> Self {
        Self {
            pointer_move_action_type: "pointerMove".to_string(),
            x,
            y,
            duration,
            origin,
            pointer_common_properties,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct WheelScrollAction {
    #[serde(rename = "type")]
    pub wheel_scroll_action_type: String,
    pub x: JsInt,
    pub y: JsInt,
    #[serde(rename = "deltaX")]
    pub delta_x: JsInt,
    #[serde(rename = "deltaY")]
    pub delta_y: JsInt,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub duration: Option<JsUint>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub origin: Option<Origin>,
}

impl WheelScrollAction {
    pub fn new(
        x: JsInt,
        y: JsInt,
        delta_x: JsInt,
        delta_y: JsInt,
        duration: Option<JsUint>,
        origin: Option<Origin>,
    ) -> Self {
        Self {
            wheel_scroll_action_type: "scroll".to_string(),
            x,
            y,
            delta_x,
            delta_y,
            duration,
            origin,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PointerCommonProperties {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub width: Option<JsUint>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub height: Option<JsUint>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pressure: Option<f64>,
    #[serde(rename = "tangentialPressure", skip_serializing_if = "Option::is_none")]
    pub tangential_pressure: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub twist: Option<JsUint>,
    #[serde(rename = "altitudeAngle", skip_serializing_if = "Option::is_none")]
    pub altitude_angle: Option<f64>,
    #[serde(rename = "azimuthAngle", skip_serializing_if = "Option::is_none")]
    pub azimuth_angle: Option<f64>,
}

impl PointerCommonProperties {
    pub fn new(
        width: Option<JsUint>,
        height: Option<JsUint>,
        pressure: Option<f64>,
        tangential_pressure: Option<f64>,
        twist: Option<JsUint>,
        altitude_angle: Option<f64>,
        azimuth_angle: Option<f64>,
    ) -> Self {
        Self {
            width,
            height,
            pressure,
            tangential_pressure,
            twist,
            altitude_angle,
            azimuth_angle,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Origin {
    Viewport(String),
    Pointer(String),
    ElementOrigin(ElementOrigin),
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ReleaseActions {
    pub method: String,
    pub params: ReleaseActionsParameters,
}

impl ReleaseActions {
    pub fn new(params: ReleaseActionsParameters) -> Self {
        Self {
            method: "input.releaseActions".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ReleaseActionsParameters {
    pub context: BrowsingContext,
}

impl ReleaseActionsParameters {
    pub fn new(context: BrowsingContext) -> Self {
        Self { context }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SetFiles {
    pub method: String,
    pub params: SetFilesParameters,
}

impl SetFiles {
    pub fn new(params: SetFilesParameters) -> Self {
        Self {
            method: "input.setFiles".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SetFilesParameters {
    pub context: BrowsingContext,
    pub element: SharedReference,
    pub files: Vec<String>,
}

impl SetFilesParameters {
    pub fn new(context: BrowsingContext, element: SharedReference, files: Vec<String>) -> Self {
        Self {
            context,
            element,
            files,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct FileDialogOpened {
    pub method: String,
    pub params: FileDialogInfo,
}

impl FileDialogOpened {
    pub fn new(params: FileDialogInfo) -> Self {
        Self {
            method: "input.fileDialogOpened".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct FileDialogInfo {
    context: BrowsingContext,
    #[serde(skip_serializing_if = "Option::is_none")]
    element: Option<SharedReference>,
    multiple: bool,
}