/** * 点击搜索框后,输入搜索关键词进行搜索 * * @throws UiObjectNotFoundException */ public void setSearchWord() throws UiObjectNotFoundException { // 点击搜索框 UiObject textV = new UiObject(new UiSelector().resourceId("com.mappn.gfan:id/tv_search")); textV.click(); // 判断搜索框是否存在-输入QQ搜索 UiObject textVChild = new UiObject(new UiSelector().resourceId("com.mappn.gfan:id/top_search_container")); Assert.assertEquals(true, textVChild.exists()); textVChild.setText("QQ"); sleep(1000); // 获取搜索关键字列表 UiObject listViewOb = new UiObject(new UiSelector().resourceId("com.mappn.gfan:id/baselistview")); // Assert.assertEquals(0, listViewOb.getChildCount()); // 点击列表第一个搜索关键字 UiObject childOb = listViewOb.getChild(new UiSelector().index(6)); // childOb.click(); Assert.assertEquals(true, childOb.exists()); if (childOb.exists()) { childOb.clickAndWaitForNewWindow(); } else { UiObject selectButton = new UiObject(new UiSelector().resourceId("com.mappn.gfan:id/top_search_container")); selectButton.clickAndWaitForNewWindow(); } }
/** * Helper function to set an alarm * * @param minutesFromNow * @throws UiObjectNotFoundException */ public void setAlarm(int minutesFromNow) throws UiObjectNotFoundException { UiObject setAlarm = new UiObject(new UiSelector().description("Alarms")); if (!setAlarm.exists()) setAlarm = new UiObject(new UiSelector().textStartsWith("Set alarm")); setAlarm.click(); UtilityFunctions uti = Controller.utilities; // let's add an alarm uti.clickByDescription("Add alarm"); // let's set the time // clickByText("Time"); Calendar c = Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat("HHmm"); c.add(Calendar.MINUTE, 1); String now = format.format(c.getTime()); Log.i("ROOT", "alarm time: " + now); new UiObject( new UiSelector() .packageName(packageName) .className("android.widget.Button") .text("" + now.charAt(0))) .click(); new UiObject( new UiSelector() .packageName(packageName) .className("android.widget.Button") .text("" + now.charAt(1))) .click(); new UiObject( new UiSelector() .packageName(packageName) .className("android.widget.Button") .text("" + now.charAt(2))) .click(); new UiObject( new UiSelector() .packageName(packageName) .className("android.widget.Button") .text("" + now.charAt(3))) .click(); // clickByText("Ok"); // few confirmations to click thru UiObject doneButton = new UiObject(new UiSelector().text("Done")); UiObject okButton = new UiObject(new UiSelector().text("OK")); // working around some inconsistencies in phone vs tablet UI if (doneButton.exists()) { doneButton.click(); } else { okButton.click(); // let it fail if neither exists } // we're done. Let's return to home screen // clickByText("Done"); uti.goToHomeScreen(); }
public void testAddToBookmarksVideo() throws UiObjectNotFoundException { findAndRunApp(); searchVideo(videoSearchString); addBookmark(videoSearchString); UiObject searchResult = new UiObject(new UiSelector().textContains(videoSearchString)); assertTrue(videoSearchString, searchResult.exists()); }
public boolean getBoolAttribute(final String attr) throws UiObjectNotFoundException, NoAttributeFoundException { boolean res = false; if (attr.equals("enabled")) { res = el.isEnabled(); } else if (attr.equals("checkable")) { res = el.isCheckable(); } else if (attr.equals("checked")) { res = el.isChecked(); } else if (attr.equals("clickable")) { res = el.isClickable(); } else if (attr.equals("focusable")) { res = el.isFocusable(); } else if (attr.equals("focused")) { res = el.isFocused(); } else if (attr.equals("longClickable")) { res = el.isLongClickable(); } else if (attr.equals("scrollable")) { res = el.isScrollable(); } else if (attr.equals("selected")) { res = el.isSelected(); } else if (attr.equals("displayed")) { res = el.exists(); } else { throw new NoAttributeFoundException(attr); } return res; }
public void testSearchVideo() throws UiObjectNotFoundException { findAndRunApp(); searchVideo(videoSearchString); getUiDevice().pressDPadDown(); // UiObject searchResult = new UiObject(new // UiSelector().className("android.widget.CheckedTextView").resourceId("com.ted.android:id/title")); UiObject searchResult = new UiObject( new UiSelector() .className("android.widget.CheckedTextView") .textContains(videoSearchString)); assertTrue(videoSearchString, searchResult.exists()); }
@Override public boolean checkForCondition() { UiObject message = new UiObject(new UiSelector().resourceId("android:id/message").textStartsWith("温馨提示")); if (message.exists()) { UiObject ok = new UiObject(new UiSelector().resourceId("android:id/button1")); try { ok.click(); } catch (UiObjectNotFoundException e) { e.printStackTrace(); } return true; } return super.checkForCondition(); }
public void testDemo() throws UiObjectNotFoundException { // Simulate a short press on the HOME button. getUiDevice().pressHome(); // We’re now in the home screen. Next, we want to simulate // a user bringing up the All Apps screen. // If you use the uiautomatorviewer tool to capture a snapshot // of the Home screen, notice that the All Apps button’s // content-description property has the value “Apps”. We can // use this property to create a UiSelector to find the button. UiObject allAppsButton = new UiObject(new UiSelector().description("Apps")); // Simulate a click to bring up the All Apps screen. allAppsButton.clickAndWaitForNewWindow(); // In the All Apps screen, the Settings app is located in // the Apps tab. To simulate the user bringing up the Apps tab, // we create a UiSelector to find a tab with the text // label “Apps”. UiObject appsTab = new UiObject(new UiSelector().text("Apps")); // Simulate a click to enter the Apps tab. appsTab.click(); // Next, in the apps tabs, we can simulate a user swiping until // they come to the Settings app icon. Since the container view // is scrollable, we can use a UiScrollable object. UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true)); // Set the swiping mode to horizontal (the default is vertical) appViews.setAsHorizontalList(); // Create a UiSelector to find the Settings app and simulate // a user click to launch the app. UiObject settingsApp = appViews.getChildByText( new UiSelector().className(android.widget.TextView.class.getName()), "Settings"); settingsApp.clickAndWaitForNewWindow(); // Validate that the package name is the expected one UiObject settingsValidation = new UiObject(new UiSelector().packageName("com.android.settings")); assertTrue("Unable to detect Settings", settingsValidation.exists()); }
public boolean isDialogPresent() { UiObject alertDialog = new UiObject(new UiSelector().packageName("com.android.systemui")); return alertDialog.exists(); }
public void testcase() throws IOException { try { Common.startLog(runcase, "*****Start to run " + runcase + " *****"); // 通过是否有IPC按钮判断是否进入 Common.openActivity(runcase, in, "cn.com.mobnote.golukmobile:id/index_carrecoder_btn"); sleep(2000); // 选择 IPC按钮 从下边状态栏 Common.clickViewById(runcase, in, "cn.com.mobnote.golukmobile:id/index_carrecoder_btn"); sleep(2000); // 检查是否连接到IPC Common.connectWifi(runcase, in, "cn.com.mobnote.golukmobile:id/mConnectTip"); sleep(2000); Common.clickViewById(runcase, in, "cn.com.mobnote.golukmobile:id/mPlayBtn"); sleep(2000); int i = 1; UiObject waitingnote = Common.findViewById2(in, "cn.com.mobnote.golukmobile:id/mLoading"); while (i < 60) { if (waitingnote.exists()) { sleep(1000); Common.infoLog(runcase, "Loading Preview" + i + "sec"); i++; } else { Common.infoLog(runcase, "Loading Finish"); sleep(3000); break; } } if (i == 60) { throw new Exception("Loading more than 60s"); } sleep(2000); Common.clickViewById(runcase, in, "cn.com.mobnote.golukmobile:id/m8sBtn"); sleep(7000); int waitforshare = 1; UiObject shareBtn = null; while (waitforshare < 30) { shareBtn = Common.findViewById2(in, "cn.com.mobnote.golukmobile:id/new1"); if (shareBtn.exists()) { Common.infoLog(runcase, "精彩视频拍摄保存成功"); sleep(2000); Common.clickViewById(runcase, in, "cn.com.mobnote.golukmobile:id/image1"); UiObject btn = Common.findViewById2(in, "cn.com.mobnote.golukmobile:id/back_btn"); if (btn.exists()) { btn.click(); } break; } sleep(5000); waitforshare++; } if (waitforshare == 30) { throw new Exception("精彩视频拍摄保存失败"); } Common.backToHome(runcase, in); Common.passcase(runcase); Common.startLog(runcase, "*****End to run " + runcase + " *****"); } catch (Exception e) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); Date curDate = new Date(System.currentTimeMillis()); String str = formatter.format(curDate); String s = Common.checkFailReason2(runcase, in, str, e.getMessage()); Common.infoLog(runcase, "截图存储在 in /sdcard/GolukTest/" + runcase + "/" + str + ".png"); Common.takeScreen(in, runcase, str); // String s=null; // s=Common.checkFailReason(runcase,in, e.getMessage()); Common.backToHome(runcase, in); Common.errorLog(runcase, s); Common.failcase(runcase); Common.startLog(runcase, "*****End to run " + runcase + " *****"); } }
public void testDemo() throws UiObjectNotFoundException, InterruptedException { // Simulate a short press on the HOME button. getUiDevice().pressHome(); // We’re now in the home screen. Next, we want to simulate // a user bringing up the All Apps screen. // If you use the uiautomatorviewer tool to capture a snapshot // of the Home screen, notice that the All Apps button’s // content-description property has the value “Apps”. We can // use this property to create a UiSelector to find the button. UiObject allAppsButton = new UiObject(new UiSelector().description("Apps")); // Simulate a click to bring up the All Apps screen. allAppsButton.clickAndWaitForNewWindow(); Thread.sleep(2000); // In the All Apps screen, the Settings app is located in // the Apps tab. To simulate the user bringing up the Apps tab, // we create a UiSelector to find a tab with the text // label “Apps”. UiObject appsTab = new UiObject(new UiSelector().text("Apps")); // Simulate a click to enter the Apps tab. appsTab.click(); // SystemClock.sleep(2000); // Next, in the apps tabs, we can simulate a user swiping until // they come to the Settings app icon. Since the container view // is scrollable, we can use a UiScrollable object. UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true)); // Set the swiping mode to horizontal (the default is vertical) appViews.setAsHorizontalList(); // Create a UiSelector to find the Netflix app and simulate // a user click to launch the app. UiObject netflixApp = appViews.getChildByText( new UiSelector().className(android.widget.TextView.class.getName()), "Netflix"); netflixApp.clickAndWaitForNewWindow(); SystemClock.sleep(3000); // create a virtual hand to click UiDevice handClick = UiDevice.getInstance(); // click the menu and "Comedies" handClick.click(20, 95); SystemClock.sleep(1500); handClick.click(300, 650); // enter the first movie in this page SystemClock.sleep(1000); handClick.click(150, 450); SystemClock.sleep(3000); for (int i = 0; i < 2; i++) { // the loop of we want to play // print out which loop now int counti = i + 1; System.out.println("the number of the loop is " + counti); // start play the movie handClick.click(400, 350); System.out.println("start play the movie 1 " + counti); SystemClock.sleep(10000); System.out.println("start play the movie 2 " + counti); // do some operation handClick.click(500, 500); SystemClock.sleep(20000); handClick.click(500, 500); SystemClock.sleep(1000); for (int j = 0; j < 10; j++) { int countj = j + 1; handClick.click(150, 675); // 10 sec seek, 10 times SystemClock.sleep(2000); System.out.println("sec seek " + countj); } handClick.click(750, 685); // normal seek SystemClock.sleep(2000); System.out.println("normal seek 1 " + counti); handClick.click(450, 685); // normal seek SystemClock.sleep(2000); System.out.println("normal seek 2 " + counti); handClick.click(590, 685); // normal seek SystemClock.sleep(2000); System.out.println("normal seek 3 " + counti); SystemClock.sleep(7000); // let is play 5000 ms System.out.println("playing" + counti); // back handClick.click(500, 500); SystemClock.sleep(100); getUiDevice().pressBack(); SystemClock.sleep(150); // add the movie in MyList handClick.click(550, 730); SystemClock.sleep(1000); // drag the menu and enter the next movie handClick.drag(16, 1025, 16, 185, 80); SystemClock.sleep(200); handClick.click(350, 1050); } // back and over // getUiDevice().pressHome(); handClick.click(20, 95); SystemClock.sleep(200); getUiDevice().pressBack(); System.out.println("The test is over"); // Validate that the package name is the expected one UiObject settingsValidation = new UiObject(new UiSelector().packageName("com.netflix.mediaclient")); assertTrue("Unable to detect Settings", settingsValidation.exists()); }