How use Espresso viewMatcher in java client

Recently, I switched from UIAutoimator2 to Espresso and I am trying to rewrite some non-standard selectors.

For example I was using selector to search by text:

(driver as AndroidDriver<*>).findElementByAndroidUIAutomator("new UiSelector().textContains(\"$text\")") as MobileElement

but this does not seems to work when I use Espresso (InvalidSelectorException: Locator strategy cannot be empty)

Then I tried to use Espresso viewMatcher strategy and withText method like so:

(driver as AndroidDriver<*>).findElementByAndroidViewMatcher(Json().toJson(
       "name", "withText",
       "args", text
)) as MobileElement

but I am getting error No such method: withText() on class: org.hamcrest.Matchers' even that I am following Espresso documentation

I have two questions:

  1. Am I still able to use UIAutomator2 selectors without using mobile: uiautomator command?
  2. How to use viewMatcher correctly?
  3. How to use dataMatcher correctly?

Appium’s documentation for view/data matchers in Espresso are almost nonexistant. And If there is some documentation, it is not for java-client

Yes, the documentation is far from great there. We accept any PR that may improve/add on it.

Here you have some function test examples: