1

I'm trying to interact with a SeekBar control in an Espresso test. Specifically, I'd like to click at the location of a "node", where a node is a location that the draggable thumb can snap to.

The UI tree has no knowledge of the SeekBar internals. It doesn't seem possible to use Espresso to target one of the nodes directly; all it sees is a SeekBar.

Instead, I wonder if I could use the Accessibility tree that exists for TalkBack support. The uiautomatorviewer tool confirms that this tree contains a virtual view for each node. Each virtual view has a content description.

uiautomatorviewer

My goal is to get a hold on one of these virtual views in a matcher and perform a click on it. Something like...

onVirtualView(withContentDescription("banana")).perform(click());

where onVirtualView would be similar to onView. I don't know how to programmatically access this Accessibility tree and if it's possible to trigger actions on it. Can someone shed light on the feasibility of this technique?

I'm aware of the approach that sets the progress value (Espresso - Set SeekBar). I'm trying to avoid that method as I want the test to be flexible to changes to the number in the number of slots.

Community
  • 1
  • 1
siger
  • 3,112
  • 1
  • 27
  • 42

1 Answers1

0

You can specify the child view (virtual view) by index. Something like this:

onView(nthChildOf(withId(R.id.seekbar), 1)).perform(click());

So here you are clicking at second child (index is 1) of SeekBar. nthChildOf is a special Matcher that allows you to reference a child. You can find it sources and more details here - http://droidtestlab.com/additions.html

  • `SeekBar` is not a `ViewGroup` and it doesn't have children in the UI tree. This matcher wouldn't work. In addition, I'm trying to avoid relying on a magic constant (`1`) in my test. I'd rather identify the child by content description or id. – siger Mar 11 '16 at 18:03