|
36 | 36 |
|
37 | 37 | public final class AppiumServiceBuilder extends DriverService.Builder<AppiumDriverLocalService, AppiumServiceBuilder> { |
38 | 38 |
|
| 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 | + */ |
39 | 44 | 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 | + */ |
40 | 51 | public static final String NODE_PATH = "NODE_BINARY_PATH"; |
41 | 52 |
|
42 | 53 | private static final String APPIUM_FOLDER = "appium"; |
| 54 | + |
43 | 55 | private static final String BIN_FOLDER = "bin"; |
| 56 | + private static final String BUILD_FOLDER = "build"; |
| 57 | + private static final String LIB_FOLDER = "lib"; |
| 58 | + |
44 | 59 | 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; |
47 | 69 |
|
48 | 70 | public static final String DEFAULT_LOCAL_IP_ADDRESS = "0.0.0.0"; |
49 | 71 |
|
@@ -100,16 +122,28 @@ private File findNodeInCurrentFileSystem(){ |
100 | 122 |
|
101 | 123 | instancePath = (commandLine.getStdOut()).trim(); |
102 | 124 | 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()) { |
106 | 128 | 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, |
110 | 130 | new IOException(errorOutput)); |
111 | 131 | } |
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")); |
113 | 147 | } |
114 | 148 | finally { |
115 | 149 | commandLine.destroy(); |
|
0 commit comments