appium_client/commands/
authentication.rs

1//! Device authentication
2use async_trait::async_trait;
3use fantoccini::error::CmdError;
4use http::Method;
5use serde_json::json;
6use crate::{AndroidClient, AppiumClientTrait, IOSClient};
7use crate::commands::AppiumCommand;
8
9/// Finger authentication (Android authentication)
10#[async_trait]
11pub trait AuthenticatesByFinger : AppiumClientTrait {
12    async fn use_finger_print(&self, id: u8) -> Result<(), CmdError> {
13        self.issue_cmd(AppiumCommand::Custom(
14            Method::POST,
15            "appium/device/finger_print".to_string(),
16            Some(json!({
17                "fingerprintId": id
18            }))
19        )).await?;
20        
21        Ok(())
22    }
23}
24
25#[async_trait]
26impl AuthenticatesByFinger for AndroidClient {}
27
28/// TouchID (iPhone authentication)
29#[async_trait]
30pub trait PerformsTouchID : AppiumClientTrait {
31    /// Simulate touchId event.
32    async fn perform_touch_id(&self, successful_scan: bool) -> Result<(), CmdError> {
33        self.issue_cmd(AppiumCommand::Custom(
34            Method::POST,
35            "appium/simulator/touch_id".to_string(),
36            Some(json!({
37                "match": successful_scan
38            })),
39        )).await?;
40        Ok(())
41    }
42
43    /// Enrolls touchId in iOS Simulators. This call will only work if Appium process
44    /// or its parent application (e.g. Terminal.app or Appium.app) has access to Mac OS accessibility
45    /// in System Preferences > Security & Privacy > Privacy > Accessibility list.
46    async fn toggle_touch_id_enrollment(&self, enabled: bool) -> Result<(), CmdError> {
47        self.issue_cmd(AppiumCommand::Custom(
48            Method::POST,
49            "appium/simulator/toggle_touch_id_enrollment".to_string(),
50            Some(json!({
51                "enabled": enabled
52            })),
53        )).await?;
54        Ok(())
55    }
56}
57
58#[async_trait]
59impl PerformsTouchID for IOSClient {}