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
//! Android capabilities
//!
//! By using [AndroidCapabilities] you can create a client with features specific to Android testing.
//! For example, a client created from [AndroidCapabilities] can be used to check current activity.
//!
//! ```no_run
//! use appium_client::capabilities::android::AndroidCapabilities;
//! use appium_client::capabilities::{AppCapable, UdidCapable, UiAutomator2AppCompatible};
//! use appium_client::ClientBuilder;
//! use appium_client::commands::android::StartsActivity;
//!
//!# #[tokio::main]
//!# async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut capabilities = AndroidCapabilities::new_uiautomator();
//! capabilities.udid("emulator-5554");
//! capabilities.app("/apps/sample.apk");
//! capabilities.app_wait_activity("com.example.AppActivity");
//!
//! let client = ClientBuilder::native(capabilities)
//! .connect("http://localhost:4723/wd/hub/")
//! .await?;
//!
//! // print current Android activity (not available on other platforms)
//! println!("{}", client.current_activity().await?);
//!# Ok(())
//!# }
//! ```
use std::ops::{Deref, DerefMut};
use fantoccini::wd::Capabilities;
use serde_json::Value;
use crate::capabilities::{AppCapable, AppiumCapability, AppiumSettingsCapable, UdidCapable, UiAutomator2AppCompatible};
use crate::capabilities::automation::{ANDROID_UIAUTOMATOR2, ESPRESSO};
/// Android capabilities
#[derive(Clone, Eq, PartialEq, Debug)]
pub struct AndroidCapabilities {
inner: Capabilities,
}
impl AndroidCapabilities {
/// Creates new empty capability set for Android (with driver autoselected by Appium).
pub fn new() -> AndroidCapabilities {
let mut inner = Capabilities::new();
inner.insert("platformName".to_string(), Value::String("android".to_string()));
AndroidCapabilities {
inner
}
}
/// Creates empty capability set for UiAutomator2 Android driver.
pub fn new_uiautomator() -> AndroidCapabilities {
let mut capabilities = AndroidCapabilities::new();
capabilities.automation_name(ANDROID_UIAUTOMATOR2);
capabilities
}
/// Creates empty capability set for Espresso Android driver.
pub fn new_espresso() -> AndroidCapabilities {
let mut capabilities = AndroidCapabilities::new();
capabilities.automation_name(ESPRESSO);
capabilities
}
}
impl Default for AndroidCapabilities {
fn default() -> Self {
Self::new()
}
}
impl From<AndroidCapabilities> for Capabilities {
fn from(value: AndroidCapabilities) -> Self {
value.inner
}
}
impl Deref for AndroidCapabilities {
type Target = Capabilities;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl DerefMut for AndroidCapabilities {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AppiumCapability for AndroidCapabilities {}
impl UdidCapable for AndroidCapabilities {}
impl AppCapable for AndroidCapabilities {}
impl AppiumSettingsCapable for AndroidCapabilities {}
impl UiAutomator2AppCompatible for AndroidCapabilities {}