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

项目:FancyTrendView    文件:GoogleTrendActivityUiAutomatorTest.java   
@Before
public void startMainActivityFromHomeScreen() throws Exception {
    // Initialize UiDevice instance
    mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    // Start from the home screen
    mDevice.pressHome();

    // Wait for launcher
    final String launcherPackage = mDevice.getLauncherPackageName();
    assertThat(launcherPackage, notNullValue());
    mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)),
            LAUNCH_TIMEOUT);

    // Launch the blueprint app
    Context context = InstrumentationRegistry.getContext();
    final Intent intent = context.getPackageManager().getLaunchIntentForPackage(BASIC_PACKAGE);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);    // Clear out any previous instances
    context.startActivity(intent);
    // Wait for the app to appear
    mDevice.wait(Until.hasObject(By.pkg(BASIC_PACKAGE).depth(0)), LAUNCH_TIMEOUT);
}
项目:ChimpCheck    文件:ExampleInstrumentedTest.java   
@Before
public void startMainActivityFromHomeScreen() {
    // Initialize UiDevice instance
    mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());

    // Start from the home screen
    mDevice.pressHome();

    // Wait for launcher
    final String launcherPackage = getLauncherPackageName();
    assertThat(launcherPackage, notNullValue());
    mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT);

    // Launch the blueprint app
    Context context = InstrumentationRegistry.getContext();
    final Intent intent = context.getPackageManager()
            .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);    // Clear out any previous instances
    context.startActivity(intent);

    // Wait for the app to appear
    mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)), LAUNCH_TIMEOUT);
}
项目:Expert-Android-Programming    文件:UIAnimatorTest.java   
@Before
public void startMainActivityFromHomeScreen() {
    // Initialize UiDevice instance
    mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());

    // Start from the home screen
    mDevice.pressHome();

    // Wait for launcher
    final String launcherPackage = mDevice.getLauncherPackageName();
    Assert.assertThat(launcherPackage, CoreMatchers.notNullValue());
    mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)),
            LAUNCH_TIMEOUT);

    // Launch the app
    Context context = InstrumentationRegistry.getContext();
    final Intent intent = context.getPackageManager()
            .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE);
    // Clear out any previous instances
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    context.startActivity(intent);

    // Wait for the app to appear
    mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)),
            LAUNCH_TIMEOUT);
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Category(CategorySettingsTests.class)
@Test
public void test007CheckEnterAdvPass() {
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) {
        screenshotCap("setting_interface");
        UiObject2 wifiops = device.findObject(By.text("WLAN"));
        wifiops.clickAndWait(Until.newWindow(), LONG_WAIT);
        screenshotCap("wifi_interface");
        sleep(SHORT_SLEEP);
        UiObject2 moreBtn = device.findObject(By.clazz("android.widget.ImageButton").desc("更多选项"));
        moreBtn.click();
        sleep(SHORT_SLEEP);
        UiObject2 addNetworkObj = device.findObject(By.text("高级"));
        addNetworkObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        sleep(SHORT_SLEEP);
        UiObject2 advWLANObj = device.findObject(By.text("高级WLAN"));
        Assert.assertNotNull("没有能够进入到高级WLAN页面", advWLANObj);
    }
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Category(CategorySettingsTests.class)
@Test
public void test008CheckBTNamePASS() {
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) {
        screenshotCap("after_enter");
        UiObject2 WlanObj = device.findObject(By.text("蓝牙"));
        WlanObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        sleep(SHORT_SLEEP);
        screenshotCap("after_click");
        UiObject2 moreOptBtn = device.findObject(By.desc("更多选项"));
        moreOptBtn.click();
        sleep(SHORT_SLEEP);
        UiObject2 renameObj = device.findObject(By.text("重命名此设备"));
        renameObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        sleep(SHORT_SLEEP);
        UiObject2 nameObj = device.findObject(By.focused(true));
        String BTName = nameObj.getText();
        if("V1".equals(Build.MODEL)){
            Assert.assertEquals("蓝牙名称不正确", V1_BT_NAME, BTName);
        }else if("P1".equals(Build.MODEL)){
            Assert.assertEquals("蓝牙名称不正确", P1_BT_NAME, BTName);
        }
    }
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Test
public void test012CheckIbeacon() {
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) {
        screenshotCap("after_enter");
        UiObject2 moreObj = device.findObject(By.text("更多"));
        moreObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        UiObject2 ibeaconObj = device.findObject(By.text("iBeacon"));
        ibeaconObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        UiObject2 ibeaconTitle = device.findObject(By.res("com.sunmi.ibeacon:id/text").text("IBEACON"));
        Assert.assertNotNull("未找到IBEANCON标题", ibeaconTitle);
        UiObject2 ibeaconSwitch = device.findObject(By.res("com.sunmi.ibeacon:id/swi"));
        Assert.assertTrue("iBeacon开关没有打开", ibeaconSwitch.isChecked());
        //检查默认的ibeacon参数
        UiObject2 defaultIbeaconUUIDObj = device.findObject(By.res("com.sunmi.ibeacon:id/tv_uuid").text("FDA50693-A4E2-4FB1-AFCF-C6EB07647825"));
        UiObject2 defaultIbeaconMAJORObj = device.findObject(By.res("com.sunmi.ibeacon:id/tv_major").text("10073"));
        UiObject2 defaultIbeaconMINORObj = device.findObject(By.res("com.sunmi.ibeacon:id/tv_minor").text("61418"));
        Assert.assertNotNull("默认UUID不正确", defaultIbeaconUUIDObj);
        Assert.assertNotNull("默认MAJRO不正确", defaultIbeaconMAJORObj);
        Assert.assertNotNull("默认MINOR不正确", defaultIbeaconMINORObj);
    }
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Test
public void test014CheckNetShareStatus() {
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) {
        screenshotCap("after_enter");
        UiObject2 moreObj = device.findObject(By.text("更多"));
        moreObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        UiObject2 APObj = device.findObject(By.text("网络共享与便携式热点"));
        APObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        UiObject2 USBObj = device.findObject(By.text("USB网络共享")).getParent().getParent().findObject(By.res("android:id/switchWidget"));
        UiObject2 WLANObj = device.findObject(By.text("便携式WLAN热点")).getParent().getParent().findObject(By.res("android:id/switchWidget"));
        UiObject2 BTObj = device.findObject(By.text("蓝牙网络共享")).getParent().getParent().findObject(By.res("android:id/switchWidget"));
        Assert.assertFalse("USB网络共享默认不是关闭", USBObj.isChecked());
        Assert.assertFalse("便携式WLAN热点默认不是关闭", WLANObj.isChecked());
        Assert.assertFalse("蓝牙网络共享默认不是关闭", BTObj.isChecked());
    }
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Test
public void test015CheckAP() {
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) {
        screenshotCap("after_enter");
        UiObject2 moreObj = device.findObject(By.text("更多"));
        moreObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        UiObject2 APObj = device.findObject(By.text("网络共享与便携式热点"));
        APObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        UiObject2 WLANObj = device.findObject(By.text("设置WLAN热点"));
        WLANObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        UiObject2 ssidObj = device.findObject(By.res("com.android.settings:id/ssid"));
        ssidObj.clear();
        ssidObj.setText("SUNMITEST");
        UiObject2 pwdObj = device.findObject(By.res("com.android.settings:id/password"));
        pwdObj.clear();
        pwdObj.setText("12345678");
        UiObject2 saveObj = device.findObject(By.res("android:id/button1"));
        saveObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        UiObject2 APInfoObj = device.findObject(By.text("SUNMITEST WPA2 PSK便携式WLAN热点"));
        Assert.assertNotNull("未找到设置的SUNMITEST便携式热点", APInfoObj);
    }
}
项目: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
public void test043CheckAPDefaultName(){
    if("P1".equals(Build.MODEL)) {
        device.findObject(By.text("更多")).clickAndWait(Until.newWindow(), 5000);
        screenshotCap("更多界面显示");
        device.findObject(By.text("网络共享与便携式热点")).clickAndWait(Until.newWindow(), 5000);
        device.findObject(By.text("WLAN 热点")).clickAndWait(Until.newWindow(), 5000);
        device.findObject(By.text("设置WLAN热点")).clickAndWait(Until.newWindow(), 5000);
        sleep(1000);
        UiObject2 WlanNameObj = device.findObject(By.text("SunmiP1"));
        screenshotCap("设置WLAN界面");
        Assert.assertNotNull("测试失败,默认名称不是SunmiP1", WlanNameObj);
    }
    else if ("V1".equals(Build.MODEL)){

    }
}
项目:SunmiAuto    文件:SunmiAppStore_v3_3_15.java   
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test011ClickHotSearchApp(){
    TestUtils.screenshotCap("appStoreHome");
    UiObject2 searchObj = device.findObject(By.res("woyou.market:id/tv_search").text("搜索"));
    searchObj.click();
    TestUtils.screenshotCap("afterClickSearchBar");
    TestUtils.sleep(SHORT_SLEEP);
    int hotAppCount = device.findObject(By.res("woyou.market:id/grid_view")).getChildCount();
    if(hotAppCount != 0){
        String appName = device.findObject(By.res("woyou.market:id/grid_view")).findObject(By.res("woyou.market:id/tv_name")).getText();
        UiObject2 hotSearchObj = device.findObject(By.res("woyou.market:id/grid_view")).findObject(By.res("woyou.market:id/item_app"));
        hotSearchObj.clickAndWait(Until.newWindow(),LONG_WAIT);
        TestUtils.screenshotCap("clickHotsearchFirstOne");
        UiObject2 appDetailObj = device.findObject(By.res("woyou.market:id/tv_name"));
        String appDetailName = appDetailObj.getText();
        Assert.assertEquals(appName,appDetailName);
    }else{
        Assert.fail("没有任何热搜应用,需要确定是否确实不存在热搜应用");
    }
}
项目: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 test011ClickHotSearchApp(){
    TestUtils.screenshotCap("appStoreHome");
    UiObject2 searchObj = device.findObject(By.res("woyou.market:id/tv_search").text("搜索"));
    searchObj.click();
    TestUtils.screenshotCap("afterClickSearchBar");
    TestUtils.sleep(SHORT_SLEEP);
    int hotAppCount = device.findObject(By.res("woyou.market:id/grid_view")).getChildCount();
    if(hotAppCount != 0){
        String appName = device.findObject(By.res("woyou.market:id/grid_view")).findObject(By.res("woyou.market:id/tv_name")).getText();
        UiObject2 hotSearchObj = device.findObject(By.res("woyou.market:id/grid_view")).findObject(By.res("woyou.market:id/item_app"));
        hotSearchObj.clickAndWait(Until.newWindow(),LONG_WAIT);
        TestUtils.screenshotCap("clickHotsearchFirstOne");
        UiObject2 appDetailObj = device.findObject(By.res("woyou.market:id/tv_name"));
        String appDetailName = appDetailObj.getText();
        Assert.assertEquals(appName,appDetailName);
    }else{
        Assert.fail("没有任何热搜应用,需要确定是否确实不存在热搜应用");
    }
}
项目:SimpleUILauncher    文件:LauncherInstrumentationTestCase.java   
/**
 * Drags an icon to the center of homescreen.
 */
