forked from openatx/uiautomator2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
974cad7
commit d31d2e0
Showing
7 changed files
with
125 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,3 +105,4 @@ ChangeLog | |
.vscode/ | ||
report/ | ||
*.apk | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# adbkit-init | ||
run `python -m uiautomator2 init` once android device plugin. | ||
|
||
## Installation | ||
```bash | ||
npm install . | ||
``` | ||
|
||
## Usage | ||
```bash | ||
node main.js --server $SERVER_ADDR | ||
``` | ||
|
||
How it works. | ||
|
||
Use adbkit to trace device. And the following command will call when device plugin | ||
|
||
```bash | ||
python -m uiautomator2 init --server $SERVER_ADDR | ||
``` | ||
|
||
## LICENSE | ||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict' | ||
|
||
var Promise = require('bluebird') | ||
var adb = require('adbkit') | ||
var client = adb.createClient() | ||
var util = require('util') | ||
const { spawn } = require("child_process") | ||
var argv = require('minimist')(process.argv.slice(2)) | ||
|
||
const serverAddr = argv.server; // Usage: node main.js --server $SERVER_ADDR | ||
|
||
function initDevice(device) { | ||
if (device.type != 'device') { | ||
return | ||
} | ||
client.shell(device.id, 'am start -a android.intent.action.VIEW -d http://www.stackoverflow.com') | ||
.then(adb.util.readAll) | ||
.then(function(output) { | ||
var args = ["-m", "uiautomator2", "init", "--serial", device.id] | ||
if (serverAddr) { | ||
args.push("--server", serverAddr); | ||
} | ||
const child = spawn("python", args); | ||
child.stdout.on("data", data => { | ||
process.stdout.write(data) | ||
}) | ||
child.stderr.on("data", data => { | ||
process.stderr.write(data) | ||
}) | ||
child.on('close', code => { | ||
util.log(`child process exited with code ${code}`); | ||
}); | ||
}) | ||
} | ||
|
||
util.log("tracking device") | ||
if (serverAddr) { | ||
util.log("server %s", serverAddr) | ||
} | ||
|
||
client.trackDevices() | ||
.then(function(tracker) { | ||
tracker.on('add', function(device) { | ||
util.log("Device %s(%s) was plugged in", device.id, device.type) | ||
initDevice(device) | ||
}) | ||
tracker.on('remove', function(device) { | ||
util.log('Device %s was unplugged', device.id) | ||
}) | ||
tracker.on("change", function(device) { | ||
util.log('Device %s was changed to %s', device.id, device.type) | ||
initDevice(device) | ||
}) | ||
tracker.on('end', function() { | ||
util.log('Tracking stopped') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "adbkit-init", | ||
"version": "1.0.0", | ||
"description": "run `python -m uiautomator2 init` once android device plugin.", | ||
"main": "main.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"adbkit": "^2.11.0", | ||
"minimist": "^1.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters