Skip to content

Commit 23d1ec3

Browse files
committed
Add getAppStrings method to allow searching app strings in the specified file
1 parent 8425992 commit 23d1ec3

4 files changed

Lines changed: 54 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ If you are using the Eclipse IDE, make sure you are using version Luna or later.
110110
##Changelog##
111111
*4.0.0 (still not released)*
112112
- `getAppStrings()` methods now return a map with the app strings keys and values, instead of an string
113+
- Add `getAppStrings(String language, String stringFile)` method to allow searching app strings in the specified file
113114

114115
*3.3.0*
115116
- updated the dependency on Selenium to version 2.48.2

src/main/java/io/appium/java_client/AppiumDriver.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public abstract class AppiumDriver<RequiredElementType extends WebElement> exten
6666
private final String SETTINGS = "settings";
6767

6868
private final String LANGUAGE_PARAM = "language";
69+
private final String STRING_FILE_PARAM = "stringFile";
6970

7071
/**
7172
* @param originalCapabilities
@@ -627,6 +628,24 @@ public Map<String, String> getAppStrings(String language) {
627628
return (Map<String, String>) response.getValue();
628629
}
629630

631+
/**
632+
* @param language
633+
* strings language code
634+
* @param stringFile
635+
* strings filename
636+
* @return a map with localized strings defined in the app
637+
*
638+
* @see HasAppStrings#getAppStrings(String, String)
639+
*/
640+
@Override
641+
public Map<String, String> getAppStrings(String language, String stringFile) {
642+
String[] parameters = new String[] { LANGUAGE_PARAM, STRING_FILE_PARAM };
643+
Object[] values = new Object[] { language, stringFile };
644+
Response response = execute(GET_STRINGS,
645+
getCommandImmutableMap(parameters, values));
646+
return (Map<String, String>) response.getValue();
647+
}
648+
630649
private TouchAction createTap(WebElement element, int duration) {
631650
TouchAction tap = new TouchAction(this);
632651
return tap.press(element).waitAction(duration).release();

src/main/java/io/appium/java_client/HasAppStrings.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,31 @@
2121
public interface HasAppStrings {
2222

2323
/**
24-
* Get all defined Strings from an app for the default language
25-
*
26-
* @return a map with localized strings defined in the app
27-
*/
24+
* Get all defined Strings from an app for the default language
25+
*
26+
* @return a map with localized strings defined in the app
27+
*/
2828
Map<String, String> getAppStrings();
2929

3030
/**
31-
* Get all defined Strings from an app for the specified language
32-
*
33-
* @param language strings language code
34-
* @return a map with localized strings defined in the app
35-
*/
31+
* Get all defined Strings from an app for the specified language
32+
*
33+
* @param language
34+
* strings language code
35+
* @return a map with localized strings defined in the app
36+
*/
3637
Map<String, String> getAppStrings(String language);
3738

39+
/**
40+
* Get all defined Strings from an app for the specified language and
41+
* strings filename
42+
*
43+
* @param language
44+
* strings language code
45+
* @param stringFile
46+
* strings filename
47+
* @return a map with localized strings defined in the app
48+
*/
49+
Map<String, String> getAppStrings(String language, String stringFile);
50+
3851
}

src/test/java/io/appium/java_client/ios/IOSDriverTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ public void getStringsWithLanguageTest() {
8181
assertTrue(strings.size() > 10);
8282
}
8383

84+
@Test
85+
public void getStringsWithLanguageAndStringFileTest() {
86+
Map<String, String> strings = driver.getAppStrings("en", "Localizable.strings");
87+
assertTrue(strings.size() > 10);
88+
}
89+
90+
@Test
91+
public void getStringsWithUnknownStringFileTest() {
92+
Map<String, String> strings = driver.getAppStrings("en", "Unknown.strings");
93+
assertTrue(strings.size() > 10);
94+
}
95+
8496
@Test
8597
public void resetTest() {
8698
driver.resetApp();

0 commit comments

Comments
 (0)