android / testing-samples

A collection of samples demonstrating different frameworks and techniques for automated testing
Apache License 2.0
9.18k stars 3.61k forks source link

UiSelector.resourceId("myButtonId") not working #147

Open umarhussain15 opened 6 years ago

umarhussain15 commented 6 years ago

I'm trying to get the facebook Login button in UIautomator but its failing to find the button given the id of the button

<com.facebook.login.widget.LoginButton
        android:id="@+id/login_button_facebook"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="0dp"
        android:layout_marginRight="0dp"
        android:layout_marginTop="0dp"/>

And here is the code how I'm accessing the button in my test case UiObject facebookButton = mDevice.findObject(new UiSelector().resourceId("login_button_facebook"));

Its failing to find the button saying :

android.support.test.uiautomator.UiObjectNotFoundException: UiSelector[RESOURCE_ID=login_button_facebook]
at android.support.test.uiautomator.UiObject.click(UiObject.java:416)

Please let me know if I'm doing it wrong. The documentation has not much detail about how to use it.

aroller commented 4 years ago

The id needs to include the package.

UiSelector().resourceId("com.example.something:id/login_button_facebook"));

This requirement is not well documented.