Java 类android.support.test.uiautomator.UiSelector 实例源码

项目:ChimpCheck    文件:PermissionGranter.java   
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");
    }
}
项目:SimpleMarkdown    文件:MainActivityTests.java   
@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();
}
项目:Expert-Android-Programming    文件:UIAnimatorTest.java   
@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();
    }
}
项目:firefox-tv    文件:ShareDialogTest.java   
@Test
public void shareTest() throws InterruptedException, UiObjectNotFoundException {

    UiObject shareBtn = TestHelper.mDevice.findObject(new UiSelector()
            .resourceId("org.mozilla.focus.debug:id/share")
            .enabled(true));

    /* Go to a webpage */
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText("mozilla");
    TestHelper.hint.waitForExists(waitingTime);
    TestHelper.pressEnterKey();
    assertTrue(TestHelper.webView.waitForExists(waitingTime));

    /* Select share */
    TestHelper.menuButton.perform(click());
    shareBtn.waitForExists(waitingTime);
    shareBtn.click();

    // For simulators, where apps are not installed, it'll take to message app
    TestHelper.shareMenuHeader.waitForExists(waitingTime);
    assertTrue(TestHelper.shareMenuHeader.exists());
    assertTrue(TestHelper.shareAppList.exists());
    TestHelper.pressBackKey();
}
项目:ibeacon-scanner-android    文件:PermissionTestHelper.java   
/**
 * 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.");
    }
}
项目:android-testing-guide    文件:MainActivityTest.java   
@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);
}
项目:Demos    文件:UiTest.java   
/**
 * 测试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();
}
项目:Demos    文件:UiTest.java   
/**
 * 滑动界面,打开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();
}
项目:SunmiAuto    文件:SunmiAppStore_v3_3_15.java   
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test009SearchByTitle() throws UiObjectNotFoundException {
    TestUtils.screenshotCap("appStoreHome");
    UiObject2 hotOne = device.findObject(By.res("woyou.market:id/linear_hot_view")).findObject(By.res("woyou.market:id/tv_name"));
    String targetAppName = hotOne.getText();
    UiObject2 searchObj = device.findObject(By.res("woyou.market:id/tv_search").text("搜索"));
    searchObj.click();
    TestUtils.screenshotCap("afterClickSearchBar");
    TestUtils.sleep(SHORT_SLEEP);
    UiObject2 searchObj1 = device.findObject(By.res("woyou.market:id/et_search").text("搜索").focused(true));
    searchObj1.click();
    searchObj1.setText(targetAppName);
    TestUtils.screenshotCap("inputSearchContent");
    UiScrollable appList = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    UiObject appInfo = appList.getChildByInstance(new UiSelector().className("android.widget.FrameLayout"),0);
    UiObject appNameObj = appInfo.getChild(new UiSelector().resourceId("woyou.market:id/tv_name"));
    Assert.assertEquals(targetAppName,appNameObj.getText());
}
项目:SunmiAuto    文件:SunmiAppStore_v3_3_15.java   
@Category(CategoryAppStoreTests_v3_3_15.class)
    @Test
    public void test020EnterFeedback() throws UiObjectNotFoundException {
        TestUtils.screenshotCap("appStoreHome");
        UiObject2 mineEntrence = device.findObject(By.res("woyou.market:id/fab_me"));
        mineEntrence.clickAndWait(Until.newWindow(),LONG_WAIT);
        TestUtils.screenshotCap("mineHome");
        UiScrollable mineScroll = new UiScrollable(new UiSelector().className("android.widget.ScrollView"));
        mineScroll.scrollTextIntoView("反馈");
        TestUtils.screenshotCap("ScrollToFeedbackInterface");
        UiObject2 feedbackObj = device.findObject(By.text("反馈"));
        feedbackObj.clickAndWait(Until.newWindow(),LONG_WAIT);
        TestUtils.screenshotCap("enterFeedbackInterface");
        String currentPkgName = device.getCurrentPackageName();
//        for (int i = 0; i <10 ; i++) {
//            Log.v("myautotest1",device.getCurrentPackageName());
//            sleep(500);
//        }
        Assert.assertEquals("期望当前包名为com.sunmi.userfeedback,而实际为"+currentPkgName,"com.sunmi.userfeedback",currentPkgName);
    }
项目:SunmiAuto    文件:SunmiAppStore_v3_3_15.java   
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test024CommentBeforeInstall() throws IOException, UiObjectNotFoundException {
    TestUtils.screenshotCap("appStoreHome");
    UiObject2 hotObj = device.findObject(By.res("woyou.market:id/tv_hot_all").text("全部"));
    hotObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    TestUtils.screenshotCap("hotAllInterface");
    UiScrollable hotAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    hotAllScroll.scrollIntoView(new UiSelector().resourceId("woyou.market:id/id_tv_install_view").text("安装"));
    TestUtils.screenshotCap("scrollInstallBtnInterface");
    UiObject2 installObj = device.findObject(By.res("woyou.market:id/id_tv_install_view").text("安装"));
    UiObject2 fullAppObj = installObj.getParent().getParent();
    fullAppObj.clickAndWait(Until.newWindow(),LONG_WAIT);
    TestUtils.screenshotCap("uninstalledAppDetail");
    UiObject2 commentObj = device.findObject(By.res("woyou.market:id/tv_install_comment_app"));
    commentObj.clickAndWait(Until.newWindow(),LONG_WAIT);
    TestUtils.screenshotCap("afterClickComment");
    UiObject2 rateObj = device.findObject(By.res("woyou.market:id/rating_bar"));
    Assert.assertNull(rateObj);
}
项目:SunmiAuto    文件:SunmiAppStore_v3_3_15.java   
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test025CommentAfterInstall() throws UiObjectNotFoundException {
    TestUtils.screenshotCap("appStoreHome");
    UiObject2 hotObj = device.findObject(By.res("woyou.market:id/tv_hot_all").text("全部"));
    hotObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    TestUtils.screenshotCap("hotAllInterface");
    UiScrollable hotAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    hotAllScroll.scrollIntoView(new UiSelector().resourceId("woyou.market:id/id_tv_install_view").text("打开"));
    UiObject2 installObj = device.findObject(By.res("woyou.market:id/id_tv_install_view").text("打开"));
    UiObject2 fullAppObj = installObj.getParent().getParent();
    fullAppObj.clickAndWait(Until.newWindow(),LONG_WAIT);
    TestUtils.screenshotCap("enterAppDetail");
    UiObject2 commentObj = device.findObject(By.res("woyou.market:id/tv_install_comment_app"));
    commentObj.clickAndWait(Until.newWindow(),LONG_WAIT);
    device.wait(Until.hasObject(By.res("woyou.market:id/rating_bar")),LONG_WAIT);
    TestUtils.screenshotCap("afterClickComment");
    UiObject2 rateObj = device.findObject(By.res("woyou.market:id/rating_bar"));
    Assert.assertNotNull(rateObj);
    device.pressBack();
}
项目:SunmiAuto    文件:SunmiAppStore_v3_3_15.java   
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test026FoldupAppDetail() throws UiObjectNotFoundException {
    TestUtils.screenshotCap("appStoreHome");
    UiObject2 hotObj = device.findObject(By.res("woyou.market:id/tv_hot_all").text("全部"));
    hotObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    TestUtils.screenshotCap("hotAllInterface");
    UiScrollable hotAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    UiObject fullAppObj = hotAllScroll.getChild(new UiSelector().className("android.widget.FrameLayout"));
    fullAppObj.clickAndWaitForNewWindow(LONG_WAIT);
    TestUtils.screenshotCap("enterAppDetail");
    UiObject2 foldupButton = device.findObject(By.res("woyou.market:id/iv_arrow"));
    foldupButton.clickAndWait(Until.newWindow(),LONG_WAIT);
    TestUtils.screenshotCap("foldUpAppDetail");
    UiScrollable hotAllScroll1 = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    Assert.assertNotNull(hotAllScroll1);
}
项目:SunmiAuto    文件:SunmiAppStore.java   
@Test
public void test009SearchByTitle() throws UiObjectNotFoundException {
    TestUtils.screenshotCap("appStoreHome");
    UiObject2 hotOne = device.findObject(By.res("woyou.market:id/linear_hot_view")).findObject(By.res("woyou.market:id/tv_name"));
    String targetAppName = hotOne.getText();
    UiObject2 searchObj = device.findObject(By.res("woyou.market:id/tv_search").text("搜索"));
    searchObj.click();
    TestUtils.screenshotCap("afterClickSearchBar");
    TestUtils.sleep(SHORT_SLEEP);
    UiObject2 searchObj1 = device.findObject(By.res("woyou.market:id/et_search").text("搜索").focused(true));
    searchObj1.click();
    searchObj1.setText(targetAppName);
    TestUtils.screenshotCap("inputSearchContent");
    UiScrollable appList = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    UiObject appInfo = appList.getChildByInstance(new UiSelector().resourceId("woyou.market:id/app_view"),0);
    UiObject appNameObj = appInfo.getChild(new UiSelector().resourceId("woyou.market:id/tv_name"));
    Assert.assertEquals("搜索结果列表第一个应用不是"+targetAppName,targetAppName,appNameObj.getText());
}
项目:SunmiAuto    文件:SunmiAppStore.java   
@Test
public void test024CommentBeforeInstall() throws IOException, UiObjectNotFoundException {
    TestUtils.screenshotCap("appStoreHome");
    UiObject2 hotObj = device.findObject(By.res("woyou.market:id/tv_hot_all").text("全部"));
    hotObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    TestUtils.screenshotCap("hotAllInterface");
    UiScrollable hotAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    hotAllScroll.scrollIntoView(new UiSelector().resourceId("woyou.market:id/tv_install").text("安装"));
    TestUtils.screenshotCap("scrollInstallBtnInterface");
    UiObject2 installObj = device.findObject(By.res("woyou.market:id/tv_install").text("安装"));
    UiObject2 fullAppObj = installObj.getParent().getParent();
    fullAppObj.clickAndWait(Until.newWindow(),LONG_WAIT);
    TestUtils.screenshotCap("uninstalledAppDetail");
    UiObject2 commentObj = device.findObject(By.res("woyou.market:id/tv_install_comment_app"));
    commentObj.clickAndWait(Until.newWindow(),LONG_WAIT);
    TestUtils.screenshotCap("afterClickComment");
    UiObject2 rateObj = device.findObject(By.res("woyou.market:id/rating_bar"));
    Assert.assertNull(rateObj);
}
项目:SunmiAuto    文件:SunmiAppStore.java   
@Test
public void test025CommentAfterInstall() throws UiObjectNotFoundException {
    TestUtils.screenshotCap("appStoreHome");
    UiObject2 hotObj = device.findObject(By.res("woyou.market:id/tv_hot_all").text("全部"));
    hotObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    TestUtils.screenshotCap("hotAllInterface");
    UiScrollable hotAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    hotAllScroll.scrollIntoView(new UiSelector().resourceId("woyou.market:id/tv_install").text("打开"));
    UiObject2 installObj = device.findObject(By.res("woyou.market:id/tv_install").text("打开"));
    UiObject2 fullAppObj = installObj.getParent().getParent();
    fullAppObj.clickAndWait(Until.newWindow(),LONG_WAIT);
    TestUtils.screenshotCap("enterAppDetail");
    UiObject2 commentObj = device.findObject(By.res("woyou.market:id/tv_install_comment_app"));
    commentObj.clickAndWait(Until.newWindow(),LONG_WAIT);
    device.wait(Until.hasObject(By.res("woyou.market:id/rating_bar")),LONG_WAIT);
    TestUtils.screenshotCap("afterClickComment");
    UiObject2 rateObj = device.findObject(By.res("woyou.market:id/rating_bar"));
    Assert.assertNotNull(rateObj);
    device.pressBack();
}
项目:SunmiAuto    文件:SunmiAppStore.java   
@Test
public void test026FoldupAppDetail() throws UiObjectNotFoundException {
    TestUtils.screenshotCap("appStoreHome");
    UiObject2 hotObj = device.findObject(By.res("woyou.market:id/tv_hot_all").text("全部"));
    hotObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    TestUtils.screenshotCap("hotAllInterface");
    UiScrollable hotAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    UiObject fullAppObj = hotAllScroll.getChild(new UiSelector().resourceId("woyou.market:id/app_view"));
    fullAppObj.clickAndWaitForNewWindow(LONG_WAIT);
    TestUtils.screenshotCap("enterAppDetail");
    UiObject2 foldupButton = device.findObject(By.res("woyou.market:id/iv_arrow"));
    foldupButton.clickAndWait(Until.newWindow(),LONG_WAIT);
    TestUtils.screenshotCap("foldUpAppDetail");
    UiScrollable hotAllScroll1 = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    Assert.assertNotNull(hotAllScroll1);
}
项目:FancyTrendView    文件:GoogleTrendActivityUiAutomatorTest.java   
@Test
public void mainActivity_changeGridSize() throws Exception {
    UiScrollable recycleView = new UiScrollable(new UiSelector().resourceId("com.fantasyfang.googletrendapp:id/trendRecycleView")
            .className(RecyclerView.class));//recycleView.click();
    UiObject item = recycleView.getChild(new UiSelector().resourceId("com.fantasyfang.googletrendapp:id/googleTrendView"));
    item.click();

    String gridDescription = InstrumentationRegistry.getInstrumentation().getTargetContext().getString(R.string.choose_grid);
    UiObject grid = mDevice.findObject(new UiSelector().descriptionContains(gridDescription));
    grid.click();

    UiObject gridList = mDevice.findObject(new UiSelector().text("2*2"));
    gridList.click();
    mDevice.waitForIdle();
    takeScreenShot("Change_grid_to_2_2.jpg");
    mDevice.pressHome();
    takeScreenShot("Home.jpg");
}
项目:FlickLauncher    文件:BindWidgetTest.java   
public void testUnboundWidget_removed() throws Exception {
    LauncherAppWidgetProviderInfo info = findWidgetProvider(false);
    LauncherAppWidgetInfo item = createWidgetInfo(info, false);
    item.appWidgetId = -33;

    // Since there is no widget to verify, just wait until the workspace is ready.
    setupAndVerifyContents(item, Workspace.class, null);

    waitUntilLoaderIdle();
    // Item deleted from db
    mCursor = mResolver.query(LauncherSettings.Favorites.getContentUri(item.id),
            null, null, null, null, null);
    assertEquals(0, mCursor.getCount());

    // The view does not exist
    assertFalse(mDevice.findObject(new UiSelector().description(info.label)).exists());
}
项目:firefox-tv    文件:BrowserScreenScreenshots.java   
private void takeScreenshotsOfOpenWithAndShare() throws Exception {
    /* Open_With View */
    UiObject openWithBtn = device.findObject(new UiSelector()
            .resourceId("org.mozilla.focus.debug:id/open_select_browser")
            .enabled(true));
    assertTrue(openWithBtn.waitForExists(waitingTime));
    openWithBtn.click();
    UiObject shareList = device.findObject(new UiSelector()
            .resourceId("org.mozilla.focus.debug:id/apps")
            .enabled(true));
    assertTrue(shareList.waitForExists(waitingTime));
    Screengrab.screenshot("OpenWith_Dialog");

    /* Share View */
    UiObject shareBtn = device.findObject(new UiSelector()
            .resourceId("org.mozilla.focus.debug:id/share")
            .enabled(true));
    device.pressBack();
    TestHelper.menuButton.perform(click());
    assertTrue(shareBtn.waitForExists(waitingTime));
    shareBtn.click();
    TestHelper.shareAppList.waitForExists(waitingTime);
    Screengrab.screenshot("Share_Dialog");

    device.pressBack();
}
项目:SimpleUILauncher    文件:BindWidgetTest.java   
public void testUnboundWidget_removed() throws Exception {
    LauncherAppWidgetProviderInfo info = findWidgetProvider(false);
    LauncherAppWidgetInfo item = createWidgetInfo(info, false);
    item.appWidgetId = -33;

    // Since there is no widget to verify, just wait until the workspace is ready.
    setupAndVerifyContents(item, Workspace.class, null);

    waitUntilLoaderIdle();
    // Item deleted from db
    mCursor = mResolver.query(LauncherSettings.Favorites.getContentUri(item.id),
            null, null, null, null, null);
    assertEquals(0, mCursor.getCount());

    // The view does not exist
    assertFalse(mDevice.findObject(new UiSelector().description(info.label)).exists());
}
项目:AsteroidOSSync    文件:UIUtil.java   
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;
}
项目:appium-uiautomator2-server    文件:CustomUiSelector.java   
/**
 * returns UiSelector object, based on UiAutomationElement attributes
 * @param node
 * @return
 */
