当前位置: 首页>>代码示例>>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;未经允许,请勿转载。