Add a Screen Wake‑Up Reminder to UiAutomator Tests

This article shows how to implement a post‑test reminder for UiAutomator by using screen sleep and wake‑up logic, providing Java code that checks the screen state, re‑activates it if needed, and optionally sets screen brightness via an ADB command.

FunTester
FunTester
FunTester
Add a Screen Wake‑Up Reminder to UiAutomator Tests

When running UiAutomator tests, it is easy to forget to check the test report after execution. To avoid this, the author proposes a simple reminder that uses screen on/off signals instead of sound or vibration, which are not available in UiAutomator 1 without an auxiliary APK.

Screen‑based reminder implementation

public void warningTester() throws RemoteException {
    UiDevice.getInstance().sleep(); // turn screen off
    sleep(1200); // pause briefly
    if (UiDevice.getInstance().isScreenOn()) { // screen is already on
        return; // exit if no reminder needed
    } else {
        UiDevice.getInstance().wakeUp(); // wake the screen
        warningTester(); // recurse to ensure reminder
    }
}

The method first forces the device to sleep, waits a short period, then checks whether the screen is on. If the screen remains off, it wakes the device and recursively calls itself, creating a visible reminder for the tester.

Optional screen‑brightness adjustment

public static void setScreenLightTo250() {
    execCmd("adb -s " + NEXUS5DEVICESID + " shell settings put system screen_brightness 250");
}

This helper method demonstrates how to set the screen brightness to a specific level (value 250) using an ADB shell command, which can be combined with the reminder logic to ensure the screen is visible after waking.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaAndroidTesting AutomationUIAutomatorScreen Reminder
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.