Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso - Set SeekBar

does anybody know, how to set a seekBar to a specific value or just a click on that view on Espresso UI Testing ?

I just get an exception: Error performing 'single click' on view with id...

onView(withId(R.id.FilterPriceMax)).perform(click());
like image 398
Luser_k Avatar asked May 14 '14 15:05

Luser_k


1 Answers

You might want to give the following code a try:

First you could match the SeekBar with its class name:

onView(withClassName(Matchers.equalTo(SeekBar.class.getName()))).perform(setProgress(progress));

where setProgress(final int progress) is a ViewAction you defined as:

public static ViewAction setProgress(final int progress) {
        return new ViewAction() {
            @Override
            public void perform(UiController uiController, View view) {
                SeekBar seekBar = (SeekBar) view;
                seekBar.setProgress(progress);
            }
            @Override
            public String getDescription() {
                return "Set a progress on a SeekBar";
            }
            @Override
            public Matcher<View> getConstraints() {
                return ViewMatchers.isAssignableFrom(SeekBar.class);
            }
        };
    }
like image 170
Luigi Massa Gallerano Avatar answered Oct 23 '22 11:10

Luigi Massa Gallerano