From 8930aec3e4fea341f952bbf58ba092e29d532efd Mon Sep 17 00:00:00 2001 From: TikhomirovSergey Date: Sat, 30 Jan 2016 20:02:44 +0300 Subject: [PATCH 1/3] #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' --- NOTICE | 2 +- README.md | 11 ++-- pom.xml | 2 +- .../io/appium/java_client/AppiumDriver.java | 22 +++++--- .../io/appium/java_client/HasAppStrings.java | 13 +++-- .../service/local/AppiumServiceBuilder.java | 52 +++++++++++++++---- .../local/InvalidServerInstanceException.java | 4 -- .../android/AndroidDriverTest.java | 4 +- .../appium/java_client/ios/IOSDriverTest.java | 8 +-- 9 files changed, 84 insertions(+), 34 deletions(-) diff --git a/NOTICE b/NOTICE index 391d40892..d7621e582 100644 --- a/NOTICE +++ b/NOTICE @@ -1 +1 @@ -Copyright 2014-2015 Appium Contributors \ No newline at end of file +Copyright 2014-2016 Appium Contributors \ No newline at end of file diff --git a/README.md b/README.md index a7a480fc9..b5248a1ee 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ More can be found in the docs, but here's a quick list of features which this pr - startActivity() - resetApp() -- getAppStrings() +- getAppStringMap() - pressKeyCode() - longPressKeyCode() - longPressKey() @@ -108,11 +108,14 @@ If you are working on this project and use Intellij Idea, you need to change the If you are using the Eclipse IDE, make sure you are using version Luna or later. ##Changelog## -*4.0.0 (still not released)* -- `getAppStrings()` methods now return a map with the app strings keys and values, instead of an string +*3.4.0 (still not released)* +- Update to Selenium v2.50.0 +- `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, +instead of an string. Thanks to [@rgonalo](https://github.com/rgonalo) for the contribution. - Add `getAppStrings(String language, String stringFile)` method to allow searching app strings in the specified file - 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). -- Fixed Zoom methods, thanks to @kkhaidukov +- FIXED Zoom methods, thanks to [@kkhaidukov](https://github.com/kkhaidukov) +- 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) *3.3.0* - updated the dependency on Selenium to version 2.48.2 diff --git a/pom.xml b/pom.xml index 0f1b41eb1..8be0d2132 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ org.seleniumhq.selenium selenium-java - 2.48.2 + 2.50.0 junit diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index f56f277eb..19624b496 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -603,13 +603,23 @@ public void setLocation(Location location) { locationContext.setLocation(location); } + @Deprecated + /** + * This method is deprecated. It is going to be removed in the next release. + * Be careful. + */ + public String getAppStrings() { + Response response = execute(GET_STRINGS); + return response.getValue().toString(); + } + /** * @return a map with localized strings defined in the app * - * @see HasAppStrings#getAppStrings() + * @see HasAppStrings#getAppStringMap() */ @Override - public Map getAppStrings() { + public Map getAppStringMap() { Response response = execute(GET_STRINGS); return (Map) response.getValue(); } @@ -619,10 +629,10 @@ public Map getAppStrings() { * strings language code * @return a map with localized strings defined in the app * - * @see HasAppStrings#getAppStrings(String) + * @see HasAppStrings#getAppStringMap(String) */ @Override - public Map getAppStrings(String language) { + public Map getAppStringMap(String language) { Response response = execute(GET_STRINGS, getCommandImmutableMap(LANGUAGE_PARAM, language)); return (Map) response.getValue(); @@ -635,10 +645,10 @@ public Map getAppStrings(String language) { * strings filename * @return a map with localized strings defined in the app * - * @see HasAppStrings#getAppStrings(String, String) + * @see HasAppStrings#getAppStringMap(String, String) */ @Override - public Map getAppStrings(String language, String stringFile) { + public Map getAppStringMap(String language, String stringFile) { String[] parameters = new String[] { LANGUAGE_PARAM, STRING_FILE_PARAM }; Object[] values = new Object[] { language, stringFile }; Response response = execute(GET_STRINGS, diff --git a/src/main/java/io/appium/java_client/HasAppStrings.java b/src/main/java/io/appium/java_client/HasAppStrings.java index 170f9cb81..727df4755 100644 --- a/src/main/java/io/appium/java_client/HasAppStrings.java +++ b/src/main/java/io/appium/java_client/HasAppStrings.java @@ -20,12 +20,19 @@ public interface HasAppStrings { + @Deprecated + /** + * This method is deprecated. It is going to be removed in the next release. + * Be careful. + */ + public String getAppStrings(); + /** * Get all defined Strings from an app for the default language * * @return a map with localized strings defined in the app */ - Map getAppStrings(); + Map getAppStringMap(); /** * Get all defined Strings from an app for the specified language @@ -34,7 +41,7 @@ public interface HasAppStrings { * strings language code * @return a map with localized strings defined in the app */ - Map getAppStrings(String language); + Map getAppStringMap(String language); /** * Get all defined Strings from an app for the specified language and @@ -46,6 +53,6 @@ public interface HasAppStrings { * strings filename * @return a map with localized strings defined in the app */ - Map getAppStrings(String language, String stringFile); + Map getAppStringMap(String language, String stringFile); } diff --git a/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java b/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java index c5e08d8a0..245bfe85c 100644 --- a/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java +++ b/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java @@ -36,14 +36,36 @@ public final class AppiumServiceBuilder extends DriverService.Builder { + /** + * The property of environmental variable used to define + * the path to executable appium.js (node server v<=1.4.x) or + * main.js (node server v>=1.5.x) + */ public static final String APPIUM_PATH = "APPIUM_BINARY_PATH"; + + /** + * The property of environmental variable used to define + * the path to executable NodeJS file (node.exe for WIN and + * node for Linux/MacOS X) + */ public static final String NODE_PATH = "NODE_BINARY_PATH"; private static final String APPIUM_FOLDER = "appium"; + private static final String BIN_FOLDER = "bin"; + private static final String BUILD_FOLDER = "build"; + private static final String LIB_FOLDER = "lib"; + private static final String APPIUM_JS = "appium.js"; - private static final String APPIUM_NODE_MASK = File.separator + - APPIUM_FOLDER + File.separator + BIN_FOLDER + File.separator + APPIUM_JS; + private static final String MAIN_JS = "appium.js"; + + private static final String ERROR_TEXT_WHEN_DEFAULT_APPIUM_NODE_IS_NOT_FOUND = "There is no installed nodes! Please " + + "install node via NPM (https://www.npmjs.com/package/appium#using-node-js) or download and " + + "install Appium app (http://appium.io/downloads.html)"; + + private static final String APPIUM_NODE_MASK_OLD = File.separator + BIN_FOLDER + File.separator + APPIUM_JS; + private static final String APPIUM_NODE_MASK = File.separator + BUILD_FOLDER + File.separator + LIB_FOLDER + + File.separator + MAIN_JS; public static final String DEFAULT_LOCAL_IP_ADDRESS = "0.0.0.0"; @@ -100,16 +122,28 @@ private File findNodeInCurrentFileSystem(){ instancePath = (commandLine.getStdOut()).trim(); try { - File result; - if (StringUtils.isBlank(instancePath) || !(result = new File(instancePath + File.separator + - APPIUM_NODE_MASK)).exists()) { + File defaultAppiumNode; + if (StringUtils.isBlank(instancePath) || !(defaultAppiumNode = new File(instancePath + File.separator + + APPIUM_FOLDER)).exists()) { String errorOutput = commandLine.getStdOut(); - throw new InvalidServerInstanceException("There is no installed nodes! Please install " + - " node via NPM (https://www.npmjs.com/package/appium#using-node-js) or download and " + - "install Appium app (http://appium.io/downloads.html)", + throw new InvalidServerInstanceException(ERROR_TEXT_WHEN_DEFAULT_APPIUM_NODE_IS_NOT_FOUND, new IOException(errorOutput)); } - return result; + + File oldResult; + //older appium server + if ((oldResult = new File(defaultAppiumNode, APPIUM_NODE_MASK_OLD)).exists()) { + return oldResult; + } + //appium servers v1.5.x and higher + File newResult; + if ((newResult = new File(defaultAppiumNode, APPIUM_NODE_MASK)).exists()) { + return newResult; + } + + throw new InvalidServerInstanceException(ERROR_TEXT_WHEN_DEFAULT_APPIUM_NODE_IS_NOT_FOUND, + new IOException("Could not find file neither " + APPIUM_NODE_MASK_OLD + " nor " + APPIUM_NODE_MASK + " in the " + + defaultAppiumNode + " directory")); } finally { commandLine.destroy(); diff --git a/src/main/java/io/appium/java_client/service/local/InvalidServerInstanceException.java b/src/main/java/io/appium/java_client/service/local/InvalidServerInstanceException.java index cb1a185d3..b8b54fa71 100644 --- a/src/main/java/io/appium/java_client/service/local/InvalidServerInstanceException.java +++ b/src/main/java/io/appium/java_client/service/local/InvalidServerInstanceException.java @@ -24,8 +24,4 @@ public class InvalidServerInstanceException extends RuntimeException { public InvalidServerInstanceException(String messege, Throwable t){ super(MESSAGE_PREFIX + messege, t); } - - public InvalidServerInstanceException(String messege){ - super(MESSAGE_PREFIX + messege); - } } diff --git a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java index d8eba03e2..5794d10fe 100644 --- a/src/test/java/io/appium/java_client/android/AndroidDriverTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidDriverTest.java @@ -82,13 +82,13 @@ private String currentActivity() { @Test public void getStringsTest() { - Map strings = driver.getAppStrings(); + Map strings = driver.getAppStringMap(); assertTrue(strings.size() > 100); } @Test public void getStringsWithLanguageTest() { - Map strings = driver.getAppStrings("en"); + Map strings = driver.getAppStringMap("en"); assertTrue(strings.size() > 100); } diff --git a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java index 15d5fa86f..7533283c9 100644 --- a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java @@ -71,25 +71,25 @@ public void tearDown() throws Exception { @Test public void getStringsTest() { - Map strings = driver.getAppStrings(); + Map strings = driver.getAppStringMap(); assertTrue(strings.size() > 10); } @Test public void getStringsWithLanguageTest() { - Map strings = driver.getAppStrings("en"); + Map strings = driver.getAppStringMap("en"); assertTrue(strings.size() > 10); } @Test public void getStringsWithLanguageAndStringFileTest() { - Map strings = driver.getAppStrings("en", "Localizable.strings"); + Map strings = driver.getAppStringMap("en", "Localizable.strings"); assertTrue(strings.size() > 10); } @Test public void getStringsWithUnknownStringFileTest() { - Map strings = driver.getAppStrings("en", "Unknown.strings"); + Map strings = driver.getAppStringMap("en", "Unknown.strings"); assertTrue(strings.size() > 10); } From d57715f65059cd99b781c6b310127706b5958eac Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Sat, 30 Jan 2016 23:18:26 +0300 Subject: [PATCH 2/3] #305 fix: a little improvement --- .../appium/java_client/service/local/AppiumServiceBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java b/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java index 245bfe85c..5232f2cb0 100644 --- a/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java +++ b/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java @@ -57,7 +57,7 @@ public final class AppiumServiceBuilder extends DriverService.Builder Date: Mon, 1 Feb 2016 22:52:32 +0300 Subject: [PATCH 3/3] #305 fix: work on remarks --- README.md | 4 ++-- src/main/java/io/appium/java_client/AppiumDriver.java | 11 +++++++++++ .../java/io/appium/java_client/HasAppStrings.java | 7 +++++++ .../service/local/AppiumServiceBuilder.java | 10 +++++----- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b5248a1ee..332ad090f 100644 --- a/README.md +++ b/README.md @@ -110,8 +110,8 @@ If you are using the Eclipse IDE, make sure you are using version Luna or later. ##Changelog## *3.4.0 (still not released)* - Update to Selenium v2.50.0 -- `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, -instead of an string. Thanks to [@rgonalo](https://github.com/rgonalo) for the contribution. +- `getAppStrings()` methods are deprecated now. They are going to be removed. `getAppStringMap()` methods were added and now return a map with app strings (keys and values) +instead of a string. Thanks to [@rgonalo](https://github.com/rgonalo) for the contribution. - Add `getAppStrings(String language, String stringFile)` method to allow searching app strings in the specified file - 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). - FIXED Zoom methods, thanks to [@kkhaidukov](https://github.com/kkhaidukov) diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index 19624b496..4c601a1b6 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -613,6 +613,17 @@ public String getAppStrings() { return response.getValue().toString(); } + @Deprecated + /** + * This method is deprecated. It is going to be removed in the next release. + * Be careful. + */ + public String getAppStrings(String language) { + Response response = execute(GET_STRINGS, + getCommandImmutableMap(LANGUAGE_PARAM, language)); + return response.getValue().toString(); + } + /** * @return a map with localized strings defined in the app * diff --git a/src/main/java/io/appium/java_client/HasAppStrings.java b/src/main/java/io/appium/java_client/HasAppStrings.java index 727df4755..25a080445 100644 --- a/src/main/java/io/appium/java_client/HasAppStrings.java +++ b/src/main/java/io/appium/java_client/HasAppStrings.java @@ -27,6 +27,13 @@ public interface HasAppStrings { */ public String getAppStrings(); + @Deprecated + /** + * This method is deprecated. It is going to be removed in the next release. + * Be careful. + */ + String getAppStrings(String language); + /** * Get all defined Strings from an app for the default language * diff --git a/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java b/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java index 5232f2cb0..09bd8ae5b 100644 --- a/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java +++ b/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java @@ -37,14 +37,14 @@ public final class AppiumServiceBuilder extends DriverService.Builder { /** - * The property of environmental variable used to define + * The environmental variable used to define * the path to executable appium.js (node server v<=1.4.x) or * main.js (node server v>=1.5.x) */ public static final String APPIUM_PATH = "APPIUM_BINARY_PATH"; /** - * The property of environmental variable used to define + * The environmental variable used to define * the path to executable NodeJS file (node.exe for WIN and * node for Linux/MacOS X) */ @@ -59,7 +59,7 @@ public final class AppiumServiceBuilder extends DriverService.Builder