Skip to content

Commit 8930aec

Browse files
appium#305 fix: initial commit.
Also - update to Selenium 2.50.0 - changes of HasAppStrings interface. The old 'getAppStrings()' was returbed with __Deprecated__ mark. New methods were renamed to 'getAppStringMap'
1 parent 340c9cb commit 8930aec

File tree

9 files changed

+84
-34
lines changed

9 files changed

+84
-34
lines changed

NOTICE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Copyright 2014-2015 Appium Contributors
1+
Copyright 2014-2016 Appium Contributors

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ More can be found in the docs, but here's a quick list of features which this pr
6060

6161
- startActivity()
6262
- resetApp()
63-
- getAppStrings()
63+
- getAppStringMap()
6464
- pressKeyCode()
6565
- longPressKeyCode()
6666
- longPressKey()
@@ -108,11 +108,14 @@ If you are working on this project and use Intellij Idea, you need to change the
108108
If you are using the Eclipse IDE, make sure you are using version Luna or later.
109109

110110
##Changelog##
111-
*4.0.0 (still not released)*
112-
- `getAppStrings()` methods now return a map with the app strings keys and values, instead of an string
111+
*3.4.0 (still not released)*
112+
- Update to Selenium v2.50.0
113+
- `getAppStrings()` is deprecated now. It is going to be removed. `getAppStringMap()` methods were added and now return a map with the app strings keys and values,
114+
instead of an string. Thanks to [@rgonalo](https://github.com/rgonalo) for the contribution.
113115
- Add `getAppStrings(String language, String stringFile)` method to allow searching app strings in the specified file
114116
- FIXED of the bug which causes deadlocks of AppiumDriver LocalService in multithreading. Thanks to [saikrishna321](https://github.com/saikrishna321) for the [bug report](https://github.com/appium/java-client/issues/283).
115-
- Fixed Zoom methods, thanks to @kkhaidukov
117+
- FIXED Zoom methods, thanks to [@kkhaidukov](https://github.com/kkhaidukov)
118+
- FIXED The issue of compatibility of AppiumServiceBuilder with Appium node server v >= 1.5.x. Take a look at [#305](https://github.com/appium/java-client/issues/305)
116119

117120
*3.3.0*
118121
- updated the dependency on Selenium to version 2.48.2

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<dependency>
3232
<groupId>org.seleniumhq.selenium</groupId>
3333
<artifactId>selenium-java</artifactId>
34-
<version>2.48.2</version>
34+
<version>2.50.0</version>
3535
</dependency>
3636
<dependency>
3737
<groupId>junit</groupId>

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -603,13 +603,23 @@ public void setLocation(Location location) {
603603
locationContext.setLocation(location);
604604
}
605605

606+
@Deprecated
607+
/**
608+
* This method is deprecated. It is going to be removed in the next release.
609+
* Be careful.
610+
*/
611+
public String getAppStrings() {
612+
Response response = execute(GET_STRINGS);
613+
return response.getValue().toString();
614+
}
615+
606616
/**
607617
* @return a map with localized strings defined in the app
608618
*
609-
* @see HasAppStrings#getAppStrings()
619+
* @see HasAppStrings#getAppStringMap()
610620
*/
611621
@Override
612-
public Map<String, String> getAppStrings() {
622+
public Map<String, String> getAppStringMap() {
613623
Response response = execute(GET_STRINGS);
614624
return (Map<String, String>) response.getValue();
615625
}
@@ -619,10 +629,10 @@ public Map<String, String> getAppStrings() {
619629
* strings language code
620630
* @return a map with localized strings defined in the app
621631
*
622-
* @see HasAppStrings#getAppStrings(String)
632+
* @see HasAppStrings#getAppStringMap(String)
623633
*/
624634
@Override
625-
public Map<String, String> getAppStrings(String language) {
635+
public Map<String, String> getAppStringMap(String language) {
626636
Response response = execute(GET_STRINGS,
627637
getCommandImmutableMap(LANGUAGE_PARAM, language));
628638
return (Map<String, String>) response.getValue();
@@ -635,10 +645,10 @@ public Map<String, String> getAppStrings(String language) {
635645
* strings filename
636646
* @return a map with localized strings defined in the app
637647
*
638-
* @see HasAppStrings#getAppStrings(String, String)
648+
* @see HasAppStrings#getAppStringMap(String, String)
639649
*/
640650
@Override
641-
public Map<String, String> getAppStrings(String language, String stringFile) {
651+
public Map<String, String> getAppStringMap(String language, String stringFile) {
642652
String[] parameters = new String[] { LANGUAGE_PARAM, STRING_FILE_PARAM };
643653
Object[] values = new Object[] { language, stringFile };
644654
Response response = execute(GET_STRINGS,

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@
2020

2121
public interface HasAppStrings {
2222

23+
@Deprecated
24+
/**
25+
* This method is deprecated. It is going to be removed in the next release.
26+
* Be careful.
27+
*/
28+
public String getAppStrings();
29+
2330
/**
2431
* Get all defined Strings from an app for the default language
2532
*
2633
* @return a map with localized strings defined in the app
2734
*/
28-
Map<String, String> getAppStrings();
35+
Map<String, String> getAppStringMap();
2936

3037
/**
3138
* Get all defined Strings from an app for the specified language
@@ -34,7 +41,7 @@ public interface HasAppStrings {
3441
* strings language code
3542
* @return a map with localized strings defined in the app
3643
*/
37-
Map<String, String> getAppStrings(String language);
44+
Map<String, String> getAppStringMap(String language);
3845

3946
/**
4047
* Get all defined Strings from an app for the specified language and
@@ -46,6 +53,6 @@ public interface HasAppStrings {
4653
* strings filename
4754
* @return a map with localized strings defined in the app
4855
*/
49-
Map<String, String> getAppStrings(String language, String stringFile);
56+
Map<String, String> getAppStringMap(String language, String stringFile);
5057

5158
}

src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,36 @@
3636

3737
public final class AppiumServiceBuilder extends DriverService.Builder<AppiumDriverLocalService, AppiumServiceBuilder> {
3838

39+
/**
40+
* The property of environmental variable used to define
41+
* the path to executable appium.js (node server v<=1.4.x) or
42+
* main.js (node server v>=1.5.x)
43+
*/
3944
public static final String APPIUM_PATH = "APPIUM_BINARY_PATH";
45+
46+
/**
47+
* The property of environmental variable used to define
48+
* the path to executable NodeJS file (node.exe for WIN and
49+
* node for Linux/MacOS X)
50+
*/
4051
public static final String NODE_PATH = "NODE_BINARY_PATH";
4152

4253
private static final String APPIUM_FOLDER = "appium";
54+
4355
private static final String BIN_FOLDER = "bin";
56+
private static final String BUILD_FOLDER = "build";
57+
private static final String LIB_FOLDER = "lib";
58+
4459
private static final String APPIUM_JS = "appium.js";
45-
private static final String APPIUM_NODE_MASK = File.separator +
46-
APPIUM_FOLDER + File.separator + BIN_FOLDER + File.separator + APPIUM_JS;
60+
private static final String MAIN_JS = "appium.js";
61+
62+
private static final String ERROR_TEXT_WHEN_DEFAULT_APPIUM_NODE_IS_NOT_FOUND = "There is no installed nodes! Please " +
63+
"install node via NPM (https://www.npmjs.com/package/appium#using-node-js) or download and " +
64+
"install Appium app (http://appium.io/downloads.html)";
65+
66+
private static final String APPIUM_NODE_MASK_OLD = File.separator + BIN_FOLDER + File.separator + APPIUM_JS;
67+
private static final String APPIUM_NODE_MASK = File.separator + BUILD_FOLDER + File.separator + LIB_FOLDER +
68+
File.separator + MAIN_JS;
4769

4870
public static final String DEFAULT_LOCAL_IP_ADDRESS = "0.0.0.0";
4971

@@ -100,16 +122,28 @@ private File findNodeInCurrentFileSystem(){
100122

101123
instancePath = (commandLine.getStdOut()).trim();
102124
try {
103-
File result;
104-
if (StringUtils.isBlank(instancePath) || !(result = new File(instancePath + File.separator +
105-
APPIUM_NODE_MASK)).exists()) {
125+
File defaultAppiumNode;
126+
if (StringUtils.isBlank(instancePath) || !(defaultAppiumNode = new File(instancePath + File.separator +
127+
APPIUM_FOLDER)).exists()) {
106128
String errorOutput = commandLine.getStdOut();
107-
throw new InvalidServerInstanceException("There is no installed nodes! Please install " +
108-
" node via NPM (https://www.npmjs.com/package/appium#using-node-js) or download and " +
109-
"install Appium app (http://appium.io/downloads.html)",
129+
throw new InvalidServerInstanceException(ERROR_TEXT_WHEN_DEFAULT_APPIUM_NODE_IS_NOT_FOUND,
110130
new IOException(errorOutput));
111131
}
112-
return result;
132+
133+
File oldResult;
134+
//older appium server
135+
if ((oldResult = new File(defaultAppiumNode, APPIUM_NODE_MASK_OLD)).exists()) {
136+
return oldResult;
137+
}
138+
//appium servers v1.5.x and higher
139+
File newResult;
140+
if ((newResult = new File(defaultAppiumNode, APPIUM_NODE_MASK)).exists()) {
141+
return newResult;
142+
}
143+
144+
throw new InvalidServerInstanceException(ERROR_TEXT_WHEN_DEFAULT_APPIUM_NODE_IS_NOT_FOUND,
145+
new IOException("Could not find file neither " + APPIUM_NODE_MASK_OLD + " nor " + APPIUM_NODE_MASK + " in the " +
146+
defaultAppiumNode + " directory"));
113147
}
114148
finally {
115149
commandLine.destroy();

src/main/java/io/appium/java_client/service/local/InvalidServerInstanceException.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,4 @@ public class InvalidServerInstanceException extends RuntimeException {
2424
public InvalidServerInstanceException(String messege, Throwable t){
2525
super(MESSAGE_PREFIX + messege, t);
2626
}
27-
28-
public InvalidServerInstanceException(String messege){
29-
super(MESSAGE_PREFIX + messege);
30-
}
3127
}

src/test/java/io/appium/java_client/android/AndroidDriverTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ private String currentActivity() {
8282

8383
@Test
8484
public void getStringsTest() {
85-
Map<String, String> strings = driver.getAppStrings();
85+
Map<String, String> strings = driver.getAppStringMap();
8686
assertTrue(strings.size() > 100);
8787
}
8888

8989
@Test
9090
public void getStringsWithLanguageTest() {
91-
Map<String, String> strings = driver.getAppStrings("en");
91+
Map<String, String> strings = driver.getAppStringMap("en");
9292
assertTrue(strings.size() > 100);
9393
}
9494

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,25 @@ public void tearDown() throws Exception {
7171

7272
@Test
7373
public void getStringsTest() {
74-
Map<String, String> strings = driver.getAppStrings();
74+
Map<String, String> strings = driver.getAppStringMap();
7575
assertTrue(strings.size() > 10);
7676
}
7777

7878
@Test
7979
public void getStringsWithLanguageTest() {
80-
Map<String, String> strings = driver.getAppStrings("en");
80+
Map<String, String> strings = driver.getAppStringMap("en");
8181
assertTrue(strings.size() > 10);
8282
}
8383

8484
@Test
8585
public void getStringsWithLanguageAndStringFileTest() {
86-
Map<String, String> strings = driver.getAppStrings("en", "Localizable.strings");
86+
Map<String, String> strings = driver.getAppStringMap("en", "Localizable.strings");
8787
assertTrue(strings.size() > 10);
8888
}
8989

9090
@Test
9191
public void getStringsWithUnknownStringFileTest() {
92-
Map<String, String> strings = driver.getAppStrings("en", "Unknown.strings");
92+
Map<String, String> strings = driver.getAppStringMap("en", "Unknown.strings");
9393
assertTrue(strings.size() > 10);
9494
}
9595

0 commit comments

Comments
 (0)