0

I am having trouble when testing with Robotium for an exercise on a Coursera course... I'll try to explain the better way possible for you to understand.

I have an activity with a TextView created programmatically on the onCreate method, I'm sure the View is coded right and actually, when I run the Robotium tests with my own device, it passes all the tests IF the screen is on, but if I run the tests with my screen off/device locked Robotium fails in an assertTrue with the waitForView method.

The problem is that I can't be sure the screen that run the tests in the Coursera platform is on (and it doesn't 'cause it fails with the same error I have when I try to run the tests with the screen off). I think it has something to do with Robotium... but I'm not sure what should I do to make my TextView visible in the sense Robotium can waitForView on it.

cesonha
  • 334
  • 2
  • 9

1 Answers1

0

Robotium is an instrumentation test framework, which is close to your app's UI, so it would click on button only if it sees it.

I don't know what Coursera course you're talking about, and why you're thinking that their tests are running on screen lock - which is certainly impossible, but I can swear that if you would use Espresso instead of Robotium it would also fail.

Find on your phone/emulator function Stay awake.

You may need first to unlock 'Developers Options' on your device. To do it choose Settings than click on About phone, finally click several times on Build version.

According to Unlocking the emulator or device for Android test

I've had the same problems with unreliable unlocking when running Robotium tests. I did not find a solution to programmaticly unlock devices that worked reliably, but there are two things that I did as a work-around.

  • Just disable the lock screen (Settings -> Security -> Screen lock -> None). Not ideal but at the end of the day, reliable tests are the important thing.

  • Enable "Stay Awake" settings to keep the screen from turning off due to inactivity (Settings -> Developer options -> Stay awake). Some OEM/phones either don't have that option or still turn off anyways, so for those pesky devices I installed the [KeepScreenOn][1] app.

Warning: leaving the screen on, sitting on the home screen, for 24 hours a day may cause some screen burn-in/ghosting. I'm not sure if this is permanent, but be aware of this. In our case, we were using dedicated test devices so it was not a big deal.

Also note that since the phones will have their screen on at all times, you may want to dim the brightness to use less battery power (charging over USB can be slow sometimes).

I think you can also use uiautomator code in setUp method, which would check if screen is locked. If true, unlock the device screen.

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94