9

The Espresso's method pressBack() is totally ignored. I'm running the test on the emulator.

What I'm testing? Just calling an Activity, launching a second one, performing two backs, and checking that I'm out of the app.

Roc Boronat
  • 11,395
  • 5
  • 47
  • 59

2 Answers2

18

Use

import static android.support.test.espresso.Espresso.pressBack;

or

import static androidx.test.espresso.Espresso.pressBack;

instead of

import static android.support.test.espresso.action.ViewActions.pressBack;

Roc Boronat
  • 11,395
  • 5
  • 47
  • 59
3

Another solution there:

Stop using regular Espresso and start using Barista. There, clicking the back button is clickBack() instead of pressBack(), so it will never conflict with anything.

... and well, Barista gives a lot of more features, but I just got some karma points for this question, and asked myself why am I not having this issue anymore? Oh, because of Barista! I should introduce it here.

Feel free to check it out: https://github.com/AdevintaSpain/Barista

Roc Boronat
  • 11,395
  • 5
  • 47
  • 59
  • As far as I understand the only thing that Barista does, in this case, is calling Espresso "pressBack" method. – Jakub Mosakowski Nov 23 '20 at 22:30
  • 1
    Totally, but thanks to the name change, it won't conflict with Espresso's ViewAction, which compiles but does nothing but driving you mad. It's just a convenient method that makes life an easier place to be. Actually, the whole Barista library is just a convenient thing to make life better, haha! – Roc Boronat Nov 24 '20 at 09:22