appium_client/capabilities/
empty.rs

1//! Empty capabilities (for creating a blank client)
2//!
3//! A blank client is an appium client that is not tied to any specific driver (or a driver not supported by this lib).
4//! You can use [EmptyCapabilities] to manually set any capability and create a featureless Appium client.
5//!
6//! Such featureless Appium client has a basic feature of [crate::find], but any other feature has to be implemented by using [crate::commands::AppiumCommand::Custom].
7//!
8//! You can use a featureless client to use any Appium driver not currently supported by this lib (other than Android and iOS).
9//! Upside: you can use this lib.
10//! Downside: no features (yet).
11//!
12//! ```no_run
13//! use http::Method;
14//! use serde_json::json;
15//! use appium_client::capabilities::AppiumCapability;
16//! use appium_client::capabilities::automation::ANDROID_UIAUTOMATOR2;
17//! use appium_client::capabilities::empty::EmptyCapabilities;
18//! use appium_client::ClientBuilder;
19//! use appium_client::commands::AppiumCommand;
20//! use appium_client::find::{AppiumFind, By};
21//!
22//!# #[tokio::main]
23//!# async fn main() -> Result<(), Box<dyn std::error::Error>> {
24//! let mut capabilities = EmptyCapabilities::new();
25//! capabilities.automation_name(ANDROID_UIAUTOMATOR2);
26//!
27//! let client = ClientBuilder::native(capabilities)
28//!    .connect("http://localhost:4723/wd/hub/")
29//!    .await?;
30//!
31//! // find works out of the box
32//! let element = client.find_by(By::Id("elementId".to_string())).await?;
33//!
34//! // any other feature must be implemented by issuing a custom command
35//! // for example, this is a command used to set geolocation on Android
36//! client.issue_cmd(AppiumCommand::Custom(
37//!     Method::POST,
38//!     "location".to_string(),
39//!     Some(json!({
40//!         "location": {
41//!             "latitude": 121.21,
42//!             "longitude": 11.56,
43//!             "altitude": 94.23
44//!         }
45//!     }))
46//! )).await?;
47//!# Ok(())
48//!# }
49//! ```
50
51use std::ops::{Deref, DerefMut};
52use fantoccini::wd::Capabilities;
53use crate::capabilities::AppiumCapability;
54
55/// Empty capabilities - for use in tests or with a platform not implemented by this lib.
56#[derive(Clone, Eq, PartialEq, Debug)]
57pub struct EmptyCapabilities {
58    inner: Capabilities,
59}
60
61impl EmptyCapabilities {
62    /// Creates new empty capability set
63    pub fn new() -> EmptyCapabilities {
64        EmptyCapabilities {
65            inner: Capabilities::new()
66        }
67    }
68}
69
70impl Default for EmptyCapabilities {
71    fn default() -> Self {
72        Self::new()
73    }
74}
75
76impl From<EmptyCapabilities> for Capabilities {
77    fn from(value: EmptyCapabilities) -> Self {
78        value.inner
79    }
80}
81
82impl Deref for EmptyCapabilities {
83    type Target = Capabilities;
84
85    fn deref(&self) -> &Self::Target {
86        &self.inner
87    }
88}
89
90impl DerefMut for EmptyCapabilities {
91    fn deref_mut(&mut self) -> &mut Self::Target {
92        &mut self.inner
93    }
94}
95
96impl AppiumCapability for EmptyCapabilities {}