public UiSelector getUiSelector(AccessibilityNodeInfo node) {
    XPathFinder.refreshUiElementTree();
    uiAutomationElement = UiAutomationElement.map.get(node);
    put(Attribute.PACKAGE, charSequenceToString(uiAutomationElement.getPackageName()));
    put(Attribute.CLASS, charSequenceToString(uiAutomationElement.getClassName()));
    put( Attribute.TEXT, charSequenceToString(uiAutomationElement.getText()));
    put( Attribute.CONTENT_DESC, charSequenceToString(uiAutomationElement.getContentDescription()));
    put( Attribute.RESOURCE_ID, charSequenceToString(uiAutomationElement.getResourceId()));
    put( Attribute.CHECKABLE, uiAutomationElement.isCheckable());
    put( Attribute.CHECKED, uiAutomationElement.isChecked());
    put( Attribute.CLICKABLE, uiAutomationElement.isClickable());
    put( Attribute.ENABLED, uiAutomationElement.isEnabled());
    put( Attribute.FOCUSABLE, uiAutomationElement.isFocusable());
    put( Attribute.FOCUSED, uiAutomationElement.isFocused());
    put( Attribute.LONG_CLICKABLE, uiAutomationElement.isLongClickable());
    put( Attribute.PASSWORD, uiAutomationElement.isPassword());
    put( Attribute.SCROLLABLE, uiAutomationElement.isScrollable());
    put( Attribute.SELECTED, uiAutomationElement.isSelected());
    put( Attribute.INDEX, uiAutomationElement.getIndex());

    return selector;
}
项目:focus-android    文件:BrowserScreenScreenshots.java   
private void takeScreenshotsOfOpenWithAndShare() throws Exception {
    /* Open_With View */
    UiObject openWithBtn = device.findObject(new UiSelector()
            .resourceId("org.mozilla.focus.debug:id/open_select_browser")
            .enabled(true));
    assertTrue(openWithBtn.waitForExists(waitingTime));
    openWithBtn.click();
    UiObject shareList = device.findObject(new UiSelector()
            .resourceId("org.mozilla.focus.debug:id/apps")
            .enabled(true));
    assertTrue(shareList.waitForExists(waitingTime));
    Screengrab.screenshot("OpenWith_Dialog");

    /* Share View */
    UiObject shareBtn = device.findObject(new UiSelector()
            .resourceId("org.mozilla.focus.debug:id/share")
            .enabled(true));
    device.pressBack();
    TestHelper.menuButton.perform(click());
    assertTrue(shareBtn.waitForExists(waitingTime));
    shareBtn.click();
    TestHelper.shareAppList.waitForExists(waitingTime);
    Screengrab.screenshot("Share_Dialog");

    device.pressBack();
}
项目:appium-uiautomator2-server    文件:GetElementAttribute.java   
private static int getScrollableOffset(AndroidElement uiScrollable) throws UiObjectNotFoundException, ClassNotFoundException, InvalidSelectorException {
    AccessibilityNodeInfo nodeInfo = null;
    int offset = 0;
    Object actualObject = uiScrollable.getUiObject();
    if (actualObject instanceof UiObject) {
        UiObject object = (UiObject) uiScrollable.getChild(new UiSelector().index(0));
        Method findAccessibilityNodeInfoMethod = ReflectionUtils.method(UiObject.class, "findAccessibilityNodeInfo", long.class);
        long waitForSelectorTimeout = (long) ReflectionUtils.getField(UiObject.class, "WAIT_FOR_SELECTOR_TIMEOUT", object);

        nodeInfo = (AccessibilityNodeInfo) ReflectionUtils.invoke(findAccessibilityNodeInfoMethod, object, waitForSelectorTimeout);
    } else {
        UiObject2 childObject = ((UiObject2) actualObject).getChildren().get(0);
        try {
            nodeInfo = AccessibilityNodeInfoGetter.fromUiObject(childObject);
        } catch (UiAutomator2Exception ignored) {
        }
    }

    if (nodeInfo != null) {
        Rect rect = new Rect();
        nodeInfo.getBoundsInParent(rect);
        offset = rect.height();
    }

    return offset;
}
项目:focus-android    文件:ShareDialogTest.java   
@Test
public void shareTest() throws InterruptedException, UiObjectNotFoundException {

    UiObject shareBtn = TestHelper.mDevice.findObject(new UiSelector()
            .resourceId("org.mozilla.focus.debug:id/share")
            .enabled(true));

    /* Go to a webpage */
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText("mozilla");
    TestHelper.hint.waitForExists(waitingTime);
    TestHelper.pressEnterKey();
    assertTrue(TestHelper.webView.waitForExists(waitingTime));

    /* Select share */
    TestHelper.menuButton.perform(click());
    shareBtn.waitForExists(waitingTime);
    shareBtn.click();

    // For simulators, where apps are not installed, it'll take to message app
    TestHelper.shareMenuHeader.waitForExists(waitingTime);
    assertTrue(TestHelper.shareMenuHeader.exists());
    assertTrue(TestHelper.shareAppList.exists());
    TestHelper.pressBackKey();
}
项目:appium-uiautomator2-server    文件:FindElements.java   
/**
 * returns  List<UiObject> using '-android automator' expression
 **/
