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


Java UiDevice.findObject方法代碼示例

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


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

示例1: 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

示例2: openAppTest

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
@Test
public void openAppTest() throws Exception {
    UiDevice mDevice = UiDevice.getInstance(getInstrumentation());
    mDevice.pressHome();
    // Bring up the default launcher by searching for a UI component
    // that matches the content description for the launcher button.
    UiObject allAppsButton = mDevice
            .findObject(new UiSelector().description("Apps"));

    // Perform a click on the button to load the launcher.
    allAppsButton.clickAndWaitForNewWindow();
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.wbrawner.simplemarkdown", appContext.getPackageName());
    UiScrollable appView = new UiScrollable(new UiSelector().scrollable(true));
    UiSelector simpleMarkdownSelector = new UiSelector().text("Simple Markdown");
    appView.scrollIntoView(simpleMarkdownSelector);
    mDevice.findObject(simpleMarkdownSelector).clickAndWaitForNewWindow();
}
 
開發者ID:wbrawner,項目名稱:SimpleMarkdown,代碼行數:21,代碼來源:MainActivityTests.java

示例3: 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

示例4: viewExistsContains

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
public static boolean viewExistsContains(UiDevice device, String... textToMatch) throws UiObjectNotFoundException
{
    if (textToMatch == null || textToMatch.length < 1)
    {
        return false;
    }
    UiObject view;
    boolean contains = false;
    for (int i = 0; i < textToMatch.length; i++)
    {
        view = device.findObject(new UiSelector().textContains(textToMatch[i]));
        contains = view.exists();
        if (contains) return true;
    }
    return false;
}
 
開發者ID:AsteroidOS,項目名稱:AsteroidOSSync,代碼行數:17,代碼來源:UIUtil.java

示例5: 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

示例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: testB

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
/**
 * 滑動界麵,打開About phone選項
 * 測試環境為標準Android 7.1.1版本,不同設備控件查找方式會有不同
 *
 * @throws UiObjectNotFoundException
 */
public void testB() throws UiObjectNotFoundException {
    // 獲取設備對象
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    UiDevice uiDevice = UiDevice.getInstance(instrumentation);
    // 獲取上下文
    Context context = instrumentation.getContext();

    // 點擊Settings按鈕
    UiObject uiObject = uiDevice.findObject(new UiSelector().description("Settings"));
    uiObject.click();

    // 滑動列表到最後,點擊About phone選項
    UiScrollable settings = new UiScrollable(new UiSelector().className("android.support.v7.widget.RecyclerView"));
    UiObject about = settings.getChildByText(new UiSelector().className("android.widget.LinearLayout"), "About phone");
    about.click();

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

示例8: 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

示例9: skipPermission

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
public void skipPermission(JSONArray permissionPatterns, int scanningCount) {
    UiDevice mDevice = Elements.getGlobal().getmDevice();

    // if permission list is empty, avoid execution
    if (permissionPatterns.size() == 0) {
        return;
    }

    // regular check for permission scanning
    try {
        for (int i = 0; i < scanningCount; i++) {
            inner:
            for (int j = 0; j < permissionPatterns.size(); j++) {
                String text = permissionPatterns.getString(j);
                UiObject object = mDevice.findObject(new UiSelector().text(text));
                if (object.exists()) {
                    object.click();
                    break inner;
                }
            }

            Thread.sleep(3000);
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
        System.out.println(e.getCause().toString());
    }
}
 
開發者ID:macacajs,項目名稱:UIAutomatorWD,代碼行數:29,代碼來源:UIAutomatorWD.java

示例10: denyPermissionsIfNeeded

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
public void denyPermissionsIfNeeded(Activity activity, String permissionNeeded) {
  try {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !hasNeededPermission(activity, permissionNeeded)) {
      waitInMillis(PERMISSIONS_DIALOG_DELAY);
      UiDevice device = UiDevice.getInstance(getInstrumentation());
      UiObject denyPermissions = device.findObject(new UiSelector().clickable(true).index(DENY_BUTTON_INDEX));
      if (denyPermissions.exists()) {
        denyPermissions.click();
      }
    }
  } catch (UiObjectNotFoundException e) {
    logNoPermissionDialogError();
  }
}
 
開發者ID:SchibstedSpain,項目名稱:Leku,代碼行數:15,代碼來源:PermissionGranter.java

示例11: clickButton

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
/**
 * Clicks a button with the given text. This will try to find the widget exactly as the text is given, and
 * will try upper casing the text if it is not found.
 */
public static void clickButton(UiDevice device, String buttonText) throws UiObjectNotFoundException
{
    UiObject accept = device.findObject(new UiSelector().text(buttonText));
    if (accept.exists())
    {
        accept.click();
        return;
    }
    accept = device.findObject(new UiSelector().text(buttonText.toUpperCase()));
    accept.click();
}
 
開發者ID:AsteroidOS,項目名稱:AsteroidOSSync,代碼行數:16,代碼來源:UIUtil.java

示例12: assertViewWithTextIsVisible

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
private void assertViewWithTextIsVisible(UiDevice device, String text) throws UiObjectNotFoundException {
    UiObject allowButton = device.findObject(new UiSelector().text(text));
    if (!allowButton.exists()) {
        throw new AssertionError("View with text <" + text + "> not found!");
    }
    allowButton.click();
}
 
開發者ID:taehwandev,項目名稱:Android-BlogExample,代碼行數:8,代碼來源:MainFragmentExtendTest.java

示例13: click

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
protected void click(String targetId) {
    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    UiObject button = device.findObject(new UiSelector().resourceId(targetId));

    try {
        button.waitForExists(3000);
        button.click();
    } catch (UiObjectNotFoundException e) {
        throw new IllegalStateException(e);
    }
}
 
開發者ID:nenick,項目名稱:espresso-macchiato,代碼行數:12,代碼來源:EspPermissionDialog.java

示例14: allowPermissionsIfNeeded

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
public static void allowPermissionsIfNeeded(UiDevice device) {
    if (Build.VERSION.SDK_INT >= 23) {
        UiObject allowPermissions = device.findObject(new UiSelector().text(TEXT_ALLOW));

        if (allowPermissions.exists()) {
            try {
                allowPermissions.click();
            } catch (UiObjectNotFoundException ignored) {
            }
        }
    }
}
 
開發者ID:Plastix,項目名稱:Forage,代碼行數:13,代碼來源:UiAutomatorUtils.java

示例15: allowPermissionsIfNeeded

import android.support.test.uiautomator.UiDevice; //導入方法依賴的package包/類
protected void allowPermissionsIfNeeded() {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    UiDevice device = UiDevice.getInstance(getInstrumentation());
    UiObject allowPermissions = device.findObject(new UiSelector().clickable(true).index(1));
    if (allowPermissions.exists()) {
      try {
        allowPermissions.click();
      } catch (UiObjectNotFoundException e) {
        Timber.e(e, "There is no permissions dialog to interact with ");
      }
    }
  }
}
 
開發者ID:xmartlabs,項目名稱:bigbang,代碼行數:14,代碼來源:SingleActivityInstrumentationTest.java


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