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

项目: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();
}
项目: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");
}
项目: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();
}
项目:akvo-caddisfly    文件:TestUtil.java   
public static boolean clickListViewItem(String name) {
    UiScrollable listView = new UiScrollable(new UiSelector());
    listView.setMaxSearchSwipes(4);
    listView.waitForExists(3000);
    UiObject listViewItem;
    try {
        if (listView.scrollTextIntoView(name)) {
            listViewItem = listView.getChildByText(new UiSelector()
                    .className(TextView.class.getName()), "" + name + "");
            listViewItem.click();
        } else {
            return false;
        }
    } catch (UiObjectNotFoundException e) {
        return false;
    }
    return true;
}
项目: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);
}
项目: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   
@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);
}
项目:SunmiAuto    文件:SunmiAppStore.java   
@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.java   
@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().resourceId("woyou.market:id/app_view"));
    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.java   
@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().resourceId("woyou.market:id/app_view"),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);
}
项目:FancyTrendView    文件:GoogleTrendActivityUiAutomatorTest.java   
@Test
public void mainActivity_RecycleViewChangeCountry() 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();
    item.click();
    mDevice.waitForIdle();
    takeScreenShot("Country_menu_page.jpg");
}
项目:FancyTrendView    文件:GoogleTrendActivityUiAutomatorTest.java   
private boolean selectSettingsFor(String name)  {
    try {
        UiScrollable appsSettingsList = new UiScrollable(SettingsHelper.SCROLL_VIEW);
        UiObject obj = appsSettingsList.getChildByText(SettingsHelper.LIST_VIEW_ITEM, name);
        obj.click();
    } catch (UiObjectNotFoundException e) {
        return false;
    }
    return true;
}
项目:firefox-tv    文件:SwitchLocaleTest.java   
@Test
public void FrenchLocaleTest() throws InterruptedException, UiObjectNotFoundException {

    UiObject frenchMenuItem = TestHelper.mDevice.findObject(new UiSelector()
            .className("android.widget.TextView")
            .text("Valeur par défaut du système"));
    UiObject englishMenuItem = TestHelper.mDevice.findObject(new UiSelector()
            .className("android.widget.TextView")
            .text("English (United States)"));
    UiObject englishLocaleinFr = TestHelper.mDevice.findObject(new UiSelector()
            .className("android.widget.CheckedTextView")
            .text("English (United States)"));

    /* Go to Settings */
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);

    openSettings();
    LanguageSelection.waitForExists(waitingTime);

    /* system locale is in French, check it is now set to system locale */
    frenchHeading.waitForExists(waitingTime);
    Assert.assertTrue(frenchHeading.exists());
    Assert.assertTrue(frenchMenuItem.exists());
    LanguageSelection.click();
    Assert.assertTrue(sysDefaultLocale.isChecked());

    /* change locale to English in the setting, verify the locale is changed */
    UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
    appViews.scrollIntoView(englishLocaleinFr);
    Assert.assertTrue(englishLocaleinFr.isClickable());
    englishLocaleinFr.click();
    englishHeading.waitForExists(waitingTime);
    Assert.assertTrue(englishHeading.exists());
    Assert.assertTrue(englishMenuItem.exists());
}
项目:focus-android    文件:SwitchLocaleTest.java   
@Test
public void FrenchLocaleTest() throws InterruptedException, UiObjectNotFoundException {

    UiObject frenchMenuItem = TestHelper.mDevice.findObject(new UiSelector()
            .className("android.widget.TextView")
            .text("Valeur par défaut du système"));
    UiObject englishMenuItem = TestHelper.mDevice.findObject(new UiSelector()
            .className("android.widget.TextView")
            .text("English (United States)"));
    UiObject englishLocaleinFr = TestHelper.mDevice.findObject(new UiSelector()
            .className("android.widget.CheckedTextView")
            .text("English (United States)"));

    /* Go to Settings */
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);

    openSettings();
    LanguageSelection.waitForExists(waitingTime);

    /* system locale is in French, check it is now set to system locale */
    frenchHeading.waitForExists(waitingTime);
    Assert.assertTrue(frenchHeading.exists());
    Assert.assertTrue(frenchMenuItem.exists());
    LanguageSelection.click();
    Assert.assertTrue(sysDefaultLocale.isChecked());

    /* change locale to English in the setting, verify the locale is changed */
    UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
    appViews.scrollIntoView(englishLocaleinFr);
    Assert.assertTrue(englishLocaleinFr.isClickable());
    englishLocaleinFr.click();
    englishHeading.waitForExists(waitingTime);
    Assert.assertTrue(englishHeading.exists());
    Assert.assertTrue(englishMenuItem.exists());
}
项目:appium-uiautomator2-server    文件:UiScrollableParser.java   
private void consumeConstructor() throws UiSelectorSyntaxException {
    if (text.charAt(0) != '(') {
        throw new UiSelectorSyntaxException("Was expecting \"" + ")" + "\" but instead saw \"" + text.charAt(0) + "\"");
    }
    StringBuilder argument = new StringBuilder();

    int index = 1;
    int parenCount = 1;
    while (parenCount > 0) {
        try {
            switch (text.charAt(index)) {
                case ')':
                    parenCount--;
                    if (parenCount > 0) {
                        argument.append(text.charAt(index));
                    }
                    break;
                case '(':
                    parenCount++;
                    argument.append(text.charAt(index));
                    break;
                default:
                    argument.append(text.charAt(index));
            }
        } catch (StringIndexOutOfBoundsException e) {
            throw new UiSelectorSyntaxException("unclosed paren in expression");
        }
        index++;
    }
    if (argument.length() < 1) {
        throw new UiSelectorSyntaxException("UiScrollable constructor expects an argument");
    }

    UiSelector selector = new UiSelectorParser().parse(argument.toString());
    scrollable = new UiScrollable(selector);

    // add two for parentheses surrounding arg
    text = text.substring(argument.length() + 2);
}
项目:android-uiautomator-server    文件:AutomatorServiceImpl.java   
/**
 * Searches for child UI element within the constraints of this UiSelector selector. It looks for any child matching the childPattern argument that has a child UI element anywhere within its sub hierarchy that has a text attribute equal to text. The returned UiObject will point at the childPattern instance that matched the search and not at the identifying child element that matched the text attribute.
 *
 * @param collection Selector of UiCollection or UiScrollable.
 * @param text       String of the identifying child contents of of the childPattern
 * @param child      UiSelector selector of the child pattern to match and return
 * @return A string ID represent the returned UiObject.
 */
