Wake up device before running UI tests

pull/69/head
Alinson S. Xavier 10 years ago
parent 18abb2038f
commit 866b62987c

@ -10,6 +10,7 @@ import android.test.suitebuilder.annotation.LargeTest;
import org.isoron.uhabits.MainActivity;
import org.isoron.uhabits.R;
import org.isoron.uhabits.models.Habit;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@ -58,6 +59,8 @@ import static org.isoron.uhabits.ui.ShowHabitActivityActions.openHistoryEditor;
@LargeTest
public class MainTest
{
private SystemHelper sys;
@Rule
public IntentsTestRule<MainActivity> activityRule = new IntentsTestRule<>(
MainActivity.class);
@ -66,13 +69,20 @@ public class MainTest
public void setup()
{
Context context = InstrumentationRegistry.getInstrumentation().getContext();
SystemHelper sys = new SystemHelper(context);
sys = new SystemHelper(context);
sys.disableAllAnimations();
sys.acquireWakeLock();
sys.unlockScreen();
skipTutorial();
}
@After
public void tearDown()
{
sys.releaseWakeLock();
}
public void skipTutorial()
{
try

@ -4,6 +4,7 @@ import android.app.KeyguardManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.IBinder;
import android.os.PowerManager;
import android.support.test.runner.AndroidJUnitRunner;
import android.util.Log;
@ -16,24 +17,39 @@ public final class SystemHelper extends AndroidJUnitRunner
private static final float DEFAULT = 1.0f;
private final Context context;
private PowerManager.WakeLock wakeLock;
SystemHelper(Context context)
{
this.context = context;
}
void acquireWakeLock()
{
PowerManager power = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
wakeLock = power.newWakeLock(PowerManager.FULL_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP |
PowerManager.ON_AFTER_RELEASE, getClass().getSimpleName());
wakeLock.acquire();
}
void releaseWakeLock()
{
if(wakeLock != null)
wakeLock.release();
}
void unlockScreen()
{
Log.i("SystemHelper", "Trying to unlock screen");
try
{
KeyguardManager mKeyGuardManager = (KeyguardManager) context
.getSystemService(Context.KEYGUARD_SERVICE);
KeyguardManager mKeyGuardManager =
(KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
KeyguardManager.KeyguardLock mLock = mKeyGuardManager.newKeyguardLock("lock");
mLock.disableKeyguard();
Log.e("SystemHelper", "Successfully unlocked screen");
}
catch (Exception e)
} catch (Exception e)
{
Log.e("SystemHelper", "Could not unlock screen");
e.printStackTrace();
@ -44,10 +60,8 @@ public final class SystemHelper extends AndroidJUnitRunner
{
Log.i("SystemHelper", "Trying to disable animations");
int permStatus = context.checkCallingOrSelfPermission(ANIMATION_PERMISSION);
if (permStatus == PackageManager.PERMISSION_GRANTED)
setSystemAnimationsScale(DISABLED);
else
Log.e("SystemHelper", "Permission denied");
if (permStatus == PackageManager.PERMISSION_GRANTED) setSystemAnimationsScale(DISABLED);
else Log.e("SystemHelper", "Permission denied");
}
@ -85,8 +99,7 @@ public final class SystemHelper extends AndroidJUnitRunner
}
catch (Exception e)
{
Log.e("SystemHelper",
"Could not change animation scale to " + animationScale + " :'(");
Log.e("SystemHelper", "Could not change animation scale to " + animationScale + " :'(");
}
}
}

@ -23,5 +23,6 @@
<uses-permission android:name="android.permission.SET_ANIMATION_SCALE"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
</manifest>

Loading…
Cancel
Save