Skip to content

Device & DeviceArray Classes

Getting Device Objects

javascript

var { getDevice, getDevices, searchName, searchGroup, searchTag } = require('sigma/device');
MethodReturnsDescription
getDevice()DevicePrimary/main device
getDevices()DeviceArrayAll connected devices
searchName(name)DeviceFind by device name
searchGroup(group)DeviceArrayFind by group name
searchTag(tag)DeviceArrayFind by tag

Device Properties

Property/MethodDescription
device.getName()Device name
device.getNo()Serial number
device.getWidth()Screen width
device.getOrientation()Rotation direction
device.getRemainingBattery()Battery percentage
device.getSDPath()SD card path
device.getTmpPath()Temporary directory
device.displayMode()Current display mode
device.getAcceleration()Rendering mode

Device Control Methods

App Management

MethodDescription
device.runApp(package)Launch app
device.closeApp(package)Close app
device.restartApp(package)Restart app
device.installAPK(path)Install APK
device.uninstallAPK(package)Uninstall app
device.getForegroundApp()Get active app
device.getActivity()Get current activity
device.getInstalledAPKList()List installed apps

Input Methods

MethodDescription
device.click(x, y)Click at coordinates
device.click2(x, y)Click with random offset
device.swipe(x1, y1, x2, y2)Swipe gesture
device.scroll(direction)Scroll screen
device.inputText(text)Enter text
device.inputForm(data)Fill form
device.send(keycode)Send key event

System Operations

MethodDescription
device.lock()Lock screen
device.unlock()Unlock screen
device.sleep()Put to sleep
device.wakeup()Wake device
device.adb(command)Execute ADB command
device.exec(command)Execute device command

FindNode (AAI)

MethodDescription
device.sendAai(query)Execute FindNode query
device.clickSync(text)Click by text synchronously
device.inputTextSync(text)Input text synchronously
device.runAppSync(package)Launch app synchronously

DeviceArray

DeviceArray wraps multiple devices for batch operations:

javascript

var devices = getDevices();

// Batch operations
devices.runApp("com.example.app");     // all devices
devices.click(540, 960);               // all devices
devices.sendAai({ query: "T:OK", action: "click" });

// Get results from all devices
var results = devices.arrayOutput(function(device) {
  return device.sendAai({ query: "T:Status", action: "getText" });
});

Custom Device Methods

Add custom methods to all device objects:

javascript

// Add custom method
addDeviceFunction("loginApp", function(username, password) {
  this.sendAai({ action: "openApp(com.example.app)" });
  this.sendAai({ query: "HT:Username", action: `setText(${username})` });
  this.sendAai({ query: "HT:Password", action: `setText(${password})` });
  this.sendAai({ query: "T:Login", action: "click" });
});

// Use custom method
device.loginApp("admin", "pass123");

// Remove custom method
delDeviceFunction("loginApp");

Directory & Userlib.js

Custom utility functions can be stored in Userlib.js for automatic loading:

  • Place in the TC scripts directory
  • Functions are available in all scripts
  • Good for shared helpers and common operations

Sigma RT Total Control Documentation