How to lcoate a specific context menu item using androidx.test.uiautomator?


I am developing a few UI tests using Android's UIAutomator. For one of them I want to long-click an item and then select a menu-entry from the appearing Context-Menu of said item. I would prefer to be able to select the menu-item using the id from the "R"-file (like "R.id.xyz"), i.e. I want to be able to write something like

	item.longClick(); // select item's context menu
	UiObject2 menuEntry = findMenuEntry(device, R.id.ctxt_duplicate);
	menuEntry.click();

where findMenuEntry() would be a utility method like:

	public static UiObject2 findMenuEntry(final UiDevice device, final int id) {
		final SearchCondition<UiObject2> condition =
			Until.findObject(By.clazz(android.view.MenuItem.class).????(id))
		return device.wait(condition, 3000);
	}

I am missing a search-condition (here marked with "????") that I can pass a widget's "id".

Is that feasible? If not: what would be a suggested alternative approach?

NB: I know one can search UiObjects(2) for a widget's "description" but that would require the assignment of descriptions and keeping track of yet another unique designator for each UI element. The ids are already there and are unique (in our environment and per Activity at least...).

0
Nov 23 at 5:24 PM
User Avatarmmo
#android#ui-automation

No answer found for this question yet.