|
46 | 46 | import static io.appium.java_client.MobileCommand.SHAKE; |
47 | 47 | import static io.appium.java_client.MobileCommand.START_ACTIVITY; |
48 | 48 | import static io.appium.java_client.MobileCommand.TOGGLE_LOCATION_SERVICES; |
| 49 | + |
| 50 | +import io.appium.java_client.remote.AppiumCommandExecutor; |
49 | 51 | import io.appium.java_client.remote.MobileCapabilityType; |
50 | 52 |
|
51 | 53 | import java.net.URL; |
|
55 | 57 |
|
56 | 58 | import javax.xml.bind.DatatypeConverter; |
57 | 59 |
|
| 60 | +import io.appium.java_client.service.local.AppiumDriverLocalService; |
| 61 | +import io.appium.java_client.service.local.AppiumServiceBuilder; |
58 | 62 | import org.openqa.selenium.By; |
59 | 63 | import org.openqa.selenium.Capabilities; |
60 | 64 | import org.openqa.selenium.Dimension; |
|
64 | 68 | import org.openqa.selenium.WebDriverException; |
65 | 69 | import org.openqa.selenium.WebElement; |
66 | 70 | import org.openqa.selenium.html5.Location; |
67 | | -import org.openqa.selenium.remote.CommandInfo; |
68 | | -import org.openqa.selenium.remote.DesiredCapabilities; |
69 | | -import org.openqa.selenium.remote.DriverCommand; |
70 | | -import org.openqa.selenium.remote.ErrorHandler; |
71 | | -import org.openqa.selenium.remote.ExecuteMethod; |
72 | | -import org.openqa.selenium.remote.HttpCommandExecutor; |
73 | | -import org.openqa.selenium.remote.RemoteWebElement; |
74 | | -import org.openqa.selenium.remote.Response; |
| 71 | +import org.openqa.selenium.remote.*; |
75 | 72 | import org.openqa.selenium.remote.html5.RemoteLocationContext; |
76 | 73 | import org.openqa.selenium.remote.http.HttpMethod; |
77 | 74 |
|
@@ -197,76 +194,34 @@ protected static ImmutableMap<String, Object> getCommandImmutableMap( |
197 | 194 | return builder.build(); |
198 | 195 | } |
199 | 196 |
|
200 | | - public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) { |
| 197 | + private AppiumDriver(CommandExecutor executor, Capabilities capabilities){ |
| 198 | + super(executor, capabilities); |
| 199 | + this.executeMethod = new AppiumExecutionMethod(this); |
| 200 | + locationContext = new RemoteLocationContext(executeMethod); |
| 201 | + super.setErrorHandler(errorHandler); |
| 202 | + } |
201 | 203 |
|
202 | | - super(remoteAddress, desiredCapabilities); |
203 | | - |
204 | | - this.executeMethod = new AppiumExecutionMethod(this); |
205 | | - this.remoteAddress = remoteAddress; |
206 | | - locationContext = new RemoteLocationContext(executeMethod); |
207 | | - |
208 | | - ImmutableMap.Builder<String, CommandInfo> builder = ImmutableMap |
209 | | - .builder(); |
210 | | - builder.put(RESET, postC("/session/:sessionId/appium/app/reset")) |
211 | | - .put(GET_STRINGS, |
212 | | - postC("/session/:sessionId/appium/app/strings")) |
213 | | - .put(KEY_EVENT, |
214 | | - postC("/session/:sessionId/appium/device/keyevent")) |
215 | | - .put(CURRENT_ACTIVITY, |
216 | | - getC("/session/:sessionId/appium/device/current_activity")) |
217 | | - .put(SET_VALUE, |
218 | | - postC("/session/:sessionId/appium/element/:id/value")) |
219 | | - .put(PULL_FILE, |
220 | | - postC("/session/:sessionId/appium/device/pull_file")) |
221 | | - .put(PULL_FOLDER, |
222 | | - postC("/session/:sessionId/appium/device/pull_folder")) |
223 | | - .put(HIDE_KEYBOARD, |
224 | | - postC("/session/:sessionId/appium/device/hide_keyboard")) |
225 | | - .put(PUSH_FILE, |
226 | | - postC("/session/:sessionId/appium/device/push_file")) |
227 | | - .put(RUN_APP_IN_BACKGROUND, |
228 | | - postC("/session/:sessionId/appium/app/background")) |
229 | | - .put(PERFORM_TOUCH_ACTION, |
230 | | - postC("/session/:sessionId/touch/perform")) |
231 | | - .put(PERFORM_MULTI_TOUCH, |
232 | | - postC("/session/:sessionId/touch/multi/perform")) |
233 | | - .put(IS_APP_INSTALLED, |
234 | | - postC("/session/:sessionId/appium/device/app_installed")) |
235 | | - .put(INSTALL_APP, |
236 | | - postC("/session/:sessionId/appium/device/install_app")) |
237 | | - .put(REMOVE_APP, |
238 | | - postC("/session/:sessionId/appium/device/remove_app")) |
239 | | - .put(LAUNCH_APP, postC("/session/:sessionId/appium/app/launch")) |
240 | | - .put(CLOSE_APP, postC("/session/:sessionId/appium/app/close")) |
241 | | - .put(END_TEST_COVERAGE, |
242 | | - postC("/session/:sessionId/appium/app/end_test_coverage")) |
243 | | - .put(LOCK, postC("/session/:sessionId/appium/device/lock")) |
244 | | - .put(IS_LOCKED, |
245 | | - postC("/session/:sessionId/appium/device/is_locked")) |
246 | | - .put(SHAKE, postC("/session/:sessionId/appium/device/shake")) |
247 | | - .put(COMPLEX_FIND, |
248 | | - postC("/session/:sessionId/appium/app/complex_find")) |
249 | | - .put(OPEN_NOTIFICATIONS, |
250 | | - postC("/session/:sessionId/appium/device/open_notifications")) |
251 | | - .put(GET_NETWORK_CONNECTION, |
252 | | - getC("/session/:sessionId/network_connection")) |
253 | | - .put(SET_NETWORK_CONNECTION, |
254 | | - postC("/session/:sessionId/network_connection")) |
255 | | - .put(GET_SETTINGS, getC("/session/:sessionId/appium/settings")) |
256 | | - .put(SET_SETTINGS, postC("/session/:sessionId/appium/settings")) |
257 | | - .put(START_ACTIVITY, |
258 | | - postC("/session/:sessionId/appium/device/start_activity")) |
259 | | - .put(TOGGLE_LOCATION_SERVICES, postC("/session/:sessionId/appium/device/toggle_location_services")); |
260 | | - |
261 | | - ImmutableMap<String, CommandInfo> mobileCommands = builder.build(); |
262 | | - |
263 | | - HttpCommandExecutor mobileExecutor = new HttpCommandExecutor( |
264 | | - mobileCommands, remoteAddress); |
265 | | - super.setCommandExecutor(mobileExecutor); |
266 | | - |
267 | | - super.setErrorHandler(errorHandler); |
| 204 | + public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) { |
| 205 | + this(new AppiumCommandExecutor( |
| 206 | + getMobileCommands(), remoteAddress), desiredCapabilities); |
| 207 | + this.remoteAddress = remoteAddress; |
268 | 208 | } |
269 | 209 |
|
| 210 | + public AppiumDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) { |
| 211 | + this(new AppiumCommandExecutor( |
| 212 | + getMobileCommands(), service), desiredCapabilities); |
| 213 | + this.remoteAddress = service.getUrl(); |
| 214 | + } |
| 215 | + |
| 216 | + public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) { |
| 217 | + this(builder.build(), desiredCapabilities); |
| 218 | + } |
| 219 | + |
| 220 | + public AppiumDriver(Capabilities desiredCapabilities) { |
| 221 | + this(AppiumDriverLocalService.buildDefaultService(), desiredCapabilities); |
| 222 | + } |
| 223 | + |
| 224 | + |
270 | 225 | @Override |
271 | 226 | protected Response execute(String command) { |
272 | 227 | return super.execute(command, ImmutableMap.<String, Object>of()); |
@@ -708,6 +663,63 @@ private static CommandInfo postC(String url) { |
708 | 663 | return new CommandInfo(url, HttpMethod.POST); |
709 | 664 | } |
710 | 665 |
|
| 666 | + private static ImmutableMap<String, CommandInfo> getMobileCommands(){ |
| 667 | + ImmutableMap.Builder<String, CommandInfo> builder = ImmutableMap |
| 668 | + .builder(); |
| 669 | + builder.put(RESET, postC("/session/:sessionId/appium/app/reset")) |
| 670 | + .put(GET_STRINGS, |
| 671 | + postC("/session/:sessionId/appium/app/strings")) |
| 672 | + .put(KEY_EVENT, |
| 673 | + postC("/session/:sessionId/appium/device/keyevent")) |
| 674 | + .put(CURRENT_ACTIVITY, |
| 675 | + getC("/session/:sessionId/appium/device/current_activity")) |
| 676 | + .put(SET_VALUE, |
| 677 | + postC("/session/:sessionId/appium/element/:id/value")) |
| 678 | + .put(PULL_FILE, |
| 679 | + postC("/session/:sessionId/appium/device/pull_file")) |
| 680 | + .put(PULL_FOLDER, |
| 681 | + postC("/session/:sessionId/appium/device/pull_folder")) |
| 682 | + .put(HIDE_KEYBOARD, |
| 683 | + postC("/session/:sessionId/appium/device/hide_keyboard")) |
| 684 | + .put(PUSH_FILE, |
| 685 | + postC("/session/:sessionId/appium/device/push_file")) |
| 686 | + .put(RUN_APP_IN_BACKGROUND, |
| 687 | + postC("/session/:sessionId/appium/app/background")) |
| 688 | + .put(PERFORM_TOUCH_ACTION, |
| 689 | + postC("/session/:sessionId/touch/perform")) |
| 690 | + .put(PERFORM_MULTI_TOUCH, |
| 691 | + postC("/session/:sessionId/touch/multi/perform")) |
| 692 | + .put(IS_APP_INSTALLED, |
| 693 | + postC("/session/:sessionId/appium/device/app_installed")) |
| 694 | + .put(INSTALL_APP, |
| 695 | + postC("/session/:sessionId/appium/device/install_app")) |
| 696 | + .put(REMOVE_APP, |
| 697 | + postC("/session/:sessionId/appium/device/remove_app")) |
| 698 | + .put(LAUNCH_APP, postC("/session/:sessionId/appium/app/launch")) |
| 699 | + .put(CLOSE_APP, postC("/session/:sessionId/appium/app/close")) |
| 700 | + .put(END_TEST_COVERAGE, |
| 701 | + postC("/session/:sessionId/appium/app/end_test_coverage")) |
| 702 | + .put(LOCK, postC("/session/:sessionId/appium/device/lock")) |
| 703 | + .put(IS_LOCKED, |
| 704 | + postC("/session/:sessionId/appium/device/is_locked")) |
| 705 | + .put(SHAKE, postC("/session/:sessionId/appium/device/shake")) |
| 706 | + .put(COMPLEX_FIND, |
| 707 | + postC("/session/:sessionId/appium/app/complex_find")) |
| 708 | + .put(OPEN_NOTIFICATIONS, |
| 709 | + postC("/session/:sessionId/appium/device/open_notifications")) |
| 710 | + .put(GET_NETWORK_CONNECTION, |
| 711 | + getC("/session/:sessionId/network_connection")) |
| 712 | + .put(SET_NETWORK_CONNECTION, |
| 713 | + postC("/session/:sessionId/network_connection")) |
| 714 | + .put(GET_SETTINGS, getC("/session/:sessionId/appium/settings")) |
| 715 | + .put(SET_SETTINGS, postC("/session/:sessionId/appium/settings")) |
| 716 | + .put(START_ACTIVITY, |
| 717 | + postC("/session/:sessionId/appium/device/start_activity")) |
| 718 | + .put(TOGGLE_LOCATION_SERVICES, postC("/session/:sessionId/appium/device/toggle_location_services")); |
| 719 | + |
| 720 | + return builder.build(); |
| 721 | + } |
| 722 | + |
711 | 723 | @SuppressWarnings("unused") |
712 | 724 | private static CommandInfo deleteC(String url) { |
713 | 725 | return new CommandInfo(url, HttpMethod.DELETE); |
|
0 commit comments