For running tests on an Android app, how can I automate the tap on a x,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.
The coordinates of the mouse whenever a click takes place can be found by detecting the click event with an event listener and finding the event's x and y position. A function is created which takes in the canvas element and event as parameters.
The x and y coordinates can be easily identified from the given point in the coordinate axes. For a point (a, b), the first value is always the x coordinate, and the second value is always the y coordinate.
X and y coordinates are, respectively, the horizontal and vertical addresses of a point in any two-dimensional (2D) space, such as a sheet of paper or a computer display screen. Together, these coordinates help identify the exact location of a point.
elementFromPoint(x, y). click();
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With