protected void dragToWorkspace(UiObject2 icon) {
    Point center = icon.getVisibleCenter();

    // Action Down
    sendPointer(MotionEvent.ACTION_DOWN, center);

    // Wait until "Remove/Delete target is visible
    assertNotNull(findViewById(R.id.delete_target_text));

    Point moveLocation = findViewById(R.id.drag_layer).getVisibleCenter();

    // Move to center
    while(!moveLocation.equals(center)) {
        center.x = getNextMoveValue(moveLocation.x, center.x);
        center.y = getNextMoveValue(moveLocation.y, center.y);
        sendPointer(MotionEvent.ACTION_MOVE, center);
    }
    sendPointer(MotionEvent.ACTION_UP, center);

    // Wait until remove target is gone.
    mDevice.wait(Until.gone(getSelectorForId(R.id.delete_target_text)), DEFAULT_UI_TIMEOUT);
}
项目:SimpleUILauncher    文件:AllAppsIconToHomeTest.java   
private void performTest() throws Throwable {
    clearHomescreen();
    startLauncher();

    // Open all apps and wait for load complete.
    final UiObject2 appsContainer = openAllApps();
    assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT));

    // Drag icon to homescreen.
    UiObject2 icon = scrollAndFind(appsContainer, By.text(mSettingsApp.getLabel().toString()));
    dragToWorkspace(icon);

    // Verify that the icon works on homescreen.
    mDevice.findObject(By.text(mSettingsApp.getLabel().toString())).click();
    assertTrue(mDevice.wait(Until.hasObject(By.pkg(
            mSettingsApp.getComponentName().getPackageName()).depth(0)), DEFAULT_UI_TIMEOUT));
}
项目: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);
}
项目:SunmiAuto    文件:TestUtils.java   
public static void uiwatchSuite(){
    device.registerWatcher("crash", new UiWatcher() {
        @Override
        public boolean checkForCondition() {
            UiObject2 crashObj = device.findObject(By.textEndsWith("已停止运行。"));
            Log.v("myautotest","enterWatch");
            if(crashObj != null){
                sleep(SHORT_SLEEP);
                device.findObject(By.text("确定")).clickAndWait(Until.newWindow(),LONG_WAIT);
                return true;
            }
            return false;
        }
    });

}
项目:FlickLauncher    文件:AllAppsIconToHomeTest.java   
private void performTest() throws Throwable {
    clearHomescreen();
    startLauncher();

    // Open all apps and wait for load complete.
    final UiObject2 appsContainer = openAllApps();
    assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT));

    // Drag icon to homescreen.
    UiObject2 icon = scrollAndFind(appsContainer, By.text(mSettingsApp.getLabel().toString()));
    dragToWorkspace(icon);

    // Verify that the icon works on homescreen.
    mDevice.findObject(By.text(mSettingsApp.getLabel().toString())).click();
    assertTrue(mDevice.wait(Until.hasObject(By.pkg(
            mSettingsApp.getComponentName().getPackageName()).depth(0)), DEFAULT_UI_TIMEOUT));
}
项目:FlickLauncher    文件:LauncherInstrumentationTestCase.java   
/**
 * Drags an icon to the center of homescreen.
 */
