androidtestingmonkeyrunner

MonkeyRunner: easy way to determine coordinates for MonkeyDevice touch command?


I've started creating a MonkeyRunner script. This is going ok, but whenever I add a MonkeyDevice::touch command, I have to determine the input coordinates by trial-and-error. Basically I guess at the coordinates I want to touch and see if those coordinates result in the button touch I'm trying to test. That works, but it's a slow process. Is there anyway to determine the coordinates of UI controls, perhaps from the layout XML files?


Solution

  • I found how to do it. Use the Pixel Perfect view within Eclipse to determine the x & y coordinates of the UI element. Here's a quick overview: 1) Eclipse must be running 2) Your Android device must be connected (either the real device via ADB, or the emulator) 3) Run the hierarchy viewer (in /tools) 4) Select "Inspect screenshot" The Pixel Perfect view will launch automatically. Just place the cross-hairs on the UI element. The x and y coordinates, along with the RGB values, are displayed below.

    Here's the URL that got me started: http://developer.android.com/guide/developing/debugging/debugging-ui.html#pixelperfect