private List<Object> getUiObjectsUsingAutomator(List<UiSelector> selectors, String contextId) throws InvalidSelectorException, ClassNotFoundException {
    List<Object> foundElements = new ArrayList<Object>();
    for (final UiSelector sel : selectors) {
        // With multiple selectors, we expect that some elements may not
        // exist.
        try {
            Logger.debug("Using: " + sel.toString());
            final List<Object> elementsFromSelector = fetchElements(sel, contextId);
            foundElements.addAll(elementsFromSelector);
        } catch (final UiObjectNotFoundException ignored) {
            //for findElements up on no elements, empty array should return.
        }
    }
    foundElements = ElementHelpers.dedupe(foundElements);
    return foundElements;
}
项目:appium-uiautomator2-server    文件:UiObject2Element.java   
public List<Object> getChildren(final Object selector, final By by) throws UiObjectNotFoundException, InvalidSelectorException, ClassNotFoundException {
    if (selector instanceof UiSelector) {
        /**
         * We can't find the child elements with UiSelector on UiObject2,
         * as an alternative creating UiObject with UiObject2's AccessibilityNodeInfo
         * and finding the child elements on UiObject.
         */
        AccessibilityNodeInfo nodeInfo = AccessibilityNodeInfoGetter.fromUiObject(element);

        UiSelector uiSelector = new UiSelector();
        CustomUiSelector customUiSelector = new CustomUiSelector(uiSelector);
        uiSelector = customUiSelector.getUiSelector(nodeInfo);
        UiObject uiObject = (UiObject)  CustomUiDevice.getInstance().findObject(uiSelector);
        String id = UUID.randomUUID().toString();
        AndroidElement androidElement = getAndroidElement(id, uiObject, by);
        return androidElement.getChildren(selector, by);
    }
    return (List)element.findObjects((BySelector) selector);
}
项目:Expander    文件:TestUtils.java   
public static void turnOnAccessibilityPermission() throws UiObjectNotFoundException {
    UiScrollable texterScreen = new UiScrollable(LauncherHelper.LAUNCHER_CONTAINER);
    texterScreen.setAsVerticalList();

    UiObject permission = new UiObject(
            new UiSelector().text("Off"));

    permission.click();

    UiScrollable permissionScreen = new UiScrollable(LauncherHelper.LAUNCHER_CONTAINER);
    permissionScreen.setAsVerticalList();

    UiObject permissionButton = new UiObject(
            new UiSelector().text("OK"));

    permissionButton.click();
}
项目:SmoothClicker    文件:ItIntroScreensActivity.java   
/**
 *
 */
