@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); }
@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); }
@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 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); } }
@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(); }
@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 static BySelector getSelector(String strategy, String text) throws Exception { BySelector selector = null; switch (strategy) { case "CLASS_NAME": selector = By.clazz(text); break; case "NAME": selector = By.desc(text); if(selector == null || elements.getmDevice().findObject(selector) == null){ selector = By.text(text); } break; case "ID": selector = By.res(text); break; } return selector; }
@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)){ } }
@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()); }
@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); }
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); } })); }
@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); }
@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); }
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)); }
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; }
public List<UiObject2> findObjects(Object selector) throws Exception { uiDevice.waitForIdle(); ArrayList<AccessibilityNodeInfo> accessibilityNodeInfos = ((NodeInfoList) selector).getNodeList(); int size = accessibilityNodeInfos.size(); List<UiObject2> list = new ArrayList<UiObject2>(); if (size > 0) { for (int i = 0; i < size; i++) { AccessibilityNodeInfo node = accessibilityNodeInfos.get(i); if (node == null) { continue; } selector = By.clazz(node.getClassName().toString()); UiObject2 uiObject2 = doFindObject(selector, node); list.add(uiObject2); } } else { return null; } return list; }
@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 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); }
@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); }
@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()); } }
@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 test010CheckDataUsage() { if("V1".equals(Build.MODEL) || "P1".equals(Build.MODEL)) { screenshotCap("after_enter"); UiObject2 dataUsageObj = device.findObject(By.text("流量使用情况")); dataUsageObj.clickAndWait(Until.newWindow(), LONG_WAIT); UiObject2 gernalObj = device.findObject(By.selected(true).text("概览")); Assert.assertNotNull("未找到概览tab", gernalObj); UiObject2 wlanObj = device.findObject(By.text("WLAN").res("android:id/title")); Assert.assertNotNull("未找到WLANtab", wlanObj); } }
private void clickUiobjectByRes(String res) { UiObject2 r = mDevice.wait(Until.findObject(By.res(res)), timeout); if (r != null) { r.click(); return; } Log.i(logTag, "Cannot find UiObject2 by res " + res); }
@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); } }
@Test public void test_wait_debounce() { onView(ViewMatchers.withId(R.id.button_debounce)).perform(click()); // In this case, CountingIdlingResource has no effect. // Use UiDevice.wait() of UIAutomator instead. uiDevice.wait(Until.hasObject(By.text("Debounce Completed")), 5000L); onView(withId(R.id.text_debounce_result)) .check(matches(withText("Debounce Completed"))); }
@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 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()); } }