2

in our app we are using Toast.makeText(context, context.getString(R.string.contact_not_present), Toast.LENGTH_SHORT).show(); to show toast message

For Ui Automation we are using https://developer.android.com/training/testing/ui-automator

While automating a use case which should fire a Toast message ,As expected the toast message was fired but i am unable to find it

I am trying to locate the element by

UiObject2 object = device.wait(Until.findObject(By.clazz("android.widget.Toast")), 9000);

But i am always getting the object as null

can anyone help me on this ?

  • It may be better to [use Espresso to check for Toast messages](https://stackoverflow.com/questions/28390574/checking-toast-message-in-android-espresso), rather than use UI Automator. But note that checking for Toasts does not work with `targetSdkVersion 30` and `Android 11 (API 30)`. See: https://github.com/android/android-test/issues/803 – Mr-IDE Dec 20 '21 at 10:35

0 Answers0