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

项目: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");
    }
}
项目: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();
}
项目: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    文件:SunmiSettings.java   
@Test
//检查显示下休眠时间正确(T1)
public void test018CheckSleepTimeOut() throws UiObjectNotFoundException {
    screenshotCap("after_enter");
    TestUtils.enterSettingsFirstLevelByName("显示");
    UiObject2 sleepTimeObj = device.findObject(By.text("休眠")).getParent().findObject(By.res("android:id/summary"));
    String sleepTime = sleepTimeObj.getText();
    Assert.assertEquals("期望是无操作1周后,而实际是" + sleepTime, "无操作1周后", sleepTime);
    sleep(SHORT_SLEEP);
    sleepTimeObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    UiObject2 sleepOpt = device.findObject(By.checked(true));
    String sleepTime1 = sleepOpt.getText();
    Assert.assertEquals("期望是1周,而实际是" + sleepTime1, "1周", sleepTime1);
    sleep(SHORT_SLEEP);
    UiObject2 fiveMinObj = device.findObject(By.text("5分钟"));
    fiveMinObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    UiObject2 sleepTimeObj1 = device.findObject(By.text("休眠")).getParent().findObject(By.res("android:id/summary"));
    String sleepTime2 = sleepTimeObj1.getText();
    Assert.assertEquals("期望是无操作5分钟后,而实际是" + sleepTime, "无操作5分钟后", sleepTime2);
    sleep(SHORT_SLEEP);
    sleepTimeObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    UiObject2 oneWeekObj = device.findObject(By.text("1周"));
    oneWeekObj.click();
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Test
//检查显示下字体大小正确(T1)
public void test019CheckFont() throws UiObjectNotFoundException {
    screenshotCap("after_enter");
    TestUtils.enterSettingsFirstLevelByName("显示");
    UiObject2 fontObj = device.findObject(By.text("字体大小")).getParent().findObject(By.res("android:id/summary"));
    String fontSize = fontObj.getText();
    Assert.assertEquals("期望是正常,而实际是" + fontSize, "正常", fontSize);
    sleep(SHORT_SLEEP);
    fontObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    UiObject2 fontOpt = device.findObject(By.checked(true));
    String fontSize1 = fontOpt.getText();
    Assert.assertEquals("期望是正常,而实际是" + fontSize1, "正常", fontSize1);
    sleep(SHORT_SLEEP);
    UiObject2 hugeObj = device.findObject(By.text("超大"));
    hugeObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    sleep(SHORT_SLEEP);
    UiObject2 fontObj1 = device.findObject(By.text("字体大小")).getParent().findObject(By.res("android:id/summary"));
    String fontSize2 = fontObj1.getText();
    Assert.assertEquals("期望是超大,而实际是" + fontSize2, "超大", fontSize2);
    sleep(SHORT_SLEEP);
    fontObj1.clickAndWait(Until.newWindow(), LONG_WAIT);
    UiObject2 normalObj = device.findObject(By.text("正常"));
    normalObj.click();
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Test
    //检查提示音和通知(T1)
    public void test021CheckTipsAndNotifFirstLevel() throws UiObjectNotFoundException {
        screenshotCap("after_enter");
        TestUtils.enterSettingsFirstLevelByName("提示音和通知");
        sleep(SHORT_SLEEP);
//        Pattern p = Pattern.compile("\\s");
        String[] tipAndNotfi = {"提示音和通知", "声音", "媒体音量", "通知音量", "免打扰", "默认通知铃声", "Pixie Dust", "其他提示音", "通知", "设备锁定时", "显示所有通知内容", "应用通知"};
        List<UiObject2> tipAndNotifList = device.findObjects(By.clazz("android.widget.TextView"));
        sleep(SHORT_SLEEP);
        for (int i = 0; i < tipAndNotifList.size(); i++) {
            Assert.assertEquals("期望是" + tipAndNotfi[i] + ",而实际是" + tipAndNotifList.get(i), tipAndNotfi[i], tipAndNotifList.get(i).getText());
            Log.v("myautotest", tipAndNotifList.get(i).getText());
        }
//        Iterator it = tipAndNotifList.iterator();
//        while(it.hasNext()){
//            Log.v("myautotest",it.next());
//        }
    }
项目:UIAutomatorAdapter    文件:AutoTestAdapter.java   
@Test
public void allTests() throws IOException, UiObjectNotFoundException, InterruptedException {
    String appName, type, value;
    if (parser.apps != null) {
        for (App app : parser.apps) {
            appName = app.getName();
            if (launchPackage(appName)) {
                if (app.actList != null) {
                    for (Action action : app.actList) {
                        type = action.getType();
                        value = action.getValue();
                        processAction(type, value);
                    }
                }
            }
        }
    }
}
项目: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);
}
项目:firefox-tv    文件:TrashcanTest.java   
@Test
public void TrashTest() throws InterruptedException, UiObjectNotFoundException {

    // Open a webpage
    //TestHelper.urlBar.waitForExists(waitingTime);
    //TestHelper.urlBar.click();
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText("mozilla");
    TestHelper.hint.waitForExists(waitingTime);
    TestHelper.pressEnterKey();
    assertTrue(TestHelper.webView.waitForExists(waitingTime));

    // Press erase button, and check for message and return to the main page
    TestHelper.floatingEraseButton.perform(click());
    TestHelper.erasedMsg.waitForExists(waitingTime);
    assertTrue(TestHelper.erasedMsg.exists());
    assertTrue(TestHelper.inlineAutocompleteEditText.exists());
}
项目:ChimpCheck    文件:WildCardManager.java   
public ArrayList<UiObject2> retrieveUiObject2s(BySelector topLevelSelector, BySelector childSelector, int depth) throws UiObjectNotFoundException {
    if (depth == 0) { return new ArrayList<>(); }
    ArrayList<UiObject2> currUiObjects = retrieveTopLevelUiObjects(topLevelSelector);
    ArrayList<UiObject2> baseUiObjects = new ArrayList<>();
    while (depth > 0 && currUiObjects.size() > 0) {
        ArrayList<UiObject2> tempUiObjects = new ArrayList<>();
        for(UiObject2 currUiObject: currUiObjects) {
            if (currUiObject.getChildCount() != 0) {
                tempUiObjects.addAll( retrieveChildUiObjects(currUiObject, childSelector) );
            } else {
                baseUiObjects.add( currUiObject );
            }
        }
        currUiObjects = tempUiObjects;
        depth--;
    }

    String str = "/***** Inferred Actionable UI Objects *****/\n";
    for(UiObject2 candidate: new HashSet<UiObject2>(baseUiObjects)) {
        str += "Found candidate: " + candidate.getClassName() + " " + candidate.getText() + " " + candidate.getContentDescription() + "\n";
    }
    str += "/******************************************/";
    Log.i("Chimp-wildCardManager",str);

    return baseUiObjects;
}
项目:UIAutomatorWD    文件:ElementController.java   
private static boolean sendDeleteKeys(Element el)
        throws UiObjectNotFoundException, IllegalAccessException,
        InvocationTargetException, NoSuchMethodException {
    String tempTextHolder = "";

    while (!el.getText().isEmpty() && !tempTextHolder.equalsIgnoreCase(el.getText())) {
        el.click();

        for (int key : new int[]{KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_FORWARD_DEL}) {
            tempTextHolder = el.getText();
            final int length = tempTextHolder.length();
            for (int count = 0; count < length; count++) {
                try {
                    InteractionController interactionController = UiAutomatorBridge.getInstance().getInteractionController();
                    interactionController.sendKey(key, 0);
                } catch (Exception e) {
                    System.out.println("UiAutomatorBridge.getInteractionController error happen!");
                }
            }
        }
    }
    return el.getText().isEmpty();
}
项目:firefox-tv    文件:TrashcanTest.java   
@Test
public void systemBarTest() throws InterruptedException, UiObjectNotFoundException {
    // Open a webpage
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText("mozilla");
    TestHelper.hint.waitForExists(waitingTime);
    TestHelper.pressEnterKey();
    assertTrue(TestHelper.webView.waitForExists(waitingTime));
    TestHelper.menuButton.perform(click());
    TestHelper.blockCounterItem.waitForExists(waitingTime);

    // Pull down system bar and select delete browsing history
    TestHelper.openNotification();
    TestHelper.notificationBarDeleteItem.waitForExists(waitingTime);
    TestHelper.notificationBarDeleteItem.click();
    TestHelper.erasedMsg.waitForExists(waitingTime);
    assertTrue(TestHelper.erasedMsg.exists());
    assertTrue(TestHelper.inlineAutocompleteEditText.exists());
    assertFalse(TestHelper.menulist.exists());
}
项目:firefox-tv    文件:URLCompletionTest.java   
@Test
public void CompletionTest() throws InterruptedException, UiObjectNotFoundException {
    /* type a partial url, and check it autocompletes*/
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.setText("mozilla");
    TestHelper.hint.waitForExists(waitingTime);
    assertTrue (TestHelper.inlineAutocompleteEditText.getText().equals("mozilla.org"));

    /* press x to delete the both autocomplete and suggestion */
    TestHelper.cleartextField.click();
    assertTrue (TestHelper.inlineAutocompleteEditText.getText().equals("Search or enter address"));
    assertFalse (TestHelper.hint.exists());

    /* type a full url, and check it does not autocomplete */
    TestHelper.inlineAutocompleteEditText.setText("http://www.mozilla.org");
    TestHelper.hint.waitForExists(waitingTime);
    assertTrue (TestHelper.inlineAutocompleteEditText.getText().equals("http://www.mozilla.org"));
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Test
//检查显示下亮度可用(T1)
public void test017CheckClickLightLevel() throws UiObjectNotFoundException {
    screenshotCap("after_enter");
    TestUtils.enterSettingsFirstLevelByName("显示");
    UiObject2 lightObj = device.findObject(By.text("亮度"));
    lightObj.click();
    sleep(SHORT_SLEEP);
    UiObject2 lightSeekBar = device.findObject(By.res("com.android.systemui:id/slider"));
    Assert.assertNotNull("未找到亮度的seekBar", lightSeekBar);
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Test
//检查隐藏底部导航条开关状态(T1)
public void test020CheckNavigateBarSwitch() throws UiObjectNotFoundException {
    screenshotCap("after_enter");
    TestUtils.enterSettingsFirstLevelByName("显示");
    UiObject2 hideBottomNavigateBarObj = device.findObject(By.text("隐藏底部导航条")).getParent().getParent().findObject(By.res("android:id/switchWidget"));
    Boolean switchStatus = hideBottomNavigateBarObj.isChecked();
    Assert.assertFalse("隐藏底部导航条开关默认为开", switchStatus);
}
项目: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 test023CheckWifiStatus() throws UiObjectNotFoundException {
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) {
        screenshotCap("after_enter");
        device.findObject(By.text("WLAN")).clickAndWait(Until.newWindow(), 5000);
        screenshotCap("after_enter");
        UiObject2 WifiStatusObj = device.findObject(By.res("com.android.settings:id/switch_widget"));
        Assert.assertTrue("测试失败,WIFI开关默认不是开启状态", WifiStatusObj.isChecked());
    }

}
项目: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 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   
@Before
//每条测试用例开始前执行操作
public void setup() throws RemoteException, UiObjectNotFoundException, IOException {
    TestUtils.clearAllRecentApps();
    TestUtils.findAppAndOpenByText("应用市场");
    TestUtils.sleep(SHORT_SLEEP);
}
项目: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);
}
项目:SunmiAuto    文件:SunmiAppStore_v3_3_15.java   
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test021CheckServiceProvider() 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("ScrollToServicePro");
    UiObject2 serviceProObj = device.findObject(By.text("服务商"));
    Assert.assertNotNull("未找到服务商信息",serviceProObj);
}
项目:SunmiAuto    文件:SunmiAppStore_v3_3_15.java   
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test022CheckRecentVersion() 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("scrollToCurVersion");
    UiObject2 serviceProObj = device.findObject(By.text("当前版本"));
    Assert.assertNotNull("未找到版本信息", serviceProObj);
}
项目:SunmiAuto    文件:SunmiAppStore_v3_3_15.java   
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test023CheckAppDetail() 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"));
    String appName = fullAppObj.getChild(new UiSelector().resourceId("woyou.market:id/tv_name")).getText();
    fullAppObj.clickAndWaitForNewWindow(LONG_WAIT);
    TestUtils.screenshotCap("enterHotAppsFirstOne");
    UiObject2 nameObj = device.findObject(By.res("woyou.market:id/tv_name"));
    Assert.assertEquals("期望的名字是"+appName+",而实际是"+nameObj.getText(),appName,nameObj.getText());
}
项目:SunmiAuto    文件:SunmiAppStore_v3_3_15.java   
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test027CheckSearchHistory() 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("afterClickSearchBtn");
    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("enterSearchContent");
    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"));
    String appName = appNameObj.getText();
    appInfo.click();
    TestUtils.screenshotCap("enterTheFirstSearchResult");
    device.pressBack();
    TestUtils.sleep(SHORT_SLEEP);
    UiObject2 clearButton = device.findObject(By.res("woyou.market:id/iv_delete"));
    clearButton.click();
    TestUtils.screenshotCap("clearSearchBar");
    TestUtils.sleep(SHORT_SLEEP);
    String historyObjName = device.findObject(By.res("woyou.market:id/history_key")).findObject(By.clazz("android.widget.TextView")).getText();
    Assert.assertEquals("期望的名字是"+appName+",而实际是"+historyObjName,appName,historyObjName);
}
项目:SunmiAuto    文件:SunmiAppStore.java   
@Before
//每条测试用例开始前执行操作
public void setup() throws RemoteException, UiObjectNotFoundException, IOException {
    TestUtils.clearAllRecentApps();
    TestUtils.findAppAndOpenByText("应用市场");
    TestUtils.sleep(SHORT_SLEEP);
}
项目:SunmiAuto    文件:SunmiAppStore.java   
@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);
}
项目:SunmiAuto    文件:SunmiAppStore.java   
@Test
public void test008InstallAppFromHot() throws UiObjectNotFoundException, IOException {
    device.registerWatcher("downLoadFail", new UiWatcher() {
        @Override
        public boolean checkForCondition() {
            UiObject2 confirmObj = device.findObject(By.res("woyou.market:id/tv_confirm"));
            if(null != confirmObj){
                confirmObj.clickAndWait(Until.newWindow(),LONG_WAIT);
                return true;
            }
            return false;
        }
    });

    TestUtils.screenshotCap("appStoreHome");
    UiObject2 hotObj = device.findObject(By.res("woyou.market:id/tv_hot_all").text("全部"));
    hotObj.clickAndWait(Until.newWindow(), LONG_WAIT);
    TestUtils.screenshotCap("allHotAppsInterface");
    UiScrollable hotAllScroll = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
    hotAllScroll.scrollTextIntoView("安装");
    TestUtils.screenshotCap("ScrollToInstallableInterface");
    UiObject2 installObj = device.findObject(By.text("安装"));
    UiObject2 fullInstallObj = installObj.getParent().getParent();
    UiObject2 installNameObj = fullInstallObj.findObject(By.res("woyou.market:id/tv_name"));
    String name = installNameObj.getText();
    UiObject2 installObjnew =  fullInstallObj.getParent().findObject(By.text("安装"));
    installObjnew.click();
    TestUtils.screenshotCap("afterClickInstallBtn");
    boolean installSucc = installObjnew.wait(Until.textEquals("打开"),DOWNLOAD_WAIT);
    if(!installSucc){
        installObjnew.click();
        TestUtils.screenshotCap("installFailed");
        Assert.fail("下载安装了300秒,仍然未安装好,暂停了下载");
    }
    TestUtils.screenshotCap("afterInstalled");
    device.pressHome();
    Boolean b = TestUtils.findAppByText(name);
    TestUtils.screenshotCap("findInstalledApp");
    Assert.assertTrue("桌面上未找到\""+name+"\"这个应用",b);
}
项目:SunmiAuto    文件:SunmiAppStore.java   
@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();
    Assert.assertEquals("期望当前包名为com.sunmi.userfeedback,而实际为"+currentPkgName,"com.sunmi.userfeedback",currentPkgName);
}
项目:SunmiAuto    文件:SunmiAppStore.java   
@Test
public void test021CheckServiceProvider() 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("ScrollToServicePro");
    UiObject2 serviceProObj = device.findObject(By.text("服务商"));
    Assert.assertNotNull("未找到服务商信息",serviceProObj);
}