private UiObject2 doFindObject(Object selector, AccessibilityNodeInfo node) throws Exception { Class uiObject2 = Class.forName("android.support.test.uiautomator.UiObject2"); Constructor cons = uiObject2.getDeclaredConstructors()[0]; cons.setAccessible(true); Object[] constructorParams = {uiDevice, selector, node}; final long timeoutMillis = 1000; long end = SystemClock.uptimeMillis() + timeoutMillis; while (true) { UiObject2 object2 = (UiObject2) cons.newInstance(constructorParams); if (object2 != null) { return object2; } long remainingMillis = end - SystemClock.uptimeMillis(); if (remainingMillis < 0) { return null; } SystemClock.sleep(Math.min(200, remainingMillis)); } }
@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); } }
@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); } } }
@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); } }
@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()); } }
@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(); }
@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()); // } }
private void performTest() throws Throwable { clearHomescreen(); Launcher launcher = startLauncher(); // Open widget tray and wait for load complete. final UiObject2 widgetContainer = openWidgetsTray(); assertTrue(Wait.atMost(Condition.minChildCount(widgetContainer, 2), DEFAULT_UI_TIMEOUT)); // Drag widget to homescreen UiObject2 widget = scrollAndFind(widgetContainer, By.clazz(WidgetCell.class) .hasDescendant(By.text(widgetInfo.getLabel(mTargetContext.getPackageManager())))); dragToWorkspace(widget); assertNotNull(launcher.getWorkspace().getFirstMatch(new ItemOperator() { @Override public boolean evaluate(ItemInfo info, View view) { return info instanceof LauncherAppWidgetInfo && ((LauncherAppWidgetInfo) info).providerName.equals(widgetInfo.provider); } })); }
@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)){ } }
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)); }
@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("没有任何热搜应用,需要确定是否确实不存在热搜应用"); } }
@Category(CategoryAppStoreTests_v3_3_15.class) @Test public void test012ClearSearchBarButton(){ TestUtils.screenshotCap("appStoreHome"); 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("DUDU"); TestUtils.screenshotCap("inputSearchContentInterface"); UiObject2 clearButton = device.findObject(By.res("woyou.market:id/iv_delete")); clearButton.click(); TestUtils.screenshotCap("afterClickClearBtn"); UiObject2 searchObj2 = device.findObject(By.res("woyou.market:id/et_search")); String textContent = searchObj2.getText(); Assert.assertEquals("搜索",textContent); }
@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); }
private static UiObject2 getAlertButton(String alertType) throws Exception { UiDevice mDevice = Elements.getGlobal().getmDevice(); int buttonIndex; if (alertType.equals("accept")) { buttonIndex = 1; } else if (alertType.equals("dismiss")) { buttonIndex = 0; } else { throw new Exception("alertType can only be 'accept' or 'dismiss'"); } List<UiObject2> alertButtons = mDevice.findObjects(By.clazz("android.widget.Button").clickable(true).checkable(false)); if (alertButtons.size() == 0) { return null; } UiObject2 alertButton = alertButtons.get(buttonIndex); return alertButton; }
@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()); }
@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("没有任何热搜应用,需要确定是否确实不存在热搜应用"); } }
@Test public void test012ClearSearchBarButton(){ TestUtils.screenshotCap("appStoreHome"); 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(SEARCH_APP); TestUtils.screenshotCap("inputSearchContentInterface"); UiObject2 clearButton = device.findObject(By.res("woyou.market:id/iv_delete")); clearButton.click(); TestUtils.screenshotCap("afterClickClearBtn"); UiObject2 searchObj2 = device.findObject(By.res("woyou.market:id/et_search")); String textContent = searchObj2.getText(); Assert.assertEquals("清除搜索框内容后,搜索框中不显示搜索","搜索",textContent); }
@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); }
@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(); }
@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); }
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; } }); }
@Test public void clickTest(){ List<UiObject2> objects = mDevice.findObjects(By.clickable(true)); UiObject2 obj = objects.get(1); Log.d("TAG", obj.getResourceName()); Resources r = getActivityInstance().getResources(); Wrapper wr = helper(obj.getResourceName()); int id = r.getIdentifier(wr.name, wr.defType, wr.defPackage); Log.d("TAG", Integer.toString(id)); Espresso.onView(withId(id)).perform(click()); objects = mDevice.findObjects(By.clickable(true)); obj = objects.get(1); wr = helper(obj.getResourceName()); id = r.getIdentifier(wr.name, wr.defType, wr.defPackage); Espresso.onView(allOf(withId(id), supportsInputMethods() )).perform(typeText("string to be typed")); }
/** * Scrolls the {@param container} until it finds an object matching {@param condition}. * @return the matching object. */ protected UiObject2 scrollAndFind(UiObject2 container, BySelector condition) { do { UiObject2 widget = container.findObject(condition); if (widget != null) { return widget; } } while (container.scroll(Direction.DOWN, 1f)); return container.findObject(condition); }
@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); } }
@Category(CategorySettingsTests.class) @Test public void test003OpenBT() { if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) { screenshotCap("after_enter"); UiObject2 WlanObj = device.findObject(By.text("蓝牙")); WlanObj.click(); sleep(SHORT_SLEEP); screenshotCap("after_click"); UiObject2 BTButtonObj = device.findObject(By.res("com.android.settings:id/switch_widget")); sleep(SHORT_SLEEP); Assert.assertTrue("蓝牙开关默认不是打开状态", BTButtonObj.isChecked()); } }
@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()); } }
@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); } }
public static Condition minChildCount(final UiObject2 obj, final int childCount) { return new Condition() { @Override public boolean isTrue() { return obj.getChildCount() >= childCount; } }; }
@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); } }
@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); } }
/** * Returns the first object to match the {@code selector} criteria. */ public UiObject2 findObject(Object selector) throws Exception { AccessibilityNodeInfo node; uiDevice.waitForIdle(); node = ((NodeInfoList) selector).getNodeList().size() > 0 ? ((NodeInfoList) selector).getNodeList().get(0) : null; selector = By.clazz(node.getClassName().toString()); if (node == null) { return null; } return doFindObject(selector, node); }
@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); }
@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); }
@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); } }
@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()); } }
@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()); } }
@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()); } }
@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()); }
@Category(CategoryAppStoreTests_v3_3_15.class) @Test public void test001OpenAppStore() { TestUtils.screenshotCap("appStoreHome"); UiObject2 suggObj = device.findObject(By.res("woyou.market:id/fab_me")); Assert.assertNotNull("未找到用户入口,判断打开应用市场失败", suggObj); }