1

I am trying to write an automated test for my map based Android application that uses the v2 GoogleMaps.

I need to be able to programmatically recreate the effect of a user taping a map marker so I can verify other UI activities occur.

I have looked into using Robotium however, the extensions available for GoogleMaps only support v1 and I am using v2. Espresso doesn't seem to have any support at all for GoogleMaps so I am left with either adding my own extensions or using plain ActivityInstrumentationTestCase2 implementations.

Any ideas?

Marc Thomas
  • 393
  • 1
  • 3
  • 16
  • what framework are you using for your testes ? Can you show how you trying that ? – PedroAGSantos Sep 09 '14 at 15:24
  • The framework I am attempting to use is just plain testing using a class that is extending ActivityInstrumentationTestCase2 – Marc Thomas Sep 10 '14 at 12:08
  • I think you would like to take a look at https://code.google.com/p/robotium/ and the extension https://github.com/nalbion/robotium-maps – PedroAGSantos Sep 10 '14 at 13:25
  • I took a look at, however, that only works for the Google Maps v1 not v2. The author hasn't found a way around the issues with testing on the v2 platform yet. – Marc Thomas Sep 26 '14 at 11:26
  • Oh sorry Marc :( testing in android is painful but if you managed to do it just let me know. I will ask some friends tho. – PedroAGSantos Sep 26 '14 at 13:37

2 Answers2

0

Do this work for you?

Projection projection = map.getProjection();
LatLng markerLocation = marker.getPosition();
Point screenPosition = projection.toScreenLocation(markerLocation);
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 100;
        MotionEvent motionEvent = MotionEvent.obtain(
                downTime,
                eventTime,
                MotionEvent.ACTION_UP,
                screenPosition.x,
                screenPosition.y,
                0
        );
        mapView.dispatchTouchEvent(motionEvent);
Pedro Oliveira
  • 20,442
  • 8
  • 55
  • 82
  • I did try this however, the MotionEvents didn't have any affect on the map. It could be because the test exited too early, but my code that should be triggered on marker click wasn't executed. I will investigate further. – Marc Thomas Oct 02 '14 at 14:33
0

Use UIAutomator:

UiDevice device = UiDevice.getInstance(getInstrumentation());
UiObject marker = device.findObject(new UiSelector().descriptionContains("marker title"));
marker.click();

my complete answer: Using Espresso to Unit Test Google Maps

Community
  • 1
  • 1
kalin
  • 3,546
  • 2
  • 25
  • 31