NodeJS wrapper for UiAutomator
npm install uiautomator-wrapper
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))
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));
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
}
-
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:
text
,textContains
,textMatches
,textStartsWith
,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')
This package is inspired by xiaocong/uiautomator python library, even using its android-uiautomator-server.