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.