Code example for Instrumentation

Methods: sendKeyDownUpSyncwaitForIdleSync

0
        int databaseSleepModeValue = Settings.System.getInt(mActivity.getContentResolver(),
                Settings.System.WIFI_SLEEP_POLICY,Settings. System.WIFI_SLEEP_POLICY_DEFAULT);
        int uiSleepModeValue = Integer.parseInt(slpModePref.getValue());
        assertEquals("Sleep mode value in database and UI are not the same", databaseSleepModeValue, uiSleepModeValue);
         
        mInstr.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
        mInstr.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
        mInstr.waitForIdleSync();
        //choose the second mode 
        mInstr.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
        mInstr.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
        mInstr.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
        mInstr.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
        mInstr.waitForIdleSync();
        uiSleepModeValue = Integer.parseInt(slpModePref.getValue());
        databaseSleepModeValue = Settings.System.getInt(mActivity.getContentResolver(),
                Settings.System.WIFI_SLEEP_POLICY,Settings. System.WIFI_SLEEP_POLICY_DEFAULT);
        assertEquals("Sleep mode on UI does not change", uiSleepModeValue, 1);
        assertEquals("Sleep mode in database does not change", databaseSleepModeValue, 1);
         
        mInstr.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
        mInstr.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
        mInstr.waitForIdleSync();
        //choose the first mode 
        mInstr.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
        mInstr.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
        mInstr.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
        mInstr.waitForIdleSync();
        uiSleepModeValue = Integer.parseInt(slpModePref.getValue());
        databaseSleepModeValue = Settings.System.getInt(mActivity.getContentResolver(),
                Settings.System.WIFI_SLEEP_POLICY,Settings. System.WIFI_SLEEP_POLICY_DEFAULT);
        assertEquals("Sleep mode on UI does not change", uiSleepModeValue, 0);
        assertEquals("Sleep mode in database does not change", databaseSleepModeValue, 0);
Connect your IDE to all the code out there  Get Codota for Java