本文整理汇总了Java中android.support.test.uiautomator.UiScrollable.getChildByText方法的典型用法代码示例。如果您正苦于以下问题:Java UiScrollable.getChildByText方法的具体用法?Java UiScrollable.getChildByText怎么用?Java UiScrollable.getChildByText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.test.uiautomator.UiScrollable
的用法示例。
在下文中一共展示了UiScrollable.getChildByText方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testB
import android.support.test.uiautomator.UiScrollable; //导入方法依赖的package包/类
/**
* 滑动界面,打开About phone选项
* 测试环境为标准Android 7.1.1版本,不同设备控件查找方式会有不同
*
* @throws UiObjectNotFoundException
*/
public void testB() throws UiObjectNotFoundException {
// 获取设备对象
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
UiDevice uiDevice = UiDevice.getInstance(instrumentation);
// 获取上下文
Context context = instrumentation.getContext();
// 点击Settings按钮
UiObject uiObject = uiDevice.findObject(new UiSelector().description("Settings"));
uiObject.click();
// 滑动列表到最后,点击About phone选项
UiScrollable settings = new UiScrollable(new UiSelector().className("android.support.v7.widget.RecyclerView"));
UiObject about = settings.getChildByText(new UiSelector().className("android.widget.LinearLayout"), "About phone");
about.click();
// 点击设备返回按钮
uiDevice.pressBack();
uiDevice.pressBack();
}
示例2: clickListViewItem
import android.support.test.uiautomator.UiScrollable; //导入方法依赖的package包/类
public static boolean clickListViewItem(String name) {
UiScrollable listView = new UiScrollable(new UiSelector());
listView.setMaxSearchSwipes(4);
listView.waitForExists(3000);
UiObject listViewItem;
try {
if (listView.scrollTextIntoView(name)) {
listViewItem = listView.getChildByText(new UiSelector()
.className(TextView.class.getName()), "" + name + "");
listViewItem.click();
} else {
return false;
}
} catch (UiObjectNotFoundException e) {
return false;
}
return true;
}
示例3: selectSettingsFor
import android.support.test.uiautomator.UiScrollable; //导入方法依赖的package包/类
private boolean selectSettingsFor(String name) {
try {
UiScrollable appsSettingsList = new UiScrollable(SettingsHelper.SCROLL_VIEW);
UiObject obj = appsSettingsList.getChildByText(SettingsHelper.LIST_VIEW_ITEM, name);
obj.click();
} catch (UiObjectNotFoundException e) {
return false;
}
return true;
}
示例4: testCalculator
import android.support.test.uiautomator.UiScrollable; //导入方法依赖的package包/类
public void testCalculator() throws Exception {
uiDevice.findObject(new UiSelector().descriptionContains("Apps")).clickAndWaitForNewWindow();
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
appViews.setAsHorizontalList();
UiObject calculatorApp = appViews.getChildByText(new UiSelector()
.className(android.widget.TextView.class.getName()), "Calculator");
calculatorApp.clickAndWaitForNewWindow();
// Calculator app
UiObject threeButton = uiDevice.findObject(new UiSelector().text("3"));
threeButton.click();
UiObject plusButton = uiDevice.findObject(new UiSelector().text("+"));
plusButton.click();
UiObject fiveButton = uiDevice.findObject(new UiSelector().text("5"));
fiveButton.click();
UiObject equalsButton = uiDevice.findObject(new UiSelector().text("="));
equalsButton.click();
UiObject display = uiDevice.findObject(new UiSelector()
.resourceId("com.android.calculator2:id/display"));
UiObject displayNumber = display.getChild(new UiSelector().index(0));
assertEquals(displayNumber.getText(), "8");
uiDevice.pressHome();
}
示例5: testBrowserApp
import android.support.test.uiautomator.UiScrollable; //导入方法依赖的package包/类
public void testBrowserApp() throws Exception {
uiDevice.findObject(new UiSelector().descriptionContains("Apps")).clickAndWaitForNewWindow();
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
appViews.setAsHorizontalList();
UiObject browserApp = appViews.getChildByText(new UiSelector()
.className(android.widget.TextView.class.getName()), "Browser");
browserApp.clickAndWaitForNewWindow();
// Browser App set url
UiObject urlForm = uiDevice.findObject(new UiSelector()
.resourceId("com.android.browser:id/url"));
urlForm.setText("http://www.google.cz");
//uiDevice.pressKeyCode(KeyEvent.KEYCODE_ENTER);
uiDevice.pressEnter();
// Wait to load page
SystemClock.sleep(10000);
// Click on webview to lose focus from form
UiObject webView = uiDevice.findObject(new UiSelector()
.className("android.webkit.WebView"));
webView.click();
uiDevice.pressMenu();
// Sleep to show the menu
SystemClock.sleep(1000);
UiObject refreshButton = uiDevice.findObject(new UiSelector()
.text("Refresh"));
refreshButton.click();
}
示例6: mainActivity_changeLanguageToEnglish
import android.support.test.uiautomator.UiScrollable; //导入方法依赖的package包/类
@Test
public void mainActivity_changeLanguageToEnglish() throws Exception {
UiScrollable recycleView = new UiScrollable(new UiSelector().resourceId("com.fantasyfang.googletrendapp:id/trendRecycleView")
.className(RecyclerView.class));//recycleView.click();
UiObject item = recycleView.getChild(new UiSelector().resourceId("com.fantasyfang.googletrendapp:id/googleTrendView"));
item.click();
item.click();
mDevice.waitForIdle();
takeScreenShot("Country_chinese.jpg");
mDevice.pressHome();
// Validate that the package name is the expected one
Context context = InstrumentationRegistry.getContext();
final Intent intent = context.getPackageManager().getLaunchIntentForPackage(SETTING_PACKAGE);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); // Clear out any previous instances
context.startActivity(intent);
mDevice.wait(Until.hasObject(By.pkg(SETTING_PACKAGE).depth(0)), LAUNCH_TIMEOUT);
if(selectSettingsFor("語言與輸入設定")){
UiObject language = mDevice.findObject(new UiSelector().text("語言"));
language.click();
takeScreenShot("language_setting.jpg");
//Click english language item
UiScrollable languageFrame = new UiScrollable(SettingsHelper.FRAMELAYOUT_VIEW);
UiObject englishLanguageItem = languageFrame.getChildByText(SettingsHelper.LIST_VIEW_ITEM, "English (United States)");
englishLanguageItem.click();
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
final Intent intentAPP = context.getPackageManager().getLaunchIntentForPackage(BASIC_PACKAGE);
intentAPP.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); // Clear out any previous instances
context.startActivity(intentAPP);
// Wait for the app to appear
mDevice.wait(Until.hasObject(By.pkg(BASIC_PACKAGE).depth(0)), LAUNCH_TIMEOUT);
// UiScrollable recycleView = new UiScrollable(new UiSelector().resourceId("com.fantasyfang.googletrendapp:id/trendRecycleView")
// .className(RecyclerView.class));//recycleView.click();
// UiObject item = recycleView.getChild(new UiSelector().resourceId("com.fantasyfang.googletrendapp:id/googleTrendView"));
item.click();
item.click();
mDevice.waitForIdle();
takeScreenShot("Country_english.jpg");
}
}
示例7: testCalculator
import android.support.test.uiautomator.UiScrollable; //导入方法依赖的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");
}
示例8: testBrowserApp
import android.support.test.uiautomator.UiScrollable; //导入方法依赖的package包/类
@Test
public void testBrowserApp() 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 browser application
UiObject browserApp = appViews.getChildByText(new UiSelector()
.className("android.widget.TextView"), "Browser");
assertTrue(browserApp.exists());
browserApp.clickAndWaitForNewWindow();
// Browser App set url
UiObject urlForm = uiDevice.findObject(new UiSelector()
.resourceId("com.android.browser:id/url"));
assertTrue(urlForm.exists());
urlForm.click();
urlForm.setText("www.google.com");
uiDevice.pressEnter();
// Wait to load page
SystemClock.sleep(10000);
// Show menu
uiDevice.pressMenu();
// Find text on page
UiObject findButton = uiDevice.findObject(new UiSelector()
.text("Find on page"));
assertTrue(findButton.exists());
findButton.click();
UiObject findView = uiDevice.findObject(new UiSelector()
.resourceId("android:id/edit"));
assertTrue(findView.exists());
findView.click();
findView.setText("Google");
uiDevice.pressEnter();
SystemClock.sleep(2000);
// Dismiss search
UiObject okButtonView = uiDevice.findObject(new UiSelector()
.resourceId("com.android.browser:id/iconcombo"));
assertTrue(okButtonView.exists());
okButtonView.click();
}
示例9: checkSettings
import android.support.test.uiautomator.UiScrollable; //导入方法依赖的package包/类
@Test
public void checkSettings() throws UiObjectNotFoundException {
// Simulate a short press on the HOME button.
mDevice.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"));
assertThat(settingsValidation.exists(), equalTo(true));
}