Search in sources :

Example 41 with UiObject2

use of android.support.test.uiautomator.UiObject2 in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AboutPhoneSettingsTests method removeItemsAndTakeAction.

/**
 * Removes items found in the view and optionally takes some action.
 */
private void removeItemsAndTakeAction(UiDevice device, ArrayList<String> itemsLeftToFind) {
    for (Iterator<String> iterator = itemsLeftToFind.iterator(); iterator.hasNext(); ) {
        String itemText = iterator.next();
        UiObject2 item = device.wait(Until.findObject(By.text(itemText)), TIMEOUT);
        if (item != null) {
            iterator.remove();
        }
    }
}
Also used : UiObject2(android.support.test.uiautomator.UiObject2)

Example 42 with UiObject2

use of android.support.test.uiautomator.UiObject2 in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AboutPhoneSettingsTests method setUp.

@Before
public void setUp() throws Exception {
    mInstrumentation = InstrumentationRegistry.getInstrumentation();
    mDevice = UiDevice.getInstance(mInstrumentation);
    try {
        mDevice.setOrientationNatural();
    } catch (RemoteException e) {
        throw new RuntimeException("Failed to freeze device orientaion", e);
    }
    // make sure we are in a clean state before starting the test
    mDevice.pressHome();
    Thread.sleep(TIMEOUT * 2);
    launchAboutPhoneSettings(Settings.ACTION_DEVICE_INFO_SETTINGS);
    // TODO: make sure we are always at the top of the app
    // currently this will fail if the user has navigated into submenus
    UiObject2 view = mDevice.wait(Until.findObject(By.res(SETTINGS_PACKAGE + ":id/main_content")), TIMEOUT);
    assertThat(view).isNotNull();
    view.scroll(Direction.UP, 1.0f);
}
Also used : RemoteException(android.os.RemoteException) UiObject2(android.support.test.uiautomator.UiObject2) Before(org.junit.Before)

Example 43 with UiObject2

use of android.support.test.uiautomator.UiObject2 in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppsSettingsTests method testDisablingAndEnablingSystemApp.

@MediumTest
public void testDisablingAndEnablingSystemApp() throws Exception {
    launchAppsSettings();
    UiObject2 calculator = mDevice.wait(Until.findObject(By.text("Calculator")), TIMEOUT);
    calculator.click();
    mDevice.waitForIdle(TIMEOUT);
    UiObject2 appInfoList = mDevice.wait(Until.findObject(By.res(SETTINGS_PACKAGE, "list")), TIMEOUT);
    appInfoList.scroll(Direction.DOWN, 100.0f);
    UiObject2 disableButton = mDevice.wait(Until.findObject(By.text("DISABLE")), TIMEOUT);
    disableButton.click();
    mDevice.waitForIdle(TIMEOUT);
    // Click on "Disable App" on dialog.
    mDevice.wait(Until.findObject(By.text("DISABLE APP")), TIMEOUT).click();
    mDevice.waitForIdle(TIMEOUT);
    UiObject2 enableButton = mDevice.wait(Until.findObject(By.text("ENABLE")), TIMEOUT);
    assertNotNull("App not disabled successfully", enableButton);
    enableButton.click();
    mDevice.waitForIdle(TIMEOUT);
    disableButton = mDevice.wait(Until.findObject(By.text("DISABLE")), TIMEOUT);
    assertNotNull("App not enabled successfully", disableButton);
}
Also used : UiObject2(android.support.test.uiautomator.UiObject2) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 44 with UiObject2

use of android.support.test.uiautomator.UiObject2 in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ConnectedDeviceTests method testNFCToggle.

// This NFC toggle test is set up this way since there's no way to set
// the NFC flag to enabled or disabled without touching UI.
// This way, we get coverage for whether or not the toggle button works.
@Test
public void testNFCToggle() throws Exception {
    NfcManager manager = (NfcManager) InstrumentationRegistry.getTargetContext().getSystemService(Context.NFC_SERVICE);
    NfcAdapter nfcAdapter = manager.getDefaultAdapter();
    boolean nfcInitiallyEnabled = nfcAdapter.isEnabled();
    InstrumentationRegistry.getContext().startActivity(new Intent().setClassName(SETTINGS_PACKAGE, "com.android.settings.Settings$ConnectedDeviceDashboardActivity"));
    UiObject2 nfcSetting = mDevice.wait(Until.findObject(By.text("NFC")), TIMEOUT);
    nfcSetting.click();
    Thread.sleep(TIMEOUT * 2);
    if (nfcInitiallyEnabled) {
        assertFalse("NFC wasn't disabled on toggle", nfcAdapter.isEnabled());
        nfcSetting.click();
        Thread.sleep(TIMEOUT * 2);
        assertTrue("NFC wasn't enabled on toggle", nfcAdapter.isEnabled());
    } else {
        assertTrue("NFC wasn't enabled on toggle", nfcAdapter.isEnabled());
        nfcSetting.click();
        Thread.sleep(TIMEOUT * 2);
        assertFalse("NFC wasn't disabled on toggle", nfcAdapter.isEnabled());
    }
}
Also used : NfcManager(android.nfc.NfcManager) NfcAdapter(android.nfc.NfcAdapter) Intent(android.content.Intent) UiObject2(android.support.test.uiautomator.UiObject2) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test)

Example 45 with UiObject2

use of android.support.test.uiautomator.UiObject2 in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class MoreWirelessSettingsTests method testVPNMenuLoad.

@MediumTest
public void testVPNMenuLoad() throws Exception {
    SettingsHelper.launchSettingsPage(getInstrumentation().getContext(), Settings.ACTION_WIRELESS_SETTINGS);
    mDevice.wait(Until.findObject(By.text("VPN")), TIMEOUT).click();
    Thread.sleep(TIMEOUT);
    UiObject2 usbTethering = mDevice.wait(Until.findObject(By.res(SETTINGS_PACKAGE, "vpn_create")), TIMEOUT);
    assertNotNull("VPN screen did not load correctly", usbTethering);
}
Also used : UiObject2(android.support.test.uiautomator.UiObject2) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

UiObject2 (android.support.test.uiautomator.UiObject2)133 Test (org.junit.Test)30 BySelector (android.support.test.uiautomator.BySelector)18 MediumTest (android.test.suitebuilder.annotation.MediumTest)16 ListView (android.widget.ListView)8 MediumTest (androidx.test.filters.MediumTest)8 Switch (android.widget.Switch)7 Intent (android.content.Intent)6 RemoteException (android.os.RemoteException)6 LargeTest (android.support.test.filters.LargeTest)6 UiDevice (android.support.test.uiautomator.UiDevice)6 Presubmit (android.platform.test.annotations.Presubmit)4 SdkSuppress (android.support.test.filters.SdkSuppress)4 Activity (android.app.Activity)2 NfcAdapter (android.nfc.NfcAdapter)2 NfcManager (android.nfc.NfcManager)2 Bundle (android.os.Bundle)2 CancellationSignal (android.os.CancellationSignal)2 ParcelFileDescriptor (android.os.ParcelFileDescriptor)2 PrintAttributes (android.print.PrintAttributes)2