0

Say I have two tests.

Each of them interacts with a spinner:

  • The first one clicks on it and fails.
  • The second one launches and also clicks a spinner(willing to open it) and now it is closed and onData() fails.

Tests must be independent.

What @Before method can i write to make sure spinner is closed on test start?

Ivan
  • 1,320
  • 16
  • 26
  • check this post http://stackoverflow.com/questions/7287195/android-spinner-close and this too http://stackoverflow.com/questions/18447063/spinner-get-state-or-get-notified-when-opens – Radwa Apr 11 '17 at 11:10
  • Thanks but those answers are either sad either suggest to play with some internals of an app. I hoped there are ways via instrumentation or espresso to accomplish this as it feels wrong to tweak actual code for UI testing. – Ivan Apr 11 '17 at 11:25

2 Answers2

4

This works Espresso.pressBack();

user597159
  • 185
  • 1
  • 4
1

Ugly yet works for me...

@Before
public void setUp() {
    closeSpinner();
}

private void closeSpinner() {
    try {
        onData(is(instanceOf(String.class)))
                .atPosition(0)
                .perform(click());
    } catch (Exception e) {
        //was closed
    }
}
Ivan
  • 1,320
  • 16
  • 26