@Override
public String childByText(Selector collection, Selector child, String text) throws UiObjectNotFoundException {
    UiObject obj;
    if (exist(collection) && objInfo(collection).isScrollable()) {
        obj = new UiScrollable(collection.toUiSelector()).getChildByText(child.toUiSelector(), text);
    } else {
        obj = new UiCollection(collection.toUiSelector()).getChildByText(child.toUiSelector(), text);
    }
    return addUiObject(obj);
}
项目:android-uiautomator-server    文件:AutomatorServiceImpl.java   
/**
 * Searches for child UI element within the constraints of this UiSelector selector. It looks for any child matching the childPattern argument that has a child UI element anywhere within its sub hierarchy that has content-description text. The returned UiObject will point at the childPattern instance that matched the search and not at the identifying child element that matched the content description.
 *
 * @param collection Selector of UiCollection or UiScrollable
 * @param child      UiSelector selector of the child pattern to match and return
 * @param text       String of the identifying child contents of of the childPattern
 * @return A string ID represent the returned UiObject.
 */
@Override
public String childByDescription(Selector collection, Selector child, String text) throws UiObjectNotFoundException {
    UiObject obj;
    if (exist(collection) && objInfo(collection).isScrollable()) {
        obj = new UiScrollable(collection.toUiSelector()).getChildByDescription(child.toUiSelector(), text);
    } else {
        obj = new UiCollection(collection.toUiSelector()).getChildByDescription(child.toUiSelector(), text);
    }
    return addUiObject(obj);
}
项目:android-uiautomator-server    文件:AutomatorServiceImpl.java   
/**
 * Searches for child UI element within the constraints of this UiSelector. It looks for any child matching the childPattern argument that has a child UI element anywhere within its sub hierarchy that is at the instance specified. The operation is performed only on the visible items and no scrolling is performed in this case.
 *
 * @param collection Selector of UiCollection or UiScrollable
 * @param child      UiSelector selector of the child pattern to match and return
 * @param instance   int the desired matched instance of this childPattern
 * @return A string ID represent the returned UiObject.
 */
@Override
public String childByInstance(Selector collection, Selector child, int instance) throws UiObjectNotFoundException {
    UiObject obj;
    if (exist(collection) && objInfo(collection).isScrollable()) {
        obj = new UiScrollable(collection.toUiSelector()).getChildByInstance(child.toUiSelector(), instance);
    } else {
        obj = new UiCollection(collection.toUiSelector()).getChildByInstance(child.toUiSelector(), instance);
    }
    return addUiObject(obj);
}
项目:android-testing    文件:AutomatorTest.java   
public void testCalculator() throws Exception {
    uiDevice.findObject(new UiSelector().descriptionContains("Apps")).clickAndWaitForNewWindow();

    UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
    appViews.setAsHorizontalList();

    UiObject calculatorApp = appViews.getChildByText(new UiSelector()
            .className(android.widget.TextView.class.getName()), "Calculator");
    calculatorApp.clickAndWaitForNewWindow();

    // Calculator app
    UiObject threeButton = uiDevice.findObject(new UiSelector().text("3"));
    threeButton.click();

    UiObject plusButton = uiDevice.findObject(new UiSelector().text("+"));
    plusButton.click();

    UiObject fiveButton = uiDevice.findObject(new UiSelector().text("5"));
    fiveButton.click();

    UiObject equalsButton = uiDevice.findObject(new UiSelector().text("="));
    equalsButton.click();

    UiObject display = uiDevice.findObject(new UiSelector()
            .resourceId("com.android.calculator2:id/display"));
    UiObject displayNumber = display.getChild(new UiSelector().index(0));

    assertEquals(displayNumber.getText(), "8");

    uiDevice.pressHome();
}
项目:android-testing    文件:AutomatorTest.java   
public void testBrowserApp() throws Exception {
    uiDevice.findObject(new UiSelector().descriptionContains("Apps")).clickAndWaitForNewWindow();

    UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
    appViews.setAsHorizontalList();

    UiObject browserApp = appViews.getChildByText(new UiSelector()
            .className(android.widget.TextView.class.getName()), "Browser");
    browserApp.clickAndWaitForNewWindow();

    // Browser App set url
    UiObject urlForm = uiDevice.findObject(new UiSelector()
            .resourceId("com.android.browser:id/url"));
    urlForm.setText("http://www.google.cz");
    //uiDevice.pressKeyCode(KeyEvent.KEYCODE_ENTER);
    uiDevice.pressEnter();

    // Wait to load page
    SystemClock.sleep(10000);

    // Click on webview to lose focus from form
    UiObject webView = uiDevice.findObject(new UiSelector()
            .className("android.webkit.WebView"));
    webView.click();

    uiDevice.pressMenu();

    // Sleep to show the menu
    SystemClock.sleep(1000);
    UiObject refreshButton = uiDevice.findObject(new UiSelector()
            .text("Refresh"));
    refreshButton.click();
}