private void testIfSlide( int index ){
    if ( index <= 0 ) throw new IllegalArgumentException("Bad parameter for index");
    try {
        UiObject title = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/title")
        );
        UiObject description = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/description")
        );
        UiObject next = mDevice.findObject(
                new UiSelector().resourceId(PACKAGE_APP_PATH + ":id/skip")
        );
        assertEquals(sTitles[index - 1], title.getText());
        assertEquals(sSummaries[index-1], description.getText());
        assertTrue(next.exists());
    } catch ( UiObjectNotFoundException uonfe ){
        uonfe.printStackTrace();
        fail(uonfe.getMessage() );
    }
}
项目:appium-uiautomator2-server    文件:UiObject2Element.java   
public Object getChild(final Object selector) throws UiObjectNotFoundException, InvalidSelectorException, ClassNotFoundException {
    if (selector instanceof UiSelector) {
        /**
         * We can't find the child element with UiSelector on UiObject2,
         * as an alternative creating UiObject with UiObject2's AccessibilityNodeInfo
         * and finding the child element on UiObject.
         */
        AccessibilityNodeInfo nodeInfo = AccessibilityNodeInfoGetter.fromUiObject(element);

        UiSelector uiSelector = new UiSelector();
        CustomUiSelector customUiSelector = new CustomUiSelector(uiSelector);
        uiSelector = customUiSelector.getUiSelector(nodeInfo);
        UiObject uiObject = (UiObject)  CustomUiDevice.getInstance().findObject(uiSelector);
        AccessibilityNodeInfo uiObject_nodeInfo = AccessibilityNodeInfoGetter.fromUiObject(element);
        return uiObject.getChild((UiSelector) selector);
    }
    return element.findObject((BySelector) selector);
}
项目:SmoothClicker    文件:ItNotificationsManager.java   
/**
 * Inner method to get a dedicated notification and test it
 * @param textContent - The text to use to get the notification
 */
