I want to test android apps for accessibility violation. Is it possible to use uiautomator api and monkeyrunner api to capture the layout of all screens?
You can simply use AndroidViewClient's dump:
$ dump --help
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)
-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)
-i, --uniqueId dump View unique IDs
-x, --position dump View positions
-d, --content-description dump View content descriptions
-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
In you case, probably
$ dump -d
is enough.
If you want something more complex than just saving the logical content of the screen, you can use culebra
(another tool in AndroidViewClient) that allows you to generate automated tests using a GUI:
$ culebra -UG -o mytest.py
You can interact with the mirror representation of the device screen in culebra's main window to generate the test. Save it. Run it on any device, even a completely different one.