本文整理匯總了Java中android.support.test.uiautomator.UiObject.getChild方法的典型用法代碼示例。如果您正苦於以下問題:Java UiObject.getChild方法的具體用法?Java UiObject.getChild怎麽用?Java UiObject.getChild使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.test.uiautomator.UiObject
的用法示例。
在下文中一共展示了UiObject.getChild方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test009SearchByTitle
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@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());
}
示例2: test009SearchByTitle
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@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());
}
示例3: getChild
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
public Object getChild(final Object selector) throws UiObjectNotFoundException, InvalidSelectorException, ClassNotFoundException {
if (selector instanceof UiSelector) {
/**
* We can't find the child element with UiSelector on UiObject2,
* as an alternative creating UiObject with UiObject2's AccessibilityNodeInfo
* and finding the child element on UiObject.
*/
AccessibilityNodeInfo nodeInfo = AccessibilityNodeInfoGetter.fromUiObject(element);
UiSelector uiSelector = new UiSelector();
CustomUiSelector customUiSelector = new CustomUiSelector(uiSelector);
uiSelector = customUiSelector.getUiSelector(nodeInfo);
UiObject uiObject = (UiObject) CustomUiDevice.getInstance().findObject(uiSelector);
AccessibilityNodeInfo uiObject_nodeInfo = AccessibilityNodeInfoGetter.fromUiObject(element);
return uiObject.getChild((UiSelector) selector);
}
return element.findObject((BySelector) selector);
}
示例4: test027CheckSearchHistory
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Category(CategoryAppStoreTests_v3_3_15.class)
@Test
public void test027CheckSearchHistory() throws UiObjectNotFoundException {
TestUtils.screenshotCap("appStoreHome");
UiObject2 hotOne = device.findObject(By.res("woyou.market:id/linear_hot_view")).findObject(By.res("woyou.market:id/tv_name"));
String targetAppName = hotOne.getText();
UiObject2 searchObj = device.findObject(By.res("woyou.market:id/tv_search").text("搜索"));
searchObj.click();
TestUtils.screenshotCap("afterClickSearchBtn");
TestUtils.sleep(SHORT_SLEEP);
UiObject2 searchObj1 = device.findObject(By.res("woyou.market:id/et_search").text("搜索").focused(true));
searchObj1.click();
searchObj1.setText(targetAppName);
TestUtils.screenshotCap("enterSearchContent");
UiScrollable appList = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
UiObject appInfo = appList.getChildByInstance(new UiSelector().className("android.widget.FrameLayout"),0);
UiObject appNameObj = appInfo.getChild(new UiSelector().resourceId("woyou.market:id/tv_name"));
String appName = appNameObj.getText();
appInfo.click();
TestUtils.screenshotCap("enterTheFirstSearchResult");
device.pressBack();
TestUtils.sleep(SHORT_SLEEP);
UiObject2 clearButton = device.findObject(By.res("woyou.market:id/iv_delete"));
clearButton.click();
TestUtils.screenshotCap("clearSearchBar");
TestUtils.sleep(SHORT_SLEEP);
String historyObjName = device.findObject(By.res("woyou.market:id/history_key")).findObject(By.clazz("android.widget.TextView")).getText();
Assert.assertEquals("期望的名字是"+appName+",而實際是"+historyObjName,appName,historyObjName);
}
示例5: test027CheckSearchHistory
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void test027CheckSearchHistory() throws UiObjectNotFoundException {
TestUtils.screenshotCap("appStoreHome");
UiObject2 hotOne = device.findObject(By.res("woyou.market:id/linear_hot_view")).findObject(By.res("woyou.market:id/tv_name"));
String targetAppName = hotOne.getText();
UiObject2 searchObj = device.findObject(By.res("woyou.market:id/tv_search").text("搜索"));
searchObj.click();
TestUtils.screenshotCap("afterClickSearchBtn");
TestUtils.sleep(SHORT_SLEEP);
UiObject2 searchObj1 = device.findObject(By.res("woyou.market:id/et_search").text("搜索").focused(true));
searchObj1.click();
searchObj1.setText(targetAppName);
TestUtils.screenshotCap("enterSearchContent");
UiScrollable appList = new UiScrollable(new UiSelector().resourceId("woyou.market:id/list_view"));
UiObject appInfo = appList.getChildByInstance(new UiSelector().resourceId("woyou.market:id/app_view"),0);
UiObject appNameObj = appInfo.getChild(new UiSelector().resourceId("woyou.market:id/tv_name"));
String appName = appNameObj.getText();
appInfo.click();
TestUtils.screenshotCap("enterTheFirstSearchResult");
device.pressBack();
TestUtils.sleep(SHORT_SLEEP);
UiObject2 clearButton = device.findObject(By.res("woyou.market:id/iv_delete"));
clearButton.click();
TestUtils.screenshotCap("clearSearchBar");
TestUtils.sleep(SHORT_SLEEP);
String historyObjName = device.findObject(By.res("woyou.market:id/history_key")).findObject(By.clazz("android.widget.TextView")).getText();
Assert.assertEquals("期望的名字是"+appName+",而實際是"+historyObjName,appName,historyObjName);
}
示例6: checkNotificationDisplayed
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
/**
* Check if the model download notifications displayed?
*
* @see <a href="https://stackoverflow.com/a/33515200/4690731">https://stackoverflow.com/a/33515200/4690731</a>
*/
@Test
public void checkNotificationDisplayed() throws UiObjectNotFoundException {
//Fire the notification
ModelDownloadingNotification.notify(InstrumentationRegistry.getTargetContext(),
0, true);
/*
* access Notification Center through resource id, package name, class name.
* if you want to check resource id, package name or class name of the specific view
* in the screen, run 'uiautomatorviewer' from command.
*/
UiSelector notificationStackScroller = new UiSelector()
.packageName("com.android.systemui")
.className("android.view.ViewGroup")
.resourceId("com.android.systemui:id/notification_stack_scroller");
UiObject notificationStackScrollerUiObject = mDevice.findObject(notificationStackScroller);
assertTrue(notificationStackScrollerUiObject.exists());
/*
* access top notification in the center through parent
*/
UiObject notiSelectorUiObject = notificationStackScrollerUiObject.getChild(new UiSelector()
.text(InstrumentationRegistry
.getTargetContext()
.getString(R.string.model_downloading_notification_title)));
assertTrue(notiSelectorUiObject.exists());
}
示例7: checkIfNotificationCanceled
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
/**
* Check if we can cancel the cancel the notification? For that we will first create the notification
* using {@link #checkNotificationDisplayed()}. Than we will cancel the notification.
*
* @see <a href="https://stackoverflow.com/a/33515200/4690731">https://stackoverflow.com/a/33515200/4690731</a>
*/
@Test
public void checkIfNotificationCanceled() throws UiObjectNotFoundException {
//Fire the notification
ModelDownloadingNotification.notify(InstrumentationRegistry.getTargetContext(),
0, true);
/*
* access Notification Center through resource id, package name, class name.
* if you want to check resource id, package name or class name of the specific view
* in the screen, run 'uiautomatorviewer' from command.
*/
UiSelector notificationStackScroller = new UiSelector()
.packageName("com.android.systemui")
.className("android.view.ViewGroup")
.resourceId("com.android.systemui:id/notification_stack_scroller");
UiObject notificationStackScrollerUiObject = mDevice.findObject(notificationStackScroller);
assertTrue(notificationStackScrollerUiObject.exists());
/*
* access top notification in the center through parent
*/
UiObject notiSelectorUiObject = notificationStackScrollerUiObject.getChild(new UiSelector()
.text(InstrumentationRegistry
.getTargetContext()
.getString(R.string.model_downloading_notification_title)));
assertTrue(notiSelectorUiObject.exists());
//Now lets cancel the notification
ModelDownloadingNotification.cancel(InstrumentationRegistry.getTargetContext());
mDevice.openNotification();
mDevice.wait(Until.hasObject(By.pkg("com.android.systemui")), 10000);
notiSelectorUiObject = notificationStackScrollerUiObject.getChild(new UiSelector()
.text(InstrumentationRegistry
.getTargetContext()
.getString(R.string.model_downloading_notification_title)));
assertFalse(notiSelectorUiObject.exists());
}
示例8: testCalculator
import android.support.test.uiautomator.UiObject; //導入方法依賴的package包/類
@Test
public void testCalculator() throws Exception {
// Home screen apps button
UiObject appButton = uiDevice.findObject(new UiSelector().descriptionContains("Apps"));
assertTrue(appButton.exists());
appButton.clickAndWaitForNewWindow();
// Scrollable view with apps
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
assertTrue(appViews.exists());
appViews.setAsHorizontalList();
// Find calculator application
UiObject calculatorApp = appViews.getChildByText(new UiSelector()
.className("android.widget.TextView"), "Calculator");
assertTrue(calculatorApp.exists());
calculatorApp.clickAndWaitForNewWindow();
// Use calculator app
UiObject clearButton = uiDevice.findObject(new UiSelector().textMatches("clr|del"));
assertTrue(clearButton.exists());
clearButton.longClick();
UiObject threeButton = uiDevice.findObject(new UiSelector().text("3"));
assertTrue(threeButton.exists());
threeButton.click();
UiObject plusButton = uiDevice.findObject(new UiSelector().text("+"));
assertTrue(plusButton.exists());
plusButton.click();
UiObject fiveButton = uiDevice.findObject(new UiSelector().text("5"));
assertTrue(fiveButton.exists());
fiveButton.click();
UiObject equalsButton = uiDevice.findObject(new UiSelector().text("="));
assertTrue(equalsButton.exists());
equalsButton.click();
UiObject display = uiDevice.findObject(new UiSelector()
.resourceId("com.android.calculator2:id/display"));
assertTrue(display.exists());
// Validate
UiObject displayNumber = display.getChild(new UiSelector().index(0));
assertTrue(displayNumber.exists());
assertEquals(displayNumber.getText(), "8");
}