1

I have a bunch of EditTexts, and each one is supposed to focus on the next when something is typed into them. My test checks that this happens:

onView(withId(R.id.textBox1)).perform(typeText("1"));
onView(withId(R.id.textBox2)).check(matches(hasFocus()));

When I run the app by clicking 'run', it fails saying hasFocus wasn't true. Why is this?

Questioner
  • 2,451
  • 4
  • 29
  • 50
  • Put `Thread.sleep(200);` before `hasFocus()` line and see what happens. – azizbekian Oct 09 '17 at 12:49
  • Thread.sleep doesn't sleep it and neither does the SystemClock sleep method. I also tried the solution at https://stackoverflow.com/a/22563297/4838107 and it didn't work either. Is there a way of making it wait for the actions to finish instead of guessing a time in milliseconds? – Questioner Oct 09 '17 at 13:57
  • The magic of espresso is, that it waits autimatically, and where there are no more actions to apply - only then matchers are executed. Though, sometimes weird things happen. – azizbekian Oct 09 '17 at 14:11
  • How do I fix this weird thing then? – Questioner Oct 09 '17 at 15:16
  • @azizbekian It just failed when I ran it without debug now – Questioner Oct 10 '17 at 08:45

2 Answers2

0

I switched my SwiftKey keyboard back to the default keyboard on my phone, and now the test passes.

Questioner
  • 2,451
  • 4
  • 29
  • 50
0

I've also experienced test failures recently using SwiftKey. After switching to GBoard they work. They used to work before with SwiftKey so I think that they changed something recently. I also can see that when using typeText() action SwiftKey automatically corrects words although it has autocorrection disabled.

LukaszS
  • 586
  • 1
  • 4
  • 6