private void testIfNotificationExists( String textContent ) {

    UiObject n = null;

    if ( Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH ){
        n = mDevice.findObject(
                new UiSelector()
                    .resourceId("android:id/text")
                    .className("android.widget.TextView")
                    .packageName("pylapp.smoothclicker.android")
                    .textContains(textContent));
    } else {
        n = mDevice.findObject(
                new UiSelector()
                        .resourceId("android:id/text")
                        .className("android.widget.TextView")
                        .packageName("com.android.systemui")
                        .textContains(textContent));
    }

    mDevice.openNotification();
    n.waitForExists(2000);
    assertTrue(n.exists());

}
项目:SmoothClicker    文件:ItServiceClicker.java   
/**
 * Inner method to get a dedicated notification and test it
 * @param textContent - The text to use to get the notification
 */
private void testNotification( String textContent ){

    UiObject n = null;

    if ( Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH ){
        n = mDevice.findObject(
                new UiSelector()
                        .resourceId("android:id/text")
                        .className("android.widget.TextView")
                        .packageName("pylapp.smoothclicker.android")
                        .textContains(textContent));
    } else {
        n = mDevice.findObject(
                new UiSelector()
                        .resourceId("android:id/text")
                        .className("android.widget.TextView")
                        .packageName("com.android.systemui")
                        .textContains(textContent));
    }

    mDevice.openNotification();
    n.waitForExists(60000);
    assertTrue(n.exists());

}
项目:NineSquare    文件:UiAutoTest.java   
@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);
    }
