今天发现 Macaca 团队发布了,基于 macaca 的 inspector 赶紧安装起来看看吧。
http://macacajs.github.io/macaca/inspector.html
不多说,根据帮助开启 win10 cmd 命令行 开始安装。前提是你已经要部署好 macaca-cli 。
C:\Users\cmd>npm i app-inspector -g
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated win-spawn@2.0.0: use [cross-spawn](https://github.com/IndigoUnited/node-cross-spawn) or [cross-spawn-async](https://github.com/IndigoUnited/node-cross-spawn-async) instead.
npm WARN deprecated tough-cookie@2.2.2: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130
D:\nodejs\node-global\inspector -> D:\nodejs\node-global\node_modules\app-inspector\bin\app-inspector
D:\nodejs\node-global\app-inspector -> D:\nodejs\node-global\node_modules\app-inspector\bin\app-inspector
> webdriveragent@1.0.19 install D:\nodejs\node-global\node_modules\app-inspector\node_modules\webdriveragent
> node ./scripts/install.js
> uiautomator-client@1.0.16 install D:\nodejs\node-global\node_modules\app-inspector\node_modules\uiautomator-client
> node ./scripts/build.js
JAVA_HOME is set to C:\Program Files\Java\jdk1.8.0_91
Updated file
D:\nodejs\node-global\node_modules\app-inspector\node_modules\uiautomator-client\build.xml
Buildfile: D:\nodejs\node-global\node_modules\app-inspector\node_modules\uiautomator-client\build.xml
-check-env:
[checkenv] Android SDK Tools Revision 25.1.7
[checkenv] Installed at D:\Android\android-sdk-windows-build-setup:
[getbuildtools] Using latest Build Tools: 23.0.2
[echo] Resolving Build Target for uiautomator-bootstrap...
[getuitarget] Project Target: Android 7.0
[getuitarget] API level: 24
[echo] ----------
[echo] Creating output directories if needed...
[mkdir] Created dir: D:\nodejs\node-global\node_modules\app-inspector\node_modules\uiautomator-client\bin
[mkdir] Created dir: D:\nodejs\node-global\node_modules\app-inspector\node_modules\uiautomator-client\bin\classes
-pre-compile:compile:
[javac] Compiling 18 source files to D:\nodejs\node-global\node_modules\app-inspector\node_modules\uiautomator-client\bin\classes
[javac] ����: [options] Դֵ1.5�ѹ�ʱ, ����δ�����з��а���ɾ��
[javac] ����: [options] Ŀ��ֵ1.5�ѹ�ʱ, ����δ�����з��а���ɾ�� [javac] ����: [options] Ҫ�����й��ѹ�ʱѡ���ľ���, ��ʹ�� -Xlint:-options��
[javac] ע: ijЩ�����ļ�ʹ�û�����ѹ�ʱ�� API��
[javac] ע: �й���ϸ��Ϣ, ��ʹ�� -Xlint:deprecation ���±��롣
[javac] 3 ������-post-compile:-dex:
[dex] input: D:\nodejs\node-global\node_modules\app-inspector\node_modules\uiautomator-client\bin\classes
[dex] Converting compiled files and external libraries into D:\nodejs\node-global\node_modules\app-inspector\node_modules\uiautomator-client\bin\classes.dex...
-post-dex:
-jar:
[jar] Building jar: D:\nodejs\node-global\node_modules\app-inspector\node_modules\uiautomator-client\bin\uiautomator-bootstrap.jar
-post-jar:
build:
BUILD SUCCESSFULTotal time: 3 seconds
uiautomator-bootstrap build success!
D:\nodejs\node-global
`-- app-inspector@1.0.8
+-- babel@5.6.23
| +-- babel-core@5.8.38
| | +-- babel-plugin-constant-folding@1.0.1
| | +-- babel-plugin-dead-code-elimination@1.0.2
| | +-- babel-plugin-eval@1.0.1
| | +-- babel-plugin-inline-environment-variables@1.0.1
| | +-- babel-plugin-jscript@1.0.4
| | +-- babel-plugin-member-expression-literals@1.0.1
| | +-- babel-plugin-property-literals@1.0.1
| | +-- babel-plugin-proto-to-assign@1.0.4
| | +-- babel-plugin-react-constant-elements@1.0.3
| | +-- babel-plugin-react-display-name@1.0.3
| | +-- babel-plugin-remove-console@1.0.1
| | +-- babel-plugin-remove-debugger@1.0.1
| | +-- babel-plugin-runtime@1.0.7
| | +-- babel-plugin-undeclared-variables-check@1.0.2
| | | `-- leven@1.0.2
| | +-- babel-plugin-undefined-to-void@1.1.6
| | +-- babylon@5.8.38
| | +-- bluebird@2.10.2
| | +-- core-js@1.2.7
| | +-- detect-indent@3.0.1
| | | +-- get-stdin@4.0.1
| | | `-- minimist@1.2.0
| | +-- esutils@2.0.2
| | +-- globals@6.4.1
| | +-- home-or-tmp@1.0.0
| | | +-- os-tmpdir@1.0.1
| | | `-- user-home@1.1.1
| | +-- is-integer@1.0.6
| | | `-- is-finite@1.0.1
| | | `-- number-is-nan@1.0.0
| | +-- js-tokens@1.0.1
| | +-- json5@0.4.0
| | +-- minimatch@2.0.10
| | | `-- brace-expansion@1.1.6
| | | +-- balanced-match@0.4.2
| | | `-- concat-map@0.0.1
| | +-- private@0.1.6
| | +-- regenerator@0.8.40
| | | +-- commoner@0.10.4
| | | | +-- detective@4.3.1
| | | | | +-- acorn@1.2.2
| | | | | `-- defined@1.0.0
| | | | `-- q@1.4.1
| | | +-- defs@1.1.1
| | | | +-- alter@0.2.0
| | | | | `-- stable@0.1.5
| | | | +-- ast-traverse@0.1.1
| | | | +-- breakable@1.0.0
| | | | +-- simple-fmt@0.1.0
| | | | +-- simple-is@0.2.0
| | | | +-- stringmap@0.2.2
| | | | +-- stringset@0.2.1
| | | | +-- tryor@0.1.2
| | | | `-- yargs@3.27.0
| | | | +-- camelcase@1.2.1
| | | | +-- cliui@2.1.0
| | | | | +-- center-align@0.1.3
| | | | | | +-- align-text@0.1.4
| | | | | | | `-- longest@1.0.1
| | | | | | `-- lazy-cache@1.0.4
| | | | | +-- right-align@0.1.3
| | | | | `-- wordwrap@0.0.2
| | | | +-- decamelize@1.2.0
| | | | +-- os-locale@1.4.0
| | | | | `-- lcid@1.0.0
| | | | | `-- invert-kv@1.0.0
| | | | +-- window-size@0.1.4
| | | | `-- y18n@3.2.1
| | | +-- esprima-fb@15001.1001.0-dev-harmony-fb
| | | +-- recast@0.10.33
| | | | +-- ast-types@0.8.12
| | | | `-- source-map@0.5.6
| | | `-- through@2.3.8
| | +-- regexpu@1.3.0
| | | +-- esprima@2.7.2
| | | +-- regenerate@1.3.1
| | | +-- regjsgen@0.2.0
| | | `-- regjsparser@0.1.5
| | | `-- jsesc@0.5.0
| | +-- repeating@1.1.3
| | +-- resolve@1.1.7
| | +-- shebang-regex@1.0.0
| | +-- source-map@0.5.6
| | +-- source-map-support@0.2.10
| | | `-- source-map@0.1.32
| | +-- to-fast-properties@1.0.2
| | +-- trim-right@1.0.1
| | `-- try-resolve@1.0.1
| +-- chokidar@1.6.0
| | +-- anymatch@1.3.0
| | | +-- arrify@1.0.1
| | | `-- micromatch@2.3.11
| | | +-- arr-diff@2.0.0
| | | | `-- arr-flatten@1.0.1
| | | +-- array-unique@0.2.1
| | | +-- braces@1.8.5
| | | | +-- expand-range@1.8.2
| | | | | `-- fill-range@2.2.3
| | | | | +-- is-number@2.1.0
| | | | | +-- isobject@2.1.0
| | | | | +-- randomatic@1.1.5
| | | | | `-- repeat-string@1.5.4
| | | | +-- preserve@0.2.0
| | | | `-- repeat-element@1.1.2
| | | +-- expand-brackets@0.1.5
| | | | `-- is-posix-bracket@0.1.1
| | | +-- extglob@0.3.2
| | | +-- filename-regex@2.0.0
| | | +-- kind-of@3.0.4
| | | | `-- is-buffer@1.1.4
| | | +-- normalize-path@2.0.1
| | | +-- object.omit@2.0.0
| | | | +-- for-own@0.1.4
| | | | | `-- for-in@0.1.5
| | | | `-- is-extendable@0.1.1
| | | +-- parse-glob@3.0.4
| | | | +-- glob-base@0.3.0
| | | | `-- is-dotfile@1.0.2
| | | `-- regex-cache@0.4.3
| | | +-- is-equal-shallow@0.1.3
| | | `-- is-primitive@2.0.0
| | +-- async-each@1.0.0
| | +-- glob-parent@2.0.0
| | +-- inherits@2.0.1
| | +-- is-binary-path@1.0.1
| | | `-- binary-extensions@1.5.0
| | +-- is-glob@2.0.1
| | | `-- is-extglob@1.0.0
| | `-- readdirp@2.1.0
| | +-- minimatch@3.0.2
| | +-- readable-stream@2.1.4
| | | `-- buffer-shims@1.0.0
| | `-- set-immediate-shim@1.0.1
| +-- convert-source-map@1.3.0
| +-- fs-readdir-recursive@0.1.2
| +-- glob@5.0.15
| | +-- inflight@1.0.5
| | | `-- wrappy@1.0.2
| | `-- once@1.3.3
| +-- lodash@3.10.1
| +-- output-file-sync@1.1.2
| | `-- graceful-fs@4.1.5
| +-- path-exists@1.0.0
| +-- path-is-absolute@1.0.0
| +-- slash@1.0.0
| `-- source-map@0.4.4
| `-- amdefine@1.0.0
+-- chalk@1.1.3
| +-- ansi-styles@2.2.1
| +-- escape-string-regexp@1.0.5
| +-- has-ansi@2.0.0
| | `-- ansi-regex@2.0.0
| +-- strip-ansi@3.0.1
| `-- supports-color@2.0.0
+-- co@4.6.0
+-- co-request@1.0.0
+-- commander@2.9.0
| `-- graceful-readlink@1.0.1
+-- detect-port@1.0.0
| `-- commander@2.8.1
+-- ios-simulator@1.0.7
| `-- plist@1.2.0
| +-- base64-js@0.0.8
| +-- util-deprecate@1.0.2
| +-- xmlbuilder@4.0.0
| `-- xmldom@0.1.22
+-- koa@1.2.1
| +-- accepts@1.3.3
| | `-- negotiator@0.6.1
| +-- composition@2.3.0
| | `-- any-promise@1.3.0
| +-- content-disposition@0.5.1
| +-- content-type@1.0.2
| +-- cookies@0.6.1
| | +-- depd@1.1.0
| | `-- keygrip@1.0.1
| +-- debug@2.2.0
| | `-- ms@0.7.1
| +-- delegates@1.0.0
| +-- destroy@1.0.4
| +-- error-inject@1.0.0
| +-- escape-html@1.0.3
| +-- fresh@0.3.0
| +-- http-assert@1.2.0
| | +-- deep-equal@1.0.1
| | `-- http-errors@1.4.0
| +-- http-errors@1.5.0
| | `-- setprototypeof@1.0.1
| +-- koa-compose@2.4.0
| +-- koa-is-json@1.0.0
| +-- mime-types@2.1.11
| | `-- mime-db@1.23.0
| +-- on-finished@2.3.0
| | `-- ee-first@1.1.1
| +-- only@0.0.2
| +-- parseurl@1.3.1
| +-- statuses@1.3.0
| +-- type-is@1.6.13
| | `-- media-typer@0.3.0
| `-- vary@1.1.0
+-- koa-bodyparser@2.2.0
| +-- co-body@4.2.0
| | +-- inflation@2.0.0
| | +-- qs@4.0.0
| | `-- raw-body@2.1.7
| | +-- bytes@2.4.0
| | +-- iconv-lite@0.4.13
| | `-- unpipe@1.0.0
| `-- copy-to@2.0.1
+-- koa-router@5.4.0
| +-- methods@1.1.2
| `-- path-to-regexp@1.5.3
| `-- isarray@0.0.1
+-- koa-static@2.0.0
| `-- koa-send@3.1.1
| +-- mz@2.4.0
| | `-- thenify-all@1.6.0
| | `-- thenify@3.2.0
| `-- resolve-path@1.3.2
+-- macaca-adb@1.0.17
| `-- macaca-utils@0.1.8
+-- npm-update@1.0.2
| `-- co-request@0.2.1
+-- react@15.3.0
| +-- fbjs@0.8.3
| | +-- immutable@3.8.1
| | +-- isomorphic-fetch@2.2.1
| | | +-- node-fetch@1.6.0
| | | | +-- encoding@0.1.12
| | | | `-- is-stream@1.1.0
| | | `-- whatwg-fetch@1.0.0
| | +-- promise@7.1.1
| | | `-- asap@2.0.4
| | `-- ua-parser-js@0.7.10
| +-- loose-envify@1.2.0
| `-- object-assign@4.1.0
+-- react-dom@15.3.0
+-- request@2.74.0
| +-- aws-sign2@0.6.0
| +-- aws4@1.4.1
| +-- bl@1.1.2
| | `-- readable-stream@2.0.6
| | +-- core-util-is@1.0.2
| | +-- isarray@1.0.0
| | +-- process-nextick-args@1.0.7
| | `-- string_decoder@0.10.31
| +-- caseless@0.11.0
| +-- combined-stream@1.0.5
| | `-- delayed-stream@1.0.0
| +-- extend@3.0.0
| +-- forever-agent@0.6.1
| +-- form-data@1.0.0-rc4
| | `-- async@1.5.2
| +-- har-validator@2.0.6
| | +-- is-my-json-valid@2.13.1
| | | +-- generate-function@2.0.0
| | | +-- generate-object-property@1.2.0
| | | | `-- is-property@1.0.2
| | | +-- jsonpointer@2.0.0
| | | `-- xtend@4.0.1
| | `-- pinkie-promise@2.0.1
| | `-- pinkie@2.0.4
| +-- hawk@3.1.3
| | +-- boom@2.10.1
| | +-- cryptiles@2.0.5
| | +-- hoek@2.16.3
| | `-- sntp@1.0.9
| +-- http-signature@1.1.1
| | +-- assert-plus@0.2.0
| | +-- jsprim@1.3.0
| | | +-- extsprintf@1.0.2
| | | +-- json-schema@0.2.2
| | | `-- verror@1.3.6
| | `-- sshpk@1.9.2
| | +-- asn1@0.2.3
| | +-- assert-plus@1.0.0
| | +-- dashdash@1.14.0
| | | `-- assert-plus@1.0.0
| | +-- ecc-jsbn@0.1.1
| | +-- getpass@0.1.6
| | | `-- assert-plus@1.0.0
| | +-- jodid25519@1.0.2
| | +-- jsbn@0.1.0
| | `-- tweetnacl@0.13.3
| +-- is-typedarray@1.0.0
| +-- isstream@0.1.2
| +-- json-stringify-safe@5.0.1
| +-- node-uuid@1.4.7
| +-- oauth-sign@0.8.2
| +-- qs@6.2.1
| +-- stringstream@0.0.5
| +-- tough-cookie@2.3.1
| `-- tunnel-agent@0.4.3
+-- uiautomator-client@1.0.16
| +-- ant-lite@1.0.1
| +-- java-home@1.0.2
| `-- win-spawn@2.0.0
+-- webdriveragent@1.0.19
| `-- adm-zip@0.4.7
+-- xctest-client@1.0.17
| +-- ios-utils@1.0.1
| | `-- bplist-parser@0.1.1
| | `-- big-integer@1.6.15
| +-- request@2.69.0
| | +-- bl@1.0.3
| | | `-- readable-stream@2.0.6
| | +-- qs@6.0.2
| | `-- tough-cookie@2.2.2
| `-- webdriver-dfn-error-code@1.0.3
+-- xlogger@1.0.4
+-- xml2map@1.0.2
| +-- sax@0.4.2
| `-- xml-writer@1.6.0
`-- xutil@1.0.1
+-- ipv4@0.0.4
+-- mkdirp@0.5.1
| `-- minimist@0.0.8
+-- moment@2.10.6
`-- rimraf@2.5.4
`-- glob@7.0.5
+-- fs.realpath@1.0.0
`-- minimatch@3.0.2
npm WARN optional Skipping failed optional dependency /app-inspector/chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.14
如此日志便说明 app-inspector 安装成功了。
C:\Users\cmd>app-inspector -v
1.0.8
https://github.com/xudafeng/app-inspector
我启动的是 Genymotion 模拟器,然后执行 adb devices -l 命令找到设备 udid 如果是虚拟器的话 udid 实际是 ip:port 形式。
C:\Users\cmd>adb devices -l
List of devices attached
192.168.236.101:5555 device product:vbox86p model:Samsung_Galaxy_S6_5_1_0API_22__1440x2560 device:vbox86p
C:\Users\cmd>app-inspector -u 192.168.236.101:5555
inspector start at: http://*.*.*.*:5678
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stream=
com.android.uiautomator.client.Initialize:
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: test=testStartServer
INSTRUMENTATION_STATUS: class=com.android.uiautomator.client.Initialize
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS_CODE: 1
uiautomator start socket server.
socket server ready
socket client ready
根据日志 发现 该行 inspector start at: http://...:5678
发现居然是个外网 IP 我以为应该是和 udid 一样的 IP 192.168.236.101:5555 可惜不是,所以我用... 来代替下。
新开个谷歌浏览器,输入该地址 http://...:5678 回车。
接下来 你就可以 打开那个示例程序 Android Bootstrap 操作几下,效果如下图,在浏览器里就 inspect 到 UI 元素了。