0.0.9 • Published 3 years ago
uiautomator-wrapper v0.0.9
uiautomator Alpha
NodeJS wrapper for UiAutomator
Installation
npm install uiautomator-wrapperUsage
CommonJS
var Device = require('uiautomator-wrapper');
var device = new Device();
device.connect()
.then(() => device.home())
.then(() => device.click({ description: 'Apps' }))
.then(() => device.back())
.then(() => console.log('Finished'))
.catch((err) => console.error(err))ES6
import Device from 'uiautomator-wrapper';
const test = async () => {
const device = new Device();
await device.connect();
await device.home();
await device.click({ description: 'Apps' });
await device.back();
};
test()
.then(() => console.log('Finished'))
.catch(err => console.error(err));Device setup
var options = {
serial: "emulator5554"
}
var device = new Device(options);Default options:
{
hostname: 'localhost',
delay: 500, //delay between commands
port: 9008,
devicePort: 9008,
connectionMaxTries: 5,
connectionTriesDelay: 1000,
serial: undefined //Not necessary if there is only one device available
}API
Device info
device.info()Key events
//Press home device.home() //Press back device.back()- All key functions:
home,volumeUp,volumeDown,volumeMute,back,right,left,up,down,menu,search,center,enter,delete,recent,camera,power
- All key functions:
Selectors
device.click({description: 'Apps'});- Supported Selectors:
,Contains,Matches,StartsWith,className,classNameMatches,description,descriptionContains,descriptionMatches,descriptionStartsWith,checkable,checked,clickable,longClickable,scrollable,enabled,focusable,focused,selected,packageName,packageNameMatches,resourceId,resourceIdMatches,index,instance
- Supported Selectors:
- Input text
device.setText({description: 'Message'}, 'Hello World')
Acknowledgement
This package is inspired by xiaocong/uiautomator python library, even using its android-uiautomator-server.