1717
1818package io .appium .java_client ;
1919
20- import static io .appium .java_client .MobileCommand .CLOSE_APP ;
21- import static io .appium .java_client .MobileCommand .COMPLEX_FIND ;
22- import static io .appium .java_client .MobileCommand .CURRENT_ACTIVITY ;
23- import static io .appium .java_client .MobileCommand .END_TEST_COVERAGE ;
24- import static io .appium .java_client .MobileCommand .GET_NETWORK_CONNECTION ;
25- import static io .appium .java_client .MobileCommand .GET_SETTINGS ;
26- import static io .appium .java_client .MobileCommand .GET_STRINGS ;
27- import static io .appium .java_client .MobileCommand .HIDE_KEYBOARD ;
28- import static io .appium .java_client .MobileCommand .INSTALL_APP ;
29- import static io .appium .java_client .MobileCommand .IS_APP_INSTALLED ;
30- import static io .appium .java_client .MobileCommand .IS_LOCKED ;
31- import static io .appium .java_client .MobileCommand .KEY_EVENT ;
32- import static io .appium .java_client .MobileCommand .LAUNCH_APP ;
33- import static io .appium .java_client .MobileCommand .LOCK ;
34- import static io .appium .java_client .MobileCommand .OPEN_NOTIFICATIONS ;
35- import static io .appium .java_client .MobileCommand .PERFORM_MULTI_TOUCH ;
36- import static io .appium .java_client .MobileCommand .PERFORM_TOUCH_ACTION ;
37- import static io .appium .java_client .MobileCommand .PULL_FILE ;
38- import static io .appium .java_client .MobileCommand .PULL_FOLDER ;
39- import static io .appium .java_client .MobileCommand .PUSH_FILE ;
40- import static io .appium .java_client .MobileCommand .REMOVE_APP ;
41- import static io .appium .java_client .MobileCommand .RESET ;
42- import static io .appium .java_client .MobileCommand .RUN_APP_IN_BACKGROUND ;
43- import static io .appium .java_client .MobileCommand .SET_NETWORK_CONNECTION ;
44- import static io .appium .java_client .MobileCommand .SET_SETTINGS ;
45- import static io .appium .java_client .MobileCommand .SET_VALUE ;
46- import static io .appium .java_client .MobileCommand .SHAKE ;
47- import static io .appium .java_client .MobileCommand .START_ACTIVITY ;
20+ import com .google .common .collect .ImmutableList ;
21+ import com .google .common .collect .ImmutableMap ;
22+ import com .google .gson .JsonObject ;
23+ import com .google .gson .JsonParser ;
4824import io .appium .java_client .internal .JsonToMobileElementConverter ;
4925import io .appium .java_client .remote .MobileCapabilityType ;
26+ import org .openqa .selenium .*;
27+ import org .openqa .selenium .html5 .Location ;
28+ import org .openqa .selenium .html5 .LocationContext ;
29+ import org .openqa .selenium .remote .*;
30+ import org .openqa .selenium .remote .html5 .RemoteLocationContext ;
31+ import org .openqa .selenium .remote .http .HttpMethod ;
5032
33+ import javax .xml .bind .DatatypeConverter ;
5134import java .net .URL ;
5235import java .util .LinkedHashSet ;
5336import java .util .List ;
5437import java .util .Map ;
5538import java .util .Set ;
5639
57- import javax .xml .bind .DatatypeConverter ;
58-
59- import org .openqa .selenium .Capabilities ;
60- import org .openqa .selenium .ContextAware ;
61- import org .openqa .selenium .Dimension ;
62- import org .openqa .selenium .Point ;
63- import org .openqa .selenium .Rotatable ;
64- import org .openqa .selenium .ScreenOrientation ;
65- import org .openqa .selenium .WebDriver ;
66- import org .openqa .selenium .WebDriverException ;
67- import org .openqa .selenium .WebElement ;
68- import org .openqa .selenium .html5 .Location ;
69- import org .openqa .selenium .html5 .LocationContext ;
70- import org .openqa .selenium .remote .CommandInfo ;
71- import org .openqa .selenium .remote .DesiredCapabilities ;
72- import org .openqa .selenium .remote .DriverCommand ;
73- import org .openqa .selenium .remote .ErrorHandler ;
74- import org .openqa .selenium .remote .ExecuteMethod ;
75- import org .openqa .selenium .remote .HttpCommandExecutor ;
76- import org .openqa .selenium .remote .RemoteWebDriver ;
77- import org .openqa .selenium .remote .Response ;
78- import org .openqa .selenium .remote .html5 .RemoteLocationContext ;
79- import org .openqa .selenium .remote .http .HttpMethod ;
80-
81- import com .google .common .collect .ImmutableList ;
82- import com .google .common .collect .ImmutableMap ;
83- import com .google .gson .JsonObject ;
84- import com .google .gson .JsonParser ;
40+ import static io .appium .java_client .MobileCommand .*;
8541
8642public class AppiumDriver extends RemoteWebDriver implements MobileDriver ,
8743ContextAware , Rotatable , FindsByIosUIAutomation ,
@@ -138,7 +94,7 @@ protected static ImmutableMap<String, Object> getCommandImmutableMap(
13894String [] params , Object [] values ) {
13995ImmutableMap .Builder <String , Object > builder = ImmutableMap .builder ();
14096for (int i =0 ; i < params .length ; i ++ ){
141- if (_isNotNullOrEmpty (params [i ])){
97+ if (_isNotNullOrEmpty (params [i ]) && _isNotNullOrEmpty ( values [ i ]) ){
14298builder .put (params [i ], values [i ]);
14399}
144100}
@@ -238,6 +194,58 @@ public void resetApp() {
238194execute (MobileCommand .RESET );
239195}
240196
197+
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+ }
248+
241249/**
242250 * Send a key event to the device
243251 *
@@ -249,17 +257,13 @@ public void sendKeyEvent(int key) {
249257execute (KEY_EVENT , getCommandImmutableMap (KEY_CODE , key ));
250258}
251259
252- /**
253- * Checks if a string is null, empty, or whitespace.
254- *
255- * @param str
256- * String to check.
257- *
258- * @return True if str is not null or empty.
259- */
260- protected static boolean _isNotNullOrEmpty (String str ) {
261- return str != null && !str .isEmpty () && str .trim ().length () > 0 ;
262- }
260+ /**
261+ * @see DeviceActionShortcuts#hideKeyboard()
262+ */
263+ @ Override
264+ public void hideKeyboard () {
265+ execute (HIDE_KEYBOARD );
266+ }
263267
264268/**
265269 * @see InteractsWithFiles#pullFile(String)
@@ -285,22 +289,6 @@ public byte[] pullFolder(String remotePath) {
285289return DatatypeConverter .parseBase64Binary (base64String );
286290}
287291
288- /**
289- * @see DeviceActionShortcuts#hideKeyboard()
290- */
291- @ Override
292- public void hideKeyboard () {
293- execute (HIDE_KEYBOARD );
294- }
295-
296- /**
297- * @see InteractsWithApps#runAppInBackground(int)
298- */
299- @ Override
300- public void runAppInBackground (int seconds ) {
301- execute (RUN_APP_IN_BACKGROUND , ImmutableMap .of ("seconds" , seconds ));
302- }
303-
304292/**
305293 * @see PerformsTouchActions#performTouchAction(TouchAction)
306294 */
@@ -482,49 +470,6 @@ public void zoom(int x, int y) {
482470 multiTouch .perform ();
483471 }
484472
485- /**
486- * @see InteractsWithApps#isAppInstalled(String)
487- */
488- @ Override
489- public boolean isAppInstalled (String bundleId ) {
490- Response response = execute (IS_APP_INSTALLED ,
491- ImmutableMap .of ("bundleId" , bundleId ));
492-
493- return Boolean .parseBoolean (response .getValue ().toString ());
494- }
495-
496- /**
497- * @see InteractsWithApps#installApp(String)
498- */
499- @ Override
500- public void installApp (String appPath ) {
501- execute (INSTALL_APP , ImmutableMap .of ("appPath" , appPath ));
502- }
503-
504- /**
505- * @see InteractsWithApps#removeApp(String)
506- */
507- @ Override
508- public void removeApp (String bundleId ) {
509- execute (REMOVE_APP , ImmutableMap .of ("bundleId" , bundleId ));
510- }
511-
512- /**
513- * @see InteractsWithApps#launchApp()
514- */
515- @ Override
516- public void launchApp () {
517- execute (LAUNCH_APP );
518- }
519-
520- /**
521- * @see InteractsWithApps#closeApp()
522- */
523- @ Override
524- public void closeApp () {
525- execute (CLOSE_APP );
526- }
527-
528473/**
529474 * Get settings stored for this test session It's probably better to use a
530475 * convenience function, rather than use this function directly. Try finding
@@ -568,7 +513,18 @@ protected void setSetting(AppiumSetting setting, Object value) {
568513setSettings (getCommandImmutableMap (setting .toString (), value ));
569514}
570515
571- @ Override
516+ /**
517+ * Lock the device (bring it to the lock screen) for a given number of
518+ * seconds
519+ *
520+ * @param seconds
521+ * number of seconds to lock the screen for
522+ */
523+ public void lockScreen (int seconds ) {
524+ execute (LOCK , ImmutableMap .of ("seconds" , seconds ));
525+ }
526+
527+ @ Override
572528public WebDriver context (String name ) {
573529if (!_isNotNullOrEmpty (name )) {
574530throw new IllegalArgumentException ("Must supply a context name" );
@@ -689,4 +645,20 @@ private static CommandInfo deleteC(String url) {
689645public URL getRemoteAddress () {
690646return remoteAddress ;
691647}
648+
649+ /**
650+ * Checks if a string is null, empty, or whitespace.
651+ *
652+ * @param str
653+ * String to check.
654+ *
655+ * @return True if str is not null or empty.
656+ */
657+ protected static boolean _isNotNullOrEmpty (String str ) {
658+ return str != null && !str .isEmpty () && str .trim ().length () > 0 ;
659+ }
660+
661+ protected static boolean _isNotNullOrEmpty (Object ob ) {
662+ return ob != null ;
663+ }
692664}
0 commit comments