2014-10-27 12 views

Trả lời

17

Sử dụng adb shell uiautomator dump lệnh:

Usage: uiautomator <subcommand> [options] 

Available subcommands: 

help: displays help message 

runtest: executes UI automation tests 
    runtest <class spec> [options] 
    <class spec>: <JARS> < -c <CLASSES> | -e class <CLASSES> > 
     <JARS>: a list of jar files containing test classes and dependencies. If 
     the path is relative, it's assumed to be under /data/local/tmp. Use 
     absolute path if the file is elsewhere. Multiple files can be 
     specified, separated by space. 
     <CLASSES>: a list of test class names to run, separated by comma. To 
     a single method, use TestClass#testMethod format. The -e or -c option 
     may be repeated. This option is not required and if not provided then 
     all the tests in provided jars will be run automatically. 
    options: 
     --nohup: trap SIG_HUP, so test won't terminate even if parent process 
       is terminated, e.g. USB is disconnected. 
     -e debug [true|false]: wait for debugger to connect before starting. 
     -e runner [CLASS]: use specified test runner class instead. If 
     unspecified, framework default runner will be used. 
     -e <NAME> <VALUE>: other name-value pairs to be passed to test classes. 
     May be repeated. 
     -e outputFormat simple | -s: enabled less verbose JUnit style output. 

dump: creates an XML dump of current UI hierarchy 
    dump [--verbose][file] 
     [--compressed]: dumps compressed layout information. 
     [file]: the location where the dumped XML should be stored, default is 
     /storage/emulated/legacy/window_dump.xml 

events: prints out accessibility events until terminated 

Theo mặc định nó bãi hệ thống phân cấp xem để $EXTERNAL_STORAGE/window_dump.xml

adb shell uiautomator dump 
UI hierchary dumped to: /sdcard/window_dump.xml 

Thông thường, bạn sẽ muốn kéo tập tin này vào máy tính của bạn để chế biến tiếp đó sẽ là một phụ bậc thang. Nhưng có một thủ thuật gọn gàng cho phép kết hợp bán phá giá và kéo vào một lệnh duy nhất. Sử dụng /dev/tty như một điểm đến bãi sẽ làm cho một lệnh duy nhất mà sẽ in toàn bộ bãi đến stdout:

adb exec-out uiautomator dump /dev/tty 
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><hierarchy rotation="0"><node ...></node></hierarchy>UI hierchary dumped to: /dev/tty 
+1

Muốn thêm ghi chú chỉ có một khách hàng UIAutomator có thể chạy hoặc lệnh sẽ xuất "bị giết" và không hoạt động. Tôi đã stumped bởi điều này cho đến khi tôi phát hiện ra tôi đã bị chặn bằng cách chạy thử nghiệm bằng cách sử dụng một kết nối UIAutomator mở. –

+1

@ Alex Tôi đã thử chạy lệnh ui automator dump để có được hệ thống phân cấp ui từ trình giả lập Android, nhưng có vẻ như tôi không nhận được kết xuất hoàn chỉnh. Tôi đang làm gì sai? Tôi đang cố gắng để có được bãi chứa cho các hoạt động của UCBrowser chạy trong giả lập Android để tôi có thể nhận được các ràng buộc của một nút/mục để click. Tôi cũng đã hỏi một câu hỏi về SO liên quan đến cùng ở đây - http://stackoverflow.com/questions/43780490/automate-the-installation-of-ucbrowser – Jignesh

+1

Bí quyết tuyệt vời với '/ dev/tty' –

2
adb pull $(adb shell uiautomator dump | grep -oP '[^ ]+.xml') /tmp/view.xml 

mở /tmp/view.xml trong một trình duyệt web như:

google-chrome /tmp/view.xml 

exec adb -out uiautomator dump/dev/tty

từ câu trả lời khác đã không làm việc cho tôi.

+0

trong máy tính của tôi không hoạt động. tôi thay đổi thành 'adb pull $ (adb shell uiautomator dump | egrep -o '/.*? xml')' – chinaanihchen

1

tôi đã sử dụng sau đây trên một máy Mac để in xml định dạng để giao diện điều khiển:

adb shell uiautomator dump && adb pull /sdcard/window_dump.xml $TMPDIR && more $TMPDIR/window_dump.xml | xmllint --format -

