Of course, to do it I would resort to our old pal AndroidViewClient. This is a very interesting example of its use because it lies far from testing and application or UI.
And so, without further ado, let me introduce you to the code...
And now a brief explanation of the most important pieces of this script.
- Shebang, you know, to invoke monkeyrunner as the interpreter. I don't have to tell you more (if you are a poor Windows user you may have to invoke monkeyrunner from command line, I feel sad for you)
- Some comments and imports
- Read PYTHONPATH just in case you are using Eclipse and Pydev (this has been explained in this post)
- Then use ANDROID_VIEW_CLIENT_HOME environment variable to find AndroidViewClient in your system
- The standard way of connecting to the device or emulator in AndroidViewClient. This handles errors and timeout automatically solving many problems you find with bare monkeyrunner
- We start Browser
- Drag a bit to make the URL visible in case the page has scrolled
- Next, we find the View with ID id/url, which you know, contains the URL
- We touch to focus
- By that time the alert dialog should be on screen so we take a new dump
- Now we find the View with ID id/message which contains the HTML and print it
- Finally, we press BACK to dismiss it
I hope you have enjoyed it as much as I did and this help you find new ways of using AndroidViewClient.
P.S. This script will be part of AndroidViewClient source code distribution examples