2

I'm trying to make UIAutomator click the MarkerOptions on the Google Maps. This solution does not work..

build.gradle (App level)

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

TestClass

@RunWith(AndroidJUnit4.class)
public class ApplicationTest {

        UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
        UiObject marker = device.findObject(new UiSelector().descriptionContains("title_of_marker. snippet_of_marker."));
        try {
            marker.click();
        } catch (UiObjectNotFoundException e) {
            e.printStackTrace();
        }
}

MapsFragment.java

private GoogleMap mMapView;

private void loadMapLocations() {

            mMapView.addMarker(new MarkerOptions()
                    .position(new LatLng(52.0988198,5.074657))
                    .title("title_of_marker")
                    .snippet("snippet_of_marker"));
}

enter image description here

Output:

W/System.err: android.support.test.uiautomator.UiObjectNotFoundException: UiSelector[CONTAINS_DESCRIPTION=title_of_marker. snippet_of_marker.]
W/System.err:     at android.support.test.uiautomator.UiObject.click(UiObject.java:412)

I've tried everything, but don't know how to proceed now.

Community
  • 1
  • 1
Jim Clermonts
  • 1,694
  • 8
  • 39
  • 94

2 Answers2

1

I've used @Diego's example code and pasted this into my ApplicationTest.java and this works, so I don't need to use Culebra:

@Test
public void loginAndClickMarker() {

    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    final BySelector bySelector = By.clazz(Pattern.compile(".*")).desc("title_of_marker. snippet_of_marker.").pkg("www.brandmkrs.com.damageapp");
    device.wait(Until.hasObject(bySelector), DEFAULT_TIMEOUT);
    device.findObject(bySelector).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
    SystemClock.sleep(1000);
}
Jim Clermonts
  • 1,694
  • 8
  • 39
  • 94
  • I thought it was clear that CulebraTester was only mentioned to indicate where or how I generated the code. CulebraTester is a powerful to help you generate this kind of code – Diego Torres Milano Jul 21 '16 at 03:23
0

I created a sample map and added a marker similar to yours. Started CulebraTester. Started a test recording. Clicked on the marker.

enter image description here

then I just added the wait (which will be autogenerated soon) to obtain this test.

@Test
public void culebraGeneratedTest() throws Exception {
    final BySelector bySelector = By.clazz(Pattern.compile(".*")).desc("title_of_marker. snippet_of_marker.").pkg("com.example.diego.mymapapplication");
    mDevice.wait(Until.hasObject(bySelector), DEFAULT_TIMEOUT);
    mDevice.findObject(bySelector).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
}

Added the test class to the project. Run the tests. And it works!

It seems like a good opportunity to test CulebraTester code generation.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • thnx I opted in for CulebraTester. – Jim Clermonts Jul 19 '16 at 00:00
  • Tried this solution, followed this tutorial: https://www.linkedin.com/pulse/android-ui-testing-androidviewclientculebra-ahmed-kasem but this doesn't work either. – Jim Clermonts Jul 20 '16 at 21:40
  • the tutorial you mentioned is for python. The code I included in the answer is UiAutomator/Java. I tested the code and worked for me, what's not working for you? Did you change `"com.example.diego.mymapapplication"` to your pkg name? – Diego Torres Milano Jul 20 '16 at 21:44
  • Using your example method was enough, Culebra was not needed! – Jim Clermonts Jul 20 '16 at 22:14
  • I thought it was clear that CulebraTester was only mentioned to indicate where or how I generated the code. CulebraTester is a powerful to help you generate this kind of code. – Diego Torres Milano Jul 21 '16 at 03:22