Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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.

like image 595
Crazy Man Avatar asked May 02 '12 19:05

Crazy Man


People also ask

How do you find coordinates in click?

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.

How do you check X and Y?

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.

What are the XY coordinates on screen?

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.

How do you click coordinates in Javascript?

elementFromPoint(x, y). click();


1 Answers

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

  1. 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.

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

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

  3. Dispatch the event on your view:

    view.dispatchTouchEvent(newTouch);

like image 162
Kevin Coppock Avatar answered Sep 21 '22 17:09

Kevin Coppock