3939
4040import static io .appium .java_client .MobileCommand .*;
4141
42- public class AppiumDriver extends RemoteWebDriver implements MobileDriver ,
43- ContextAware , Rotatable , FindsByIosUIAutomation ,
44- FindsByAndroidUIAutomator , FindsByAccessibilityId , LocationContext ,
45- DeviceActionShortcuts , TouchShortcuts , InteractsWithFiles , InteractsWithApps {
42+ public abstract class AppiumDriver extends RemoteWebDriver implements MobileDriver ,
43+ ContextAware , Rotatable , FindsByAccessibilityId , LocationContext ,
44+ DeviceActionShortcuts , TouchShortcuts , InteractsWithFiles ,
45+ InteractsWithApps {
4646
4747private final static ErrorHandler errorHandler = new ErrorHandler (
4848new ErrorCodesMobile (), true );
4949private URL remoteAddress ;
5050private RemoteLocationContext locationContext ;
5151private ExecuteMethod executeMethod ;
5252
53- //frequently used command parameters
53+ // frequently used command parameters
5454protected final String KEY_CODE = "keycode" ;
5555protected final String PATH = "path" ;
5656private final String SETTINGS = "settings" ;
57-
57+
5858/**
5959 * @param originalCapabilities
6060 * the given {@link Capabilities}
@@ -71,7 +71,7 @@ protected static Capabilities substituteMobilePlatform(
7171}
7272
7373/**
74- * @param param
74+ * @param param
7575 * is a parameter name
7676 * @param value
7777 * is the parameter value
@@ -83,23 +83,25 @@ protected static ImmutableMap<String, Object> getCommandImmutableMap(
8383builder .put (param , value );
8484return builder .build ();
8585}
86-
86+
8787/**
8888 *
89- * @param params is the array with parameter names
90- * @param values is the array with parameter values
89+ * @param params
90+ * is the array with parameter names
91+ * @param values
92+ * is the array with parameter values
9193 * @return built {@link ImmutableMap}
9294 */
9395protected static ImmutableMap <String , Object > getCommandImmutableMap (
9496String [] params , Object [] values ) {
9597ImmutableMap .Builder <String , Object > builder = ImmutableMap .builder ();
96- for (int i = 0 ; i < params .length ; i ++ ) {
97- if (_isNotNullOrEmpty (params [i ]) && _isNotNullOrEmpty (values [i ])){
98+ for (int i = 0 ; i < params .length ; i ++) {
99+ if (_isNotNullOrEmpty (params [i ]) && _isNotNullOrEmpty (values [i ])) {
98100builder .put (params [i ], values [i ]);
99101}
100102}
101103return builder .build ();
102- }
104+ }
103105
104106public AppiumDriver (URL remoteAddress , Capabilities desiredCapabilities ) {
105107
@@ -194,57 +196,56 @@ public void resetApp() {
194196execute (MobileCommand .RESET );
195197}
196198
199+ /**
200+ * @see InteractsWithApps#isAppInstalled(String)
201+ */
202+ @ Override
203+ public boolean isAppInstalled (String bundleId ) {
204+ Response response = execute (IS_APP_INSTALLED ,
205+ ImmutableMap .of ("bundleId" , bundleId ));
206+
207+ return Boolean .parseBoolean (response .getValue ().toString ());
208+ }
209+
210+ /**
211+ * @see InteractsWithApps#installApp(String)
212+ */
213+ @ Override
214+ public void installApp (String appPath ) {
215+ execute (INSTALL_APP , ImmutableMap .of ("appPath" , appPath ));
216+ }
197217
198- /**
199- * @see InteractsWithApps#isAppInstalled(String)
200- */
201- @ Override
202- public boolean isAppInstalled (String bundleId ) {
203- Response response = execute (IS_APP_INSTALLED ,
204- ImmutableMap .of ("bundleId" , bundleId ));
205-
206- return Boolean .parseBoolean (response .getValue ().toString ());
207- }
208-
209- /**
210- * @see InteractsWithApps#installApp(String)
211- */
212- @ Override
213- public void installApp (String appPath ) {
214- execute (INSTALL_APP , ImmutableMap .of ("appPath" , appPath ));
215- }
216-
217- /**
218- * @see InteractsWithApps#removeApp(String)
219- */
220- @ Override
221- public void removeApp (String bundleId ) {
222- execute (REMOVE_APP , ImmutableMap .of ("bundleId" , bundleId ));
223- }
224-
225- /**
226- * @see InteractsWithApps#launchApp()
227- */
228- @ Override
229- public void launchApp () {
230- execute (LAUNCH_APP );
231- }
232-
233- /**
234- * @see InteractsWithApps#closeApp()
235- */
236- @ Override
237- public void closeApp () {
238- execute (CLOSE_APP );
239- }
240-
241- /**
242- * @see InteractsWithApps#runAppInBackground(int)
243- */
244- @ Override
245- public void runAppInBackground (int seconds ) {
246- execute (RUN_APP_IN_BACKGROUND , ImmutableMap .of ("seconds" , seconds ));
247- }
218+ /**
219+ * @see InteractsWithApps#removeApp(String)
220+ */
221+ @ Override
222+ public void removeApp (String bundleId ) {
223+ execute (REMOVE_APP , ImmutableMap .of ("bundleId" , bundleId ));
224+ }
225+
226+ /**
227+ * @see InteractsWithApps#launchApp()
228+ */
229+ @ Override
230+ public void launchApp () {
231+ execute (LAUNCH_APP );
232+ }
233+
234+ /**
235+ * @see InteractsWithApps#closeApp()
236+ */
237+ @ Override
238+ public void closeApp () {
239+ execute (CLOSE_APP );
240+ }
241+
242+ /**
243+ * @see InteractsWithApps#runAppInBackground(int)
244+ */
245+ @ Override
246+ public void runAppInBackground (int seconds ) {
247+ execute (RUN_APP_IN_BACKGROUND , ImmutableMap .of ("seconds" , seconds ));
248+ }
248249
249250/**
250251 * Send a key event to the device
@@ -257,13 +258,13 @@ public void sendKeyEvent(int key) {
257258execute (KEY_EVENT , getCommandImmutableMap (KEY_CODE , key ));
258259}
259260
260- /**
261- * @see DeviceActionShortcuts#hideKeyboard()
262- */
263- @ Override
264- public void hideKeyboard () {
265- execute (HIDE_KEYBOARD );
266- }
261+ /**
262+ * @see DeviceActionShortcuts#hideKeyboard()
263+ */
264+ @ Override
265+ public void hideKeyboard () {
266+ execute (HIDE_KEYBOARD );
267+ }
267268
268269/**
269270 * @see InteractsWithFiles#pullFile(String)
@@ -277,8 +278,8 @@ public byte[] pullFile(String remotePath) {
277278return DatatypeConverter .parseBase64Binary (base64String );
278279}
279280
280- /**
281- * @see InteractsWithFiles#pullFolder(String)
281+ /**
282+ * @see InteractsWithFiles#pullFolder(String)
282283 */
283284@ Override
284285public byte [] pullFolder (String remotePath ) {
@@ -315,7 +316,7 @@ public void performMultiTouchAction(MultiTouchAction multiAction) {
315316}
316317
317318/**
318- *@see TouchShortcuts#tap(int, WebElement, int)
319+ * @see TouchShortcuts#tap(int, WebElement, int)
319320 */
320321@ Override
321322public void tap (int fingers , WebElement element , int duration ) {
@@ -398,8 +399,8 @@ public void pinch(int x, int y) {
398399}
399400
400401/**
401- * @see TouchShortcuts#zoom(WebElement)
402- */
402+ * @see TouchShortcuts#zoom(WebElement)
403+ */
403404@ Override
404405public void zoom (WebElement el ) {
405406MultiTouchAction multiTouch = new MultiTouchAction (this );
@@ -479,18 +480,18 @@ protected void setSetting(AppiumSetting setting, Object value) {
479480setSettings (getCommandImmutableMap (setting .toString (), value ));
480481}
481482
482- /**
483- * Lock the device (bring it to the lock screen) for a given number of
484- * seconds
485- *
486- * @param seconds
487- * number of seconds to lock the screen for
488- */
489- public void lockScreen (int seconds ) {
490- execute (LOCK , ImmutableMap .of ("seconds" , seconds ));
491- }
483+ /**
484+ * Lock the device (bring it to the lock screen) for a given number of
485+ * seconds
486+ *
487+ * @param seconds
488+ * number of seconds to lock the screen for
489+ */
490+ public void lockScreen (int seconds ) {
491+ execute (LOCK , ImmutableMap .of ("seconds" , seconds ));
492+ }
492493
493- @ Override
494+ @ Override
494495public WebDriver context (String name ) {
495496if (!_isNotNullOrEmpty (name )) {
496497throw new IllegalArgumentException ("Must supply a context name" );
@@ -545,26 +546,6 @@ public ScreenOrientation getOrientation() {
545546}
546547}
547548
548- @ Override
549- public WebElement findElementByIosUIAutomation (String using ) {
550- return findElement ("-ios uiautomation" , using );
551- }
552-
553- @ Override
554- public List <WebElement > findElementsByIosUIAutomation (String using ) {
555- return findElements ("-ios uiautomation" , using );
556- }
557-
558- @ Override
559- public WebElement findElementByAndroidUIAutomator (String using ) {
560- return findElement ("-android uiautomator" , using );
561- }
562-
563- @ Override
564- public List <WebElement > findElementsByAndroidUIAutomator (String using ) {
565- return findElements ("-android uiautomator" , using );
566- }
567-
568549@ Override
569550public WebElement findElementByAccessibilityId (String using ) {
570551return findElement ("accessibility id" , using );
@@ -612,19 +593,19 @@ public URL getRemoteAddress() {
612593return remoteAddress ;
613594}
614595
615- /**
616- * Checks if a string is null, empty, or whitespace.
617- *
618- * @param str
619- * String to check.
620- *
621- * @return True if str is not null or empty.
622- */
623- protected static boolean _isNotNullOrEmpty (String str ) {
624- return str != null && !str .isEmpty () && str .trim ().length () > 0 ;
625- }
626-
627- protected static boolean _isNotNullOrEmpty (Object ob ) {
628- return ob != null ;
629- }
596+ /**
597+ * Checks if a string is null, empty, or whitespace.
598+ *
599+ * @param str
600+ * String to check.
601+ *
602+ * @return True if str is not null or empty.
603+ */
604+ protected static boolean _isNotNullOrEmpty (String str ) {
605+ return str != null && !str .isEmpty () && str .trim ().length () > 0 ;
606+ }
607+
608+ protected static boolean _isNotNullOrEmpty (Object ob ) {
609+ return ob != null ;
610+ }
630611}
0 commit comments