protected void dragToWorkspace(UiObject2 icon) {
    Point center = icon.getVisibleCenter();

    // Action Down
    sendPointer(MotionEvent.ACTION_DOWN, center);

    // Wait until "Remove/Delete target is visible
    assertNotNull(findViewById(R.id.delete_target_text));

    Point moveLocation = findViewById(R.id.drag_layer).getVisibleCenter();

    // Move to center
    while(!moveLocation.equals(center)) {
        center.x = getNextMoveValue(moveLocation.x, center.x);
        center.y = getNextMoveValue(moveLocation.y, center.y);
        sendPointer(MotionEvent.ACTION_MOVE, center);
    }
    sendPointer(MotionEvent.ACTION_UP, center);

    // Wait until remove target is gone.
    mDevice.wait(Until.gone(getSelectorForId(R.id.delete_target_text)), DEFAULT_UI_TIMEOUT);
}
项目:notification-adapter    文件:NotificationAdapterTest.java   
@Test
public void testNotificationAdapter() {
    final String NOTIFICATION_TEXT = "adapter-text";
    final String NOTIFICATION_TITLE = "adapter-title";
    final long TIMEOUT = 5000;

    Context appContext = InstrumentationRegistry.getTargetContext();

    RemoteViews contentView = new RemoteViews("cn.dreamtobe.toolset.test", R.layout.custom_layout);
    contentView.setTextViewText(R.id.title, NOTIFICATION_TITLE);
    contentView.setTextViewText(R.id.text, NOTIFICATION_TEXT);

    // Fix the Notification-Style problem ---------------
    // Set the default title style color to title view.
    contentView.setTextColor(R.id.title, NotificationAdapter.getTitleColor(appContext));
    // Set the default title style size to title view
    contentView.setTextViewTextSize(R.id.title, COMPLEX_UNIT_PX, NotificationAdapter.getTitleSize(appContext));
    // Set the default text style color to text view
    contentView.setTextColor(R.id.text, NotificationAdapter.getTextColor(appContext));
    // Set the default text style size to text view
    contentView.setTextViewTextSize(R.id.text, COMPLEX_UNIT_PX, NotificationAdapter.getTextSize(appContext));
    // End fix the Notification-Style problem ---------------

    Notification notification = new Notification();
    notification.icon = R.drawable.ic_launcher;
    notification.contentView = contentView;

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;

    NotificationManager notifyMgr =
            (NotificationManager) appContext.getSystemService(NOTIFICATION_SERVICE);
    notifyMgr.notify(1, notification);

    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    device.openNotification();
    device.wait(Until.hasObject(By.text(NOTIFICATION_TITLE)), TIMEOUT);
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Before
public void setup() throws IOException, RemoteException {
    TestUtils.clearAllRecentApps();
    TestUtils.findAppByText("设置");
    long begin = System.currentTimeMillis();
    UiObject2 setObj = device.findObject(By.text("设置"));
    long end = System.currentTimeMillis();
    Log.v(LOG_V, String.valueOf(end - begin));
    setObj.clickAndWait(Until.newWindow(), LONG_WAIT);
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Category(CategorySettingsTests.class)
@Test
public void test001WiFi() {
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) {
        screenshotCap("setting_interface");
        UiObject2 wifiops = device.findObject(By.text("WLAN"));
        wifiops.clickAndWait(Until.newWindow(), LONG_WAIT);
        screenshotCap("wifi_interface");
        UiObject2 wifiButton = device.findObject(By.res("com.android.settings:id/switch_widget"));
        Assert.assertEquals("Wifi开关默认应该为打开状态", true, wifiButton.isChecked());
    }
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Category(CategorySettingsTests.class)
@Test
public void test002DataUsage() {
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) {
        screenshotCap("setting_interface");
        UiObject2 ethOps = device.findObject(By.text("流量使用情况"));
        ethOps.clickAndWait(Until.newWindow(), LONG_WAIT);
        screenshotCap("dataUsage_interface");
        UiObject2 dataUsageObj = device.findObject(By.text("流量使用情况").clazz("android.widget.TextView"));
        Assert.assertNotNull("未找到流量使用情况标识", dataUsageObj);
    }
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Category(CategorySettingsTests.class)
@Test
public void test006CheckWLANStatus() {
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) {
        screenshotCap("setting_interface");
        UiObject2 wifiops = device.findObject(By.text("WLAN"));
        wifiops.clickAndWait(Until.newWindow(), LONG_WAIT);
        screenshotCap("wifi_interface");
        UiObject2 wifiButton = device.findObject(By.res("com.android.settings:id/switch_widget"));
        Assert.assertEquals("Wifi开关默认应该为打开状态", true, wifiButton.isChecked());
    }
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Category(CategorySettingsTests.class)
@Test
public void test009CheckBTRenamePASS() {
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) {
        screenshotCap("after_enter");
        UiObject2 WlanObj = device.findObject(By.text("蓝牙"));
        WlanObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        sleep(SHORT_SLEEP);
        screenshotCap("after_click");
        UiObject2 moreOptBtn = device.findObject(By.desc("更多选项"));
        moreOptBtn.click();
        sleep(SHORT_SLEEP);
        UiObject2 renameObj = device.findObject(By.text("重命名此设备"));
        renameObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        sleep(SHORT_SLEEP);
        UiObject2 nameObj = device.findObject(By.focused(true));
        nameObj.clear();
        nameObj.setText("TESTV1");
        UiObject2 renameBtn = device.findObject(By.text("重命名"));
        renameBtn.clickAndWait(Until.newWindow(), LONG_WAIT);
        sleep(SHORT_SLEEP);
        UiObject2 moreOptBtn1 = device.findObject(By.desc("更多选项"));
        moreOptBtn1.click();
        sleep(SHORT_SLEEP);
        UiObject2 renameObj1 = device.findObject(By.text("重命名此设备"));
        renameObj1.clickAndWait(Until.newWindow(), LONG_WAIT);
        sleep(SHORT_SLEEP);
        UiObject2 nameObj1 = device.findObject(By.focused(true));
        String BTName = nameObj1.getText();
        Assert.assertEquals("蓝牙改名失败", "TESTV1", BTName);
        nameObj1.clear();
        if("V1".equals(Build.MODEL)){
            nameObj1.setText(V1_BT_NAME);
        }else if("P1".equals(Build.MODEL)){
            nameObj1.setText(P1_BT_NAME);
        }
        UiObject2 renameBtn1 = device.findObject(By.text("重命名"));
        renameBtn1.clickAndWait(Until.newWindow(), LONG_WAIT);
    }
}
项目:SimpleUILauncher    文件:LauncherInstrumentationTestCase.java   
/**
 * Opens widget tray and returns the recycler view.
 */
protected UiObject2 openWidgetsTray() {
    mDevice.pressMenu(); // Enter overview mode.
    mDevice.wait(Until.findObject(
            By.text(mTargetContext.getString(R.string.widget_button_text)
                    .toUpperCase(Locale.getDefault()))), DEFAULT_UI_TIMEOUT).click();
    return findViewById(R.id.widgets_list_view);
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Category(CategorySettingsTests.class)
@Test
public void test011CheckAirPlaneStatus() {
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) {
        screenshotCap("after_enter");
        UiObject2 moreObj = device.findObject(By.text("更多"));
        moreObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        UiObject2 airplaneSwitch = device.findObject(By.text("飞行模式")).getParent().getParent().findObject(By.res("android:id/switchWidget"));
        Boolean airplaneOpen = airplaneSwitch.isChecked();
        Assert.assertFalse("飞行模式不是关闭状态", airplaneOpen);
    }
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Test
public void test013CheckIbeaconSetting() {
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) {
        screenshotCap("after_enter");
        UiObject2 moreObj = device.findObject(By.text("更多"));
        moreObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        UiObject2 ibeaconObj = device.findObject(By.text("iBeacon"));
        ibeaconObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        UiObject2 ibeaconSetObj = device.findObject(By.res("com.sunmi.ibeacon:id/tv_setting").text("设置iBeacon"));
        ibeaconSetObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        device.pressBack();
        UiObject2 othersUUIDObj = device.findObject(By.text("其他"));
        othersUUIDObj.click();
        UiObject2 setUUIDObj = device.findObject(By.focused(true));
        setUUIDObj.setText("11111111-2222-3333-4444-012345678910");
        UiObject2 setMAJORObj = device.findObject(By.res("com.sunmi.ibeacon:id/et_major"));
        setMAJORObj.setText("12345");
        UiObject2 setMINORObj = device.findObject(By.res("com.sunmi.ibeacon:id/et_minor"));
        setMINORObj.setText("54321");
        UiObject2 confirmObj = device.findObject(By.res("com.sunmi.ibeacon:id/tv_confirm"));
        confirmObj.click();
        UiObject2 UUIDObj = device.findObject(By.res("com.sunmi.ibeacon:id/tv_uuid").text("11111111-2222-3333-4444-012345678910"));
        Assert.assertNotNull("UUID未设置成功", UUIDObj);
        UiObject2 MAJORObj = device.findObject(By.res("com.sunmi.ibeacon:id/tv_major").text("12345"));
        Assert.assertNotNull("MAJOR未设置成功", MAJORObj);
        UiObject2 MINORObj = device.findObject(By.res("com.sunmi.ibeacon:id/tv_minor").text("54321"));
        Assert.assertNotNull("MINOR未设置成功", MINORObj);
        ibeaconSetObj.clickAndWait(Until.newWindow(), LONG_WAIT);
        device.pressBack();
        UiObject2 wechatUUIDObj = device.findObject(By.text("微信"));
        wechatUUIDObj.click();
        UiObject2 confirmObj1 = device.findObject(By.res("com.sunmi.ibeacon:id/tv_confirm"));
        confirmObj1.clickAndWait(Until.newWindow(), LONG_WAIT);
    }
}
项目:UIAutomatorAdapter    文件:AutoTestAdapter.java   
private void clickUiobjectByDes(String desc) {
    UiObject2 d = mDevice.wait(Until.findObject(By.desc(desc)), timeout);
    if (d != null) {
        d.click();
        return;
    }
    Log.i(logTag, "Cannot find UiObject2 by desc " + desc);
}
项目: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 test027CheckWifiNotificationStatus(){
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) {
        device.findObject(By.text("WLAN")).clickAndWait(Until.newWindow(), 5000);
        device.findObject(By.desc("更多选项")).click();
        sleep(1000);
        device.findObject(By.text("高级")).clickAndWait(Until.newWindow(), 5000);
        screenshotCap("after_enter");
        UiObject2 NoticeObj = device.findObject(By.res("android:id/switchWidget"));
        Assert.assertTrue("测试失败,网络通知默认为关闭", NoticeObj.isChecked());
    }
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Test
public void test035ModifyPairedDeviceName(){
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) {
        screenshotCap("after_enter");
        device.findObject(By.text("蓝牙")).clickAndWait(Until.newWindow(), 5000);
        sleep(1000);
        UiObject2 SwitchObj = device.findObject(By.res("com.android.settings:id/switch_widget"));
        screenshotCap("after_enter");
        if (SwitchObj.isChecked() == false) {//判断蓝牙开关状态
            SwitchObj.click();
            sleep(3000);
        }
        device.findObject(By.res("com.android.settings:id/deviceDetails")).click();
        sleep(1000);
        device.findObject(By.res("com.android.settings:id/name")).setText("测试重命名");
        sleep(1000);
        device.findObject(By.text("确定")).click();
        sleep(1000);
        screenshotCap("after_enter");
        UiObject2 TestObj = device.findObject(By.text("测试重命名"));
        Assert.assertNotNull("测试失败,未找到修改后的蓝牙名", TestObj);
        sleep(1000);
        device.findObject(By.res("com.android.settings:id/deviceDetails")).click();
        sleep(1000);
        device.findObject(By.res("com.android.settings:id/name")).setText("InnerPrinter");
        sleep(1000);
        device.findObject(By.text("确定")).click();
    }
}
项目:SunmiAuto    文件:SunmiSettings.java   
@Test
public void test047CheckAirplaneStatus(){
    if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) {
        device.findObject(By.text("更多")).clickAndWait(Until.newWindow(), 5000);
        UiObject2 SwitchObj = device.findObject(By.res("android:id/switchWidget"));
        screenshotCap("更多界面显示");
        Assert.assertFalse("测试失败,飞行模式开关默认不是关闭", SwitchObj.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());

    }
}