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


Java UiObject.exists方法代碼示例

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


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

示例1: allowPermissionsIfNeeded

import android.support.test.uiautomator.UiObject; //導入方法依賴的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: testChangeText_sameActivity

import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void testChangeText_sameActivity() {


    UiObject skipButton = mDevice.findObject(new UiSelector()
            .text("SKIP").className("android.widget.TextView"));

    // Simulate a user-click on the OK button, if found.
    try {
        if (skipButton.exists() && skipButton.isEnabled()) {
                skipButton.click();
        }
    } catch (UiObjectNotFoundException e) {
        e.printStackTrace();
    }
}
 
開發者ID:PacktPublishing,項目名稱:Expert-Android-Programming,代碼行數:17,代碼來源:UIAnimatorTest.java

示例3: viewExistsContains

import android.support.test.uiautomator.UiObject; //導入方法依賴的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

示例4: allowLocationPermissionWhenAsked

import android.support.test.uiautomator.UiObject; //導入方法依賴的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

示例5: scrollIntoView

import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Override
public boolean scrollIntoView(UiObject obj) throws UiObjectNotFoundException {
    if (obj.exists()) {
        return true;
    }

    // we will need to reset the search from the beginning to start search
    flingToBeginning(getMaxSearchSwipes());
    if (obj.exists()) {
        return true;
    }


    for (int x = 0; x < getMaxSearchSwipes(); x++) {
        if (!scrollForward()) {
            return false;
        }

        if (obj.exists()) {
            return true;
        }
    }

    return false;
}
 
開發者ID:appium,項目名稱:appium-uiautomator2-server,代碼行數:26,代碼來源:ScrollToElement.java

示例6: autoTest

import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
    public void autoTest() throws UiObjectNotFoundException, IOException {
//        mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
//        mDevice.pressHome();

//        final String launcherPackage = mDevice.getLauncherPackageName();
//        Runtime.getRuntime().exec("am start me.xdj.ninesquare.sample/me.xdj.ninesquare.sample.MainActivity");
        UiSelector uiSelector = new UiSelector().resourceId("me.xdj.ninesquare.sample:id/image");
        UiObject uiObject = mDevice.findObject(uiSelector);
        if (uiObject.exists()) {
            uiObject.click();
        }
//        SystemClock.sleep(5000);
        mDevice.waitForIdle();
//        uiObject.swipeLeft(1);
        for (int i = 0; i < 11; i++) {
            // 1步5毫秒
            mDevice.swipe(900, 1000, 10, 900, 100);
//        UiObject uiObject1 = mDevice.findObject(new UiSelector().resourceId("me.xdj.ninesquare.sample:id"));
//        uiObject1.swipeLeft(100);
            SystemClock.sleep(900);
        }
        mDevice.click(900, 100);
        SystemClock.sleep(3000);
    }
 
開發者ID:XuDaojie,項目名稱:NineSquare,代碼行數:26,代碼來源:UiAutoTest.java

示例7: clickOnAllow

import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
Roboter clickOnAllow() throws UiObjectNotFoundException {
  final UiObject allowPermissions = getButton("ALLOW");

  if (allowPermissions.exists()) {
    allowPermissions.click();
  }

  return this;
}
 
開發者ID:vanniktech,項目名稱:RxPermission,代碼行數:10,代碼來源:PermissionActivityTest.java

示例8: allowPermissionsIfNeeded

import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
protected void allowPermissionsIfNeeded()  {
    if (Build.VERSION.SDK_INT >= 23) {
        UiObject allowPermissions = mDevice.findObject(
                new UiSelector().className("android.widget.Button")
                                .resourceId("com.android.packageinstaller:id/permission_allow_button"));
        if (allowPermissions.exists()) {
            try {
                allowPermissions.click();
            } catch (UiObjectNotFoundException e) {
                Log.e(this.getClass().getName(), "There is no permissions dialog to interact with ", e);
            }
        }
    }
}
 
開發者ID:aschattney,項目名稱:dagger-test-example,代碼行數:15,代碼來源:UiAutomatorEspressoTestCase.java

示例9: allowPermissionsIfNeeded

import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
protected void allowPermissionsIfNeeded()  {
    if (Build.VERSION.SDK_INT >= 23) {
        UiObject allowPermissions = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).findObject(
                new UiSelector().className("android.widget.Button")
                                .resourceId("com.android.packageinstaller:id/permission_allow_button"));
        if (allowPermissions.exists()) {
            try {
                allowPermissions.click();
            } catch (UiObjectNotFoundException e) {
                Log.e(this.getClass().getName(), "There is no permissions dialog to interact with ", e);
            }
        }
    }
}
 
開發者ID:aschattney,項目名稱:dagger-test-example,代碼行數:15,代碼來源:SimpleEspressoTest.java

示例10: skipPermission

import android.support.test.uiautomator.UiObject; //導入方法依賴的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

示例11: closePermissionDialog

import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
private void closePermissionDialog() {
    UiObject denyPermissions = device.findObject(new UiSelector().text("Deny"));
    if (denyPermissions.exists()) {
        try {
            denyPermissions.click();
        } catch (UiObjectNotFoundException e) {
        }
    }
}
 
開發者ID:xbauquet,項目名稱:Theo,代碼行數:10,代碼來源:AnotationsTest.java

示例12: denyPermissionsIfNeeded

import android.support.test.uiautomator.UiObject; //導入方法依賴的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

示例13: clickButton

import android.support.test.uiautomator.UiObject; //導入方法依賴的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

示例14: shouldAskForPermissionFromSnackBarButton

import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void shouldAskForPermissionFromSnackBarButton() throws Exception {
    if (Build.VERSION.SDK_INT >= 23) {
        String snackBarButtonText = activityRule.getActivity().getResources().getString(R.string.snack_bar_button);
        UiObject snackBarButton = device.findObject(new UiSelector().text(snackBarButtonText));
        if (snackBarButton.exists()) {
            try {
                snackBarButton.click();
                testIfDialogIsDisplayed();
                closePermissionDialog();
            } catch (UiObjectNotFoundException e) {
            }
        }
    }
}
 
開發者ID:xbauquet,項目名稱:Theo,代碼行數:16,代碼來源:SnackBarTest.java

示例15: allowPermissionsIfNeeded

import android.support.test.uiautomator.UiObject; //導入方法依賴的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


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