Skip to main content

appium_client/commands/
settings.rs

1//! Settings API (<https://appium.io/docs/en/2.1/guides/settings/>)
2use std::collections::HashMap;
3use async_trait::async_trait;
4use fantoccini::error::CmdError;
5use http::Method;
6use serde_json::{json, Map, Value};
7use crate::{AndroidClient, AppiumClientTrait, IOSClient};
8use crate::commands::AppiumCommand;
9
10/// Set or get setting from Settings API (<https://appium.io/docs/en/2.1/guides/settings/>)
11#[async_trait]
12pub trait HasSettings : AppiumClientTrait {
13    async fn set_settings(&self, values: Map<String, Value>) -> Result<(), CmdError> {
14        let value = Value::Object(values);
15        self.issue_cmd(AppiumCommand::Custom(
16            Method::POST,
17            "appium/settings".to_string(),
18            Some(json!({
19                "settings": value
20            }))
21        )).await?;
22
23        Ok(())
24    }
25
26    async fn set_setting(&self, name: &str, value: Value) -> Result<(), CmdError> {
27        let mut map = Map::new();
28        map.insert(name.to_string(), value);
29
30        self.set_settings(map).await
31    }
32
33    async fn get_settings(&self) -> Result<HashMap<String, Value>, CmdError> {
34        let value = self.issue_cmd(AppiumCommand::Custom(
35            Method::GET,
36            "appium/settings".to_string(),
37            None
38        )).await?;
39
40        Ok(serde_json::from_value(value)?)
41    }
42}
43
44#[async_trait]
45impl HasSettings for AndroidClient {}
46
47#[async_trait]
48impl HasSettings for IOSClient {}