How can I test a click at a certain x,y coordinate?

For running tests on an Android app, how can I automate the tap on ax,y coordinate of either the view or the screen?

I am hoping that there is some call in ActivityInstrumentationTestCase2 or TouchUtils, but haven't found one yet.


So, this I haven't tried, but giving a look through the documentation, you might be able to do something to this effect:

  • Capture an ACTION_DOWN MotionEvent (through the debugger from a touch action) and note its properties (down time, event time, and the meta state). This would only need to be done once to figure out what sort of values you should use to simulate a typical touch event.

  • In your test program, create a new MotionEvent with MotionEvent.obtain()

    MotionEvent newTouch = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, x, y, metaState);

  • Dispatch the event on your view:

    view.dispatchTouchEvent(newTouch);

  • 链接地址: http://www.djcxy.com/p/59194.html

    上一篇: Ruby ruby​​ 1.8上的WEBrick错误,在Ruby 1.9上正常工作

    下一篇: 我如何测试某个x,y坐标的点击?