项目:appium-uiautomator2-server    文件:FindElements.java   
public List<UiSelector> findByUiAutomator(String expression) throws UiSelectorSyntaxException {
    List<UiSelector> parsedSelectors = null;
    UiAutomatorParser uiAutomatorParser = new UiAutomatorParser();
    final List<UiSelector> selectors = new ArrayList<UiSelector>();
    try {
        parsedSelectors = uiAutomatorParser.parse(expression);
    } catch (final UiSelectorSyntaxException e) {
        throw new UiSelectorSyntaxException(
                "Could not parse UiSelector argument: " + e.getMessage());
    }

    for (final UiSelector selector : parsedSelectors) {
        selectors.add(selector);
    }
    return selectors;
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Test
public void test022Search() throws UiObjectNotFoundException {
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)){
        Log.v("myautotest1","233333333");
        UiObject2 searchBtnObj = device.findObject(By.res("com.android.settings:id/search"));
        searchBtnObj.clickAndWait(Until.newWindow(),LONG_WAIT);
        UiObject2 searchTextObj = device.findObject(By.focused(true));
        searchTextObj.setText("W");
        UiScrollable resultScroll = new UiScrollable(new UiSelector().resourceId("com.android.settings:id/list_results"));
        Boolean searched = resultScroll.scrollTextIntoView("WLAN");
        Assert.assertTrue("未搜索到要查找的WLAN",searched);
    }
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Test
public void test063CheckShowPasswordStatus() throws UiObjectNotFoundException {
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) {
        UiScrollable SettingScoll = new UiScrollable(new UiSelector().resourceId("android:id/content"));
        SettingScoll.scrollTextIntoView("安全");
        device.findObject(By.text("安全")).clickAndWait(Until.newWindow(), 5000);
        UiScrollable SwitchScoll = new UiScrollable(new UiSelector().resourceId("android:id/list"));
        SwitchScoll.scrollTextIntoView("显示密码");
        UiObject2 SwitchObj = device.findObjects(By.res("android:id/switchWidget")).get(0);
        Assert.assertTrue("测试失败,显示密码默认不是打开", SwitchObj.isChecked());

    }
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Test
public void test067CheckAutoGetTimeZoneStatus() throws UiObjectNotFoundException {
    if ("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL));
    UiScrollable SettingScroll = new UiScrollable(new UiSelector().resourceId("android:id/content"));
    SettingScroll.scrollTextIntoView("日期和时间");
    device.findObject(By.text("日期和时间")).clickAndWait(Until.newWindow(),5000);
    UiScrollable DateScroll = new UiScrollable(new UiSelector().resourceId("android:id/list"));
    DateScroll.scrollTextIntoView("自动确定日期和时间");
    UiObject2 DataObj = device.findObjects(By.res("android:id/switchWidget")).get(0);
    Assert.assertTrue("测试失败,自动确定时区开关默认不是打开",DataObj.isChecked());


}
项目:SunmiAuto    文件:SunmiSettings.java   
@Test
public void test071Check24HFormatStatus() throws UiObjectNotFoundException {
    if ("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL));
    UiScrollable SettingScroll = new UiScrollable(new UiSelector().resourceId("android:id/content"));
    SettingScroll.scrollTextIntoView("日期和时间");
    device.findObject(By.text("日期和时间")).clickAndWait(Until.newWindow(),5000);
    UiScrollable DataScroll = new UiScrollable(new UiSelector().resourceId("android:id/list"));
    DataScroll.scrollTextIntoView("使用24小时制");
    UiObject2 FormatObj = device.findObjects(By.res("android:id/switchWidget")).get(1);
    Assert.assertTrue("测试失败,使用24小时制开关默认不是打开状态",FormatObj.isChecked());
}
项目:SunmiAuto    文件:SunmiAppStore_v3_3_15.java   
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test004HotScroll() throws UiObjectNotFoundException {
    TestUtils.screenshotCap("appStoreHome");
    UiScrollable hotAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/linear_hot_view"));
    hotAllScroll.scrollToEnd(20, 10);
    hotAllScroll.scrollToBeginning(20, 10);
    TestUtils.screenshotCap("scollInterface");
    UiObject2 hotObj = device.findObject(By.res("woyou.market:id/item_hot_title"));
    Assert.assertNotNull("热门应用Title为能够找到",hotObj);
}