Native Mobile commands in Appium

Automating Gestures

iOS specific gestures

Map<String, Object> args = new HashMap<>();
args.put("direction", "up");
driver.executeScript("mobile: swipe", args);
args.put("direction", "down");
driver.executeScript("mobile: swipe", args);

mobile: swipe

Map<String, Object> args = new HashMap<>();
args.put("direction", "down");
driver.executeScript("mobile: scroll", args);
args.put("direction", "up");
driver.executeScript("mobile: scroll", args);

mobile: scroll

Map<String, Object> args = new HashMap<>();
args.put("scale", 5);
driver.executeScript("mobile: pinch", args);

mobile: pinch

iOS specific gestures

Map<String, Object> args = new HashMap<>();
args.put("element", ((MobileElement) element).getId());
args.put("x", 2);
args.put("y", 2);
driver.executeScript("mobile: tap", args);

mobile: tap

// double-tap the screen at a specific point
Map<String, Object> args = new HashMap<>();
args.put("x", 100);
args.put("y", 200);
driver.executeScript("mobile: doubleTap", args);

mobile: doubleTap

// two-finger-tap an element (assume element object already
 exists)
Map<String, Object> args = new HashMap<>();
args.put("element", ((MobileElement) element).getId());
driver.executeScript("mobile: twoFingerTap", args);

mobile: twoFingerTap

Switching b/w multiple Apps

Siri Shortcuts

args.put("text", "Hey Siri Whats trending");
driver.executeScript("mobile: siriCommand", args);

Performance Profiling

Face Unlock

args.put("type", "faceId");
args.put("match", "true");
driver.executeScript("mobile:  sendBiometricMatch", args);

Instant Apps

args.put("url", "https://www.site.com/");
args.put("package", "com.site.SomeAndroidPackage");
driver.executeScript("mobile:  deepLink", args);

Drawer Actions

args.put("gravity", "3");
args.put("element", ((RemoteWebElement) element).getId());
driver.executeScript("mobile: openDrawer", args);

Date Picker

args.put("year", "2020");
args.put("monthOfYear", "10");
args.put("dayOfMonth", "25");
args.put("element", ((RemoteWebElement) element).getId());
driver.executeScript("mobile: setDate", args);

Android shell interactions

10057 ◯ : adb shell dumpsys battery
Current Battery Service state:
  AC powered: true
  USB powered: false
  Wireless powered: false
  Max charging current: 0
  Max charging voltage: 0
  Charge counter: 0
  status: 2
  health: 2
  present: true
  level: 100
  scale: 100
  voltage: 0
  temperature: 0
  technology: Li-ion

Get Battery Information

10078 ◯ : adb shell dumpsys cpuinfo
Load: 0.0 / 0.0 / 0.0
CPU usage from 312959ms to 312499ms ago (2018-10-07 10:49:37.267 to 2018-10-07 10:49:37.727):
  151% 1523/system_server: 51% user + 100% kernel / faults: 7233 minor 83 major
  15% 1365/surfaceflinger: 6.6% user + 8.8% kernel / faults: 1 minor
  15% 1375/installd: 2.2% user + 13% kernel / faults: 113 minor
  6.6% 1499/bootanimation: 4.4% user + 2.2% kernel
  4.4% 1358/android.hardware.graphics.composer@2.1-service: 2.2% user + 2.2% kernel
  2.2% 1288/kworker/0:1: 0% user + 2.2% kernel
  2.2% 1298/logd: 0% user + 2.2% kernel / faults: 5 minor
  2.2% 1299/servicemanager: 0% user + 2.2% kernel / faults: 1 minor
  2.2% 1360/android.hardware.sensors@1.0-service: 0% user + 2.2% kernel / faults: 20 minor
50% TOTAL: 13% user + 26% kernel + 10% iowait

Get cpu Information

10079 ◯ : adb shell service list

List all services

 

@saikrisv

 

saikrisv@thoughtworks.com

 

github.com/saikrishna321

 

 

@srinivasanskr

 

sekars@thoughtworks.com

 

github.com/srinivasantarget

 

Native Mobile commands using Appium

By Srinivasan Sekar

Native Mobile commands using Appium

  • 1,945