Bạn có thể cần phải thay đổi đường dẫn của tập tin /sdcard/window_dump.xml để kéo dựa trên nơi các tập tin xml được đổ. Công cụ

1

AndroidViewClient/culebra 's dump cho phép bạn làm chính xác điều đó. AndroidViewClient có thể được sử dụng làm thư viện và cũng cung cấp một số công cụ như dumpculebra.

usage: dump [OPTION]... [serialno] 

Options: 
    -H, --help      prints this help        
    -V, --verbose     verbose comments        
    -v, --version 
    -I, --ignore-secure-device  ignore secure device       
    -E, --ignore-version-check  ignores ADB version check      
    -F, --force-view-server-use  force view server use (even if UiAutomator present:w) 
    -S, --do-not-start-view-server don't start ViewServer      
    -k, --do-not-ignore-uiautomator-killed don't ignore UiAutomator killed    
    -w, --window=WINDOW    dump WINDOW content (default: -1, all windows) 
    -a, --all      dump all information about Views    
    -i, --uniqueId     dump View unique IDs       
    -x, --position     dump View positions       
    -b, --bounds      dump View bounds        
    -d, --content-description  dump View content descriptions    
    -g, --tag      dump View tags        
    -c, --center      dump View centers        
    -f, --save-screenshot=FILE  save screenshot to file      
    -W, --save-view-screenshots=DIR save View screenshots to files in directory 
    -D, --do-not-dump-views   don't dump views, only useful if you specified -f or -W 
    -A, --device-art=MODEL   device art model to frame screenshot (auto: autodetected) 
    -Z, --drop-shadow    drop shadow for device art screenshot   
    -B, --glare      screen glare over screenshot     
    -h, --use-uiautomator-helper  use UiAutomatorHelper Android app    
    -X, --debug=LIST     debug options 

chạy dump không có tùy chọn, chỉ cần in cây Số lượt xem và một số tính chất cơ bản của nó, giống như ID

android.widget.FrameLayout 
    com.android.launcher3.Workspace com.google.android.apps.nexuslauncher:id/workspace 
     android.widget.FrameLayout com.google.android.apps.nexuslauncher:id/workspace_blocked_row 
     android.widget.TextView com.google.android.apps.nexuslauncher:id/date_text1 May 1 
     android.widget.TextView com.google.android.apps.nexuslauncher:id/date_text2 MONDAY, 2017 
     android.widget.TextView Maps 
    android.widget.ImageView com.google.android.apps.nexuslauncher:id/g_icon 
    android.widget.ImageView com.google.android.apps.nexuslauncher:id/all_apps_handle 
    android.view.ViewGroup com.google.android.apps.nexuslauncher:id/layout 
     android.widget.TextView Messenger 
     android.widget.TextView Chrome 

Mặt khác, nếu bạn muốn vị trí của các quan điểm, bạn có thể chạy

$ đổ -x

android.widget.FrameLayout (0, 0, 1440, 2392) 
    com.android.launcher3.Workspace com.google.android.apps.nexuslauncher:id/workspace (0, 0, 1440, 2392) 
     android.widget.FrameLayout com.google.android.apps.nexuslauncher:id/workspace_blocked_row (30, 126, 1380, 372) 
     android.widget.TextView com.google.android.apps.nexuslauncher:id/date_text1 May 1 (1037, 194, 337, 162) 
     android.widget.TextView com.google.android.apps.nexuslauncher:id/date_text2 MONDAY, 2017 (1092, 356, 282, 73) 
     android.widget.TextView Maps (30, 1614, 276, 372) 
    android.widget.ImageView com.google.android.apps.nexuslauncher:id/g_icon (30, 214, 276, 196) 
    android.widget.ImageView com.google.android.apps.nexuslauncher:id/all_apps_handle (636, 1986, 168, 98) 
    android.view.ViewGroup com.google.android.apps.nexuslauncher:id/layout (0, 2084, 1440, 308) 
     android.widget.TextView Messenger (306, 2112, 276, 280) 
     android.widget.TextView Chrome (858, 2112, 276, 280) 

Các tùy chọn này sẽ cung cấp cho bạn kiểm soát đầu ra. Bạn có thể nhận thêm một số thông tin here.

Các vấn đề liên quan