Using Espresso to Unit Test Google Maps

Using Espresso to Unit Test Google Maps

Short Answer:
With espresso is not really possible.
A solution might be to use UIAutomator:
https://developer.android.com/tools/testing-support-library/index.html#UIAutomator
https://developer.android.com/training/testing/ui-testing/uiautomator-testing.html

So you need to:

1) add gradle dependencies:

dependencies {
androidTestCompile 'com.android.support.test:runner:0.2'
androidTestCompile 'com.android.support.test:rules:0.2'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1' }

2) make sure you add at least title to your markers even if you're not using it.

3) Write the test, code is smth like this:

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

Explanation:

GoogleMap generates UI and also makes it accessible i.e. map content can be seen as a tree of accessibility node info.

This is tree is a virtual view tree, it does not represent the real view tree.
We will come to this later

By default the contentDescription of the map is "Google Map" and that of markers is "{markerTitle}. {markerSnippet}".

Then the question is so why not using espresso:

onView(withContentDescription("marker title. ")).perform(click());
?

Because it won't find it, however :

onView(withContentDescription("Google Map")).perform(click());

will work just fine.

So how come UIAutomator works and Espresso doesn't?

Because they use different view trees.

UIAutomator uses tree of accessibility node info provided by AccessibilityService, while Espresso uses the view hierarchy and thus processes all children of any ViewGroup. The accessibility node info and the view hierarchy may or may not map one-to-one.
In this case

onView(withContentDescription("Google Map"))

finds not a ViewGroup but a TextureView, which is not known to have children so Espresso cannot know what is drawn in there.

Voila! :)

Espresso with mock location : avoid Google's experience popup

What you are seeing may be a bug in Firebase Test Lab if it is happening on certain devices but works on others. E.g. works on a physical Samsung device but does not work on a physical HTC device. Or works on all physical devices but does not work on virtual devices.

Since I cannot message you directly on Stack Overflow, I encourage you to join the Firebase Test Lab Slack channel (#test-lab) on https://firebase-community.slack.com/.

There will be Firebase engineers actively investigating issues that you are seeing and look directly at the test runs you have run in your project.

Android, how to test Google Map

The best way is UiAutomator library ,
https://developer.android.com/training/testing/ui-testing/uiautomator-testing.html

private UiDevice uiDevice = UiDevice.getInstance(getInstrumentation());
private UiObject mMarker1 = uiDevice.findObject(new UiSelector().descriptionContains("The title of marker"));
try {
mMarker1.click();
} catch (UiObjectNotFoundException e) {

e.printStackTrace();
}

for taping on map you can use this

uiDevice.click(x, y);

x and y are the coordinates

Android ui test with espresso cannot use fresco SimpleDreweeView

In your case writing

@Override
public void onCreate() {
super.onCreate();
Fresco.initialize(this);
setContentView(R.layout.activity_image_viewer);
}


Related Topics



Leave a reply



Submit