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
//! App strings (localized text from app)
use std::collections::HashMap;
use async_trait::async_trait;
use fantoccini::error::CmdError;
use http::Method;
use serde_json::json;
use crate::{AndroidClient, AppiumClientTrait, IOSClient};
use crate::commands::AppiumCommand;

/// Retrieve localized app strings (text used in app)
#[async_trait]
pub trait HasAppStrings : AppiumClientTrait {
    async fn app_strings_default_lang(&self) -> Result<HashMap<String, String>, CmdError> {
        let value = self.issue_cmd(AppiumCommand::Custom(
            Method::POST,
            "appium/app/strings".to_string(),
            None
        )).await?;

        Ok(serde_json::from_value(value)?)
    }

    async fn app_strings(&self, lang: &str) -> Result<HashMap<String, String>, CmdError> {
        let value = self.issue_cmd(AppiumCommand::Custom(
            Method::POST,
            "appium/app/strings".to_string(),
            Some(json!({
                "language": lang
            }))
        )).await?;

        Ok(serde_json::from_value(value)?)
    }

    async fn app_strings_from_file(&self, lang: &str, file: &str) -> Result<HashMap<String, String>, CmdError> {
        let value = self.issue_cmd(AppiumCommand::Custom(
            Method::POST,
            "appium/app/strings".to_string(),
            Some(json!({
                "language": lang,
                "stringFile": file
            }))
        )).await?;

        Ok(serde_json::from_value(value)?)
    }
}

#[async_trait]
impl HasAppStrings for AndroidClient {}

#[async_trait]
impl HasAppStrings for IOSClient {}