當前位置: 首頁>>代碼示例>>Java>>正文


Java UiDevice.getInstance方法代碼示例

本文整理匯總了Java中android.support.test.uiautomator.UiDevice.getInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java UiDevice.getInstance方法的具體用法?Java UiDevice.getInstance怎麽用?Java UiDevice.getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.test.uiautomator.UiDevice的用法示例。


在下文中一共展示了UiDevice.getInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setup

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
@Before
public void setup() {
    // Unlock the screen if it's locked
    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    try {
        device.wakeUp();
    } catch (RemoteException e) {
        e.printStackTrace();
    }

    // Set the flags on our activity so it'll appear regardless of lock screen state
    new Handler(Looper.getMainLooper()).post(() -> {
        if (getActivity() == null) return;
        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    });
}
 
開發者ID:kevalpatel2106,項目名稱:smart-lens,代碼行數:19,代碼來源:BaseTestClass.java

示例2: startMainActivityFromHomeScreen

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
@Before
public void startMainActivityFromHomeScreen() {
    // Initialize UiDevice instance
    mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());

    // Start from the home screen
    mDevice.pressHome();

    // Wait for launcher
    final String launcherPackage = getLauncherPackageName();
    assertThat(launcherPackage, notNullValue());
    mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT);

    // Launch the blueprint app
    Context context = InstrumentationRegistry.getContext();
    final Intent intent = context.getPackageManager()
            .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);    // Clear out any previous instances
    context.startActivity(intent);

    // Wait for the app to appear
    mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT);
}
 
開發者ID:cuplv,項目名稱:ChimpCheck,代碼行數:24,代碼來源:ExampleInstrumentedTest.java

示例3: allowPermissionsIfNeeded

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
public static void allowPermissionsIfNeeded(String permissionNeeded) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !hasNeededPermission(permissionNeeded)) {
            sleep(PERMISSIONS_DIALOG_DELAY);
            UiDevice device = UiDevice.getInstance(getInstrumentation());
            UiObject allowPermissions = device.findObject(new UiSelector()
                    .clickable(true)
                    .checkable(false)
                    .index(GRANT_BUTTON_INDEX));
            if (allowPermissions.exists()) {
                allowPermissions.click();
            }
        }
    } catch (UiObjectNotFoundException e) {
        System.out.println("There is no permissions dialog to interact with");
    }
}
 
開發者ID:cuplv,項目名稱:ChimpCheck,代碼行數:18,代碼來源:PermissionGranter.java

示例4: testUiAutomatorAPI

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
@Ignore
@Test
public void testUiAutomatorAPI() throws UiObjectNotFoundException, InterruptedException {
    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());

    UiSelector editTextSelector = new UiSelector().className("android.widget.EditText").text("this is a test").focusable(true);
    UiObject editTextWidget = device.findObject(editTextSelector);
    editTextWidget.setText("this is new text");

    Thread.sleep(2000);

    UiSelector buttonSelector = new UiSelector().className("android.widget.Button").text("CLICK ME").clickable(true);
    UiObject buttonWidget = device.findObject(buttonSelector);
    buttonWidget.click();

    Thread.sleep(2000);
}
 
開發者ID:ravidsrk,項目名稱:android-testing-guide,代碼行數:18,代碼來源:MainActivityTest.java

示例5: allowLocationPermissionWhenAsked

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
/**
 * Allows location permission if the runtime permission dialog is shown.
 */
public static void allowLocationPermissionWhenAsked()
{
    try
    {
        if (!PermissionUtils.isLocationGranted(InstrumentationRegistry.getTargetContext()))
        {
            TestHelper.sleep(PERMISSIONS_DIALOG_DELAY);

            final UiDevice device = UiDevice.getInstance(getInstrumentation());
            final UiObject allowPermissions = device.findObject(new UiSelector()
                                                                        .clickable(true)
                                                                        .checkable(false)
                                                                        .index(GRANT_BUTTON_INDEX));
            if (allowPermissions.exists())
            {
                allowPermissions.click();
            }
        }
    }
    catch (final UiObjectNotFoundException e)
    {
        Log.e(PermissionTestHelper.class.getSimpleName(), "There is no permissions dialog to interact with.");
    }
}
 
開發者ID:inthepocket,項目名稱:ibeacon-scanner-android,代碼行數:28,代碼來源:PermissionTestHelper.java

示例6: testA

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
/**
 * 測試CollapsingToolbarLayout
 * 被測Demo下載地址:https://github.com/alidili/DesignSupportDemo
 *
 * @throws UiObjectNotFoundException
 */
public void testA() throws UiObjectNotFoundException {
    // 獲取設備對象
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    UiDevice uiDevice = UiDevice.getInstance(instrumentation);
    // 獲取上下文
    Context context = instrumentation.getContext();

    // 啟動測試App
    Intent intent = context.getPackageManager().getLaunchIntentForPackage("com.yang.designsupportdemo");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    context.startActivity(intent);

    // 打開CollapsingToolbarLayout
    String resourceId = "com.yang.designsupportdemo:id/CollapsingToolbarLayout";
    UiObject collapsingToolbarLayout = uiDevice.findObject(new UiSelector().resourceId(resourceId));
    collapsingToolbarLayout.click();

    for (int i = 0; i < 5; i++) {
        // 向上移動
        uiDevice.swipe(uiDevice.getDisplayHeight() / 2, uiDevice.getDisplayHeight(),
                uiDevice.getDisplayHeight() / 2, uiDevice.getDisplayHeight() / 2, 10);

        // 向下移動
        uiDevice.swipe(uiDevice.getDisplayHeight() / 2, uiDevice.getDisplayHeight() / 2,
                uiDevice.getDisplayHeight() / 2, uiDevice.getDisplayHeight(), 10);
    }

    // 點擊應用返回按鈕
    UiObject back = uiDevice.findObject(new UiSelector().description("Navigate up"));
    back.click();

    // 點擊設備返回按鈕
    uiDevice.pressBack();
}
 
開發者ID:alidili,項目名稱:Demos,代碼行數:41,代碼來源:UiTest.java

示例7: setUpScreenshots

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
@Before
public void setUpScreenshots() {
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    targetContext = instrumentation.getTargetContext();
    device = UiDevice.getInstance(instrumentation);

    // Use this to switch between default strategy and HostScreencap strategy
    //Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy());
    Screengrab.setDefaultScreenshotStrategy(new HostScreencapScreenshotStrategy(device));

    device.waitForIdle();
}
 
開發者ID:mozilla-mobile,項目名稱:firefox-tv,代碼行數:13,代碼來源:ScreenshotTest.java

示例8: addWidget

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
@Before
public void addWidget() throws Exception {
    device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());

    device.pressHome();
    device.pressHome();
}
 
開發者ID:orgzly,項目名稱:orgzly-android,代碼行數:8,代碼來源:ListWidgetTest.java

示例9: testNotificationAdapter

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
@Test
public void testNotificationAdapter() {
    final String NOTIFICATION_TEXT = "adapter-text";
    final String NOTIFICATION_TITLE = "adapter-title";
    final long TIMEOUT = 5000;

    Context appContext = InstrumentationRegistry.getTargetContext();

    RemoteViews contentView = new RemoteViews("cn.dreamtobe.toolset.test", R.layout.custom_layout);
    contentView.setTextViewText(R.id.title, NOTIFICATION_TITLE);
    contentView.setTextViewText(R.id.text, NOTIFICATION_TEXT);

    // Fix the Notification-Style problem ---------------
    // Set the default title style color to title view.
    contentView.setTextColor(R.id.title, NotificationAdapter.getTitleColor(appContext));
    // Set the default title style size to title view
    contentView.setTextViewTextSize(R.id.title, COMPLEX_UNIT_PX, NotificationAdapter.getTitleSize(appContext));
    // Set the default text style color to text view
    contentView.setTextColor(R.id.text, NotificationAdapter.getTextColor(appContext));
    // Set the default text style size to text view
    contentView.setTextViewTextSize(R.id.text, COMPLEX_UNIT_PX, NotificationAdapter.getTextSize(appContext));
    // End fix the Notification-Style problem ---------------

    Notification notification = new Notification();
    notification.icon = R.drawable.ic_launcher;
    notification.contentView = contentView;

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;

    NotificationManager notifyMgr =
            (NotificationManager) appContext.getSystemService(NOTIFICATION_SERVICE);
    notifyMgr.notify(1, notification);

    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    device.openNotification();
    device.wait(Until.hasObject(By.text(NOTIFICATION_TITLE)), TIMEOUT);
}
 
開發者ID:Jacksgong,項目名稱:notification-adapter,代碼行數:40,代碼來源:NotificationAdapterTest.java

示例10: testIdealPayment

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
/**
 * This test needs additional work. The following passes in Google Pixel device. But since
 * it uses screen coordinates; this test cannot be relied on yet. Work in progress.
 * @throws Exception
 */
@Ignore @Test
public void testIdealPayment() throws Exception {
    startIdealPayment();
    waitForText("Test Issuer");
    onView(withText(equalToIgnoringCase("Test Issuer"))).perform(click());
    final UiDevice device = UiDevice.getInstance(getInstrumentation());
    Thread.sleep(5000);
    device.click(65, 535);

    checkResultString(Payment.PaymentStatus.AUTHORISED.toString());
}
 
開發者ID:Adyen,項目名稱:adyen-android,代碼行數:17,代碼來源:PaymentAppTest.java

示例11: takeCameraPhoto

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
private static void takeCameraPhoto() throws UiObjectNotFoundException {
    UiDevice device = UiDevice.getInstance(getInstrumentation());
    UiSelector shutterSelector =
            new UiSelector().resourceId("com.android.camera:id/shutter_button");
    UiObject shutterButton = device.findObject(shutterSelector);
    shutterButton.click();

    UiSelector doneSelector = new UiSelector().resourceId("com.android.camera:id/btn_done");
    UiObject doneButton = device.findObject(doneSelector);
    doneButton.click();
}
 
開發者ID:ArnauBlanch,項目名稱:civify-app,代碼行數:12,代碼來源:CreateIssueActivityTest.java

示例12: setUp

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
@Override
protected void setUp() throws Exception {
    super.setUp();

    mDevice = UiDevice.getInstance(getInstrumentation());
    mTargetContext = getInstrumentation().getTargetContext();
    mTargetPackage = mTargetContext.getPackageName();
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:9,代碼來源:LauncherInstrumentationTestCase.java

示例13: setUp

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
@Before
public void setUp() throws IOException, RemoteException {
    // Initialize UiDevice instance
    mDevice = UiDevice.getInstance(getInstrumentation());
    // wake up the device when screen is off
    if (!mDevice.isScreenOn()) {
        mDevice.wakeUp();
        mDevice.swipe(mDevice.getDisplayWidth() / 2,
                mDevice.getDisplayHeight() - 100, mDevice.getDisplayWidth() / 2,
                mDevice.getDisplayHeight() / 2, 5);
        delay(1000);
        preSteup(); // do wakeup & maybe unlock gesture lock
    }
    // Start from the home screen
    mDevice.pressHome();
    // launch "com.sc.uiautomatoradapter" to grant the permission and copy XML file to SDCARD
    launchPackage("com.sc.uiautomatoradapter");

    UiObject2 allow = mDevice.wait(Until.findObject(By.res(
            "com.android.packageinstaller:id/permission_allow_button")), timeout);
    // click the allow button to grant the permission
    if (allow != null && allow.isClickable()) {
        allow.click();
        delay(5000);
    }
    if (logger.mOut == null || parser.apps == null) {
        // initialize the Logger instance
        logger.init();
        // initialize the XMLParser instance
        parser.init();
    }
}
 
開發者ID:Sl0v3C,項目名稱:UIAutomatorAdapter,代碼行數:33,代碼來源:AutoTestAdapter.java

示例14: setUp

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
@Override
protected void setUp() throws Exception {
    super.setUp();

    mDevice = UiDevice.getInstance(getInstrumentation());
    mTargetContext = getInstrumentation().getTargetContext();
    mTargetPackage = mTargetContext.getPackageName();
    mPrefs = Utilities.getPrefs(mTargetContext);
    mOriginalRotationValue = mPrefs.getBoolean(Utilities.ALLOW_ROTATION_PREFERENCE_KEY, false);
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:11,代碼來源:RotationPreferenceTest.java

示例15: setup

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
@Before
public void setup() throws IOException, TimeoutException {
	mDevice = UiDevice.getInstance(getInstrumentation());

	server = new MockWebServer();
	server.start();
	String serverUrl = server.url("").toString();

	server.enqueue(TestHelper.getResponseForRaw(R.raw.conferences_json));
	server.enqueue(TestHelper.getResponseForRaw(R.raw.conferences_101_33c3_json));

	Intent i = new Intent();
	i.putExtra("server_url",serverUrl);
	mActivityTestRule.launchActivity(i);
}
 
開發者ID:NiciDieNase,項目名稱:chaosflix-leanback,代碼行數:16,代碼來源:ConferencesActivityTest.java


注:本文中的android.support.test.uiautomator.UiDevice.getInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。