本文整理汇总了Java中com.android.uiautomator.core.UiObject.clickAndWaitForNewWindow方法的典型用法代码示例。如果您正苦于以下问题:Java UiObject.clickAndWaitForNewWindow方法的具体用法?Java UiObject.clickAndWaitForNewWindow怎么用?Java UiObject.clickAndWaitForNewWindow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.uiautomator.core.UiObject
的用法示例。
在下文中一共展示了UiObject.clickAndWaitForNewWindow方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDemo
import com.android.uiautomator.core.UiObject; //导入方法依赖的package包/类
public void testDemo() throws UiObjectNotFoundException {
// Press on the HOME button.
getUiDevice().pressHome();
// Launch the "Google" apps via the All Apps screen.
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
allAppsButton.clickAndWaitForNewWindow();
UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
appsTab.click();
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
appViews.setAsHorizontalList();
UiObject testApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()),
"Google");
testApp.clickAndWaitForNewWindow();
// Get the google search text box
UiObject searchBox = new UiObject(
new UiSelector().className("com.google.android.search.shared.ui.SimpleSearchText"));
// do Japanese Input!
searchBox.setText(Utf7ImeHelper.e("こんにちは!UiAutomatorで入力しています。"));
}
示例2: openThumbGrid
import com.android.uiautomator.core.UiObject; //导入方法依赖的package包/类
/**
* Launches the app, opens the navigation drawer and click the home item to
* load the thumb grid
*
* @throws RemoteException
* @throws UiObjectNotFoundException
*/
private void openThumbGrid() throws RemoteException,
UiObjectNotFoundException {
startTSAP();
UiObject navDrawer = new UiObject(
new UiSelector().description("navigation_drawer"));
if (!navDrawer.exists()) {
UiObject upButton = new UiObject(
new UiSelector().descriptionContains("navigation drawer"));
upButton.clickAndWaitForNewWindow(1000);
}
UiObject homeItem = navDrawer.getChild(new UiSelector().text("Home"));
homeItem.click();
}
示例3: testDemo
import com.android.uiautomator.core.UiObject; //导入方法依赖的package包/类
public void testDemo() throws UiObjectNotFoundException, InterruptedException {
Log.i("vicky", "here");
// 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("Kik"));
// Simulate a click to enter the Apps tab.
appsTab.clickAndWaitForNewWindow();
while(true) {
if (hasConversation()) {
chat();
} else {
Thread.sleep(10000);
}
}
}
示例4: chat
import com.android.uiautomator.core.UiObject; //导入方法依赖的package包/类
protected void chat() throws UiObjectNotFoundException {
// Select First conversation
UiSelector firstEl = new UiSelector()
.className("android.widget.ListView").index(3)
.childSelector(new UiSelector().index(0));
UiObject conversation = new UiObject(firstEl);
conversation.clickAndWaitForNewWindow();
// Reads Text
UiObject text = new UiObject(find("ListView-2.LinearLayout-2.TextView-0").instance(0));
String response;
if (text.exists()) {
String userInput = text.getText();
// Get response from the server
response = getResponseFor(userInput.toString());
} else {
response = "What?";
}
// Write response back
UiObject textBox = new UiObject(find("EditText-0"));
UiObject submitButton = new UiObject(find("LinearLayout-5.ImageView-3"));
textBox.setText(response);
submitButton.click();
// Delete conversation
UiObject conversarionManager = new UiObject(new UiSelector().className(
"android.widget.ImageView").instance(2));
conversarionManager.clickAndWaitForNewWindow();
UiObject closeButton = new UiObject(find("TextView-3"));
closeButton.clickAndWaitForNewWindow();
UiObject confirmCloseButton = new UiObject(find("Button-1"));
confirmCloseButton.click();
}
示例5: start_target_app
import com.android.uiautomator.core.UiObject; //导入方法依赖的package包/类
private void start_target_app(String appName) throws UiObjectNotFoundException {
// 0. Start fromIndex HOME
dev.pressHome();
// 1. Find and click "Apps" button
//NO Need to use that
// UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
//
// allAppsButton.clickAndWaitForNewWindow();
// 2. Find and click “Apps” tab
UiObject appsTab = new UiObject(new UiSelector().description("Apps"));
if (launcherPackName == null) {
launcherPackName = appsTab.getPackageName(); // remember the launcher package
}
appsTab.click();
// 3. Select scrollable "container view"
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
// Set the swiping mode to horizontal (the default is vertical)
appViews.setAsHorizontalList();
// 4. This API does not work properly in 4.2.2
appViews.scrollTextIntoView(appName);
// 5. Click target app
UiObject targetApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), appName, true);
boolean done = targetApp.clickAndWaitForNewWindow();
waitForNetworkUpdate();
// AccessibilityEventProcessor.waitForLastEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED, WINDOW_CONTENT_UPDATE_TIMEOUT);
}
示例6: testDemo
import com.android.uiautomator.core.UiObject; //导入方法依赖的package包/类
public void testDemo() throws UiObjectNotFoundException {
// Good practice to start from a common place
getUiDevice().pressHome();
// When we use the uiautomatorviewer in the DSK/tools we find that this
// button has the following content-description
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
// ** NOTE **
// Any operation on a UiObject that is not currently present on the display
// will result in a UiObjectNotFoundException to be thrown. If we want to
// first check if the object exists we can use allAppsButton.exists() which
// return boolean.
// ** NOTE **
//The operation below expects the click will result a new window.
allAppsButton.clickAndWaitForNewWindow();
// On the this view, we expect two tabs, one for APPS and another for
// WIDGETS. We will want to click the APPS just so we're sure apps and
// not widgets is our current display
UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
// ** NOTE **
// The above operation assumes that there is only one text "Apps" in the
// current view. If not, then the first "Apps" is selected. But if we
// want to be certain that we click on the tab "Apps", we can use the
// uiautomatorview from the SDK/tools and see if we can further narrow the
// selector. Comment the line above and uncomment the one bellow to use
// the more specific selector.
// ** NOTE **
// This creates a selector hierarchy where the first selector is for the
// TabWidget and the second will search only inside the layout of TabWidget
// To use this instead, uncomment the lines bellow and comment the above appsTab
//UiSelector appsTabSelector =
// new UiSelector().className(android.widget.TabWidget.class.getName())
// .childSelector(new UiSelector().text("Apps"));
//UiObject appsTab = new UiObject(appsTabSelector);
// The operation below we only cause a content change so a click() is good
appsTab.click();
// Since our device may have many apps on it spanning multiple views, we
// may need to scroll to find our app. Here we use UiScrollable to help.
// We declare the object with a selector to a scrollable view. Since in this
// case the firt scrollable view happens to be the one containing our apps
// list, we should be ok.
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
// swipe horizontally when searching (default is vertical)
appViews.setAsHorizontalList();
// the appsViews will perform horizontal scrolls to find the Settings app
UiObject settingsApp = appViews.getChildByText(
new UiSelector().className(android.widget.TextView.class.getName()), "Settings");
settingsApp.clickAndWaitForNewWindow();
// create a selector for anything on the display and check if the package name
// is the expected one
UiObject settingsValidation =
new UiObject(new UiSelector().packageName("com.android.settings"));
assertTrue("Unable to detect Settings", settingsValidation.exists());
}
示例7: testStartLocalServerUsingTestContent
import com.android.uiautomator.core.UiObject; //导入方法依赖的package包/类
/**
* Select start local server with test content in the settings menu.
* @throws Exception
*/
public void testStartLocalServerUsingTestContent()
throws Exception {
openYaacc();
getUiDevice().pressMenu(); // open option menu
UiScrollable settingsMenu = new UiScrollable(
new UiSelector().className("android.widget.ListView"));
UiObject settingsItem = settingsMenu.getChild(new UiSelector().className("android.widget.TextView")
.text("Settings"));
settingsItem.clickAndWaitForNewWindow();
UiObject validation = new UiObject(new UiSelector().text("Settings").className(
android.widget.TextView.class));
assertTrue("Unable to open Yaacc settings ", validation.exists());
UiScrollable settingsList = new UiScrollable(new UiSelector().className("android.widget.ListView").scrollable(true));
assertTrue("Unbale to find list view for settings ", settingsList.exists());
//Scroll to server settings
settingsList.getChildByText(new UiSelector().className(android.widget.TextView.class), "Local server configuration");
int itemCount = settingsList.getChildCount(new UiSelector().className(android.widget.LinearLayout.class));
assertTrue("itemCount > 0 (" + itemCount + ")", itemCount > 0);
for (int i = 0; i < itemCount; i++){
UiObject item = settingsList.getChildByInstance(new UiSelector().className(android.widget.LinearLayout.class), i);
UiObject textView = item.getChild(new UiSelector().textStartsWith("local server").className(
android.widget.TextView.class));
if(textView.exists()){
UiObject checkBox = item.getChild(new UiSelector().className(
android.widget.CheckBox.class));
assertTrue("CheckBox not found", checkBox.exists());
if(!checkBox.isChecked()){
checkBox.click();
}
}
}
//Back to BrowseActivity
getUiDevice().pressBack();
closeBrowseActivity();
}
示例8: openYaacc
import com.android.uiautomator.core.UiObject; //导入方法依赖的package包/类
private void openYaacc() throws Exception {
// Simulate a short press on the HOME button.
getUiDevice().pressHome();
// Were 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 buttons
// 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 Yaacc app and simulate
// a user click to launch the app.
UiObject yaaccApp = appViews.getChildByText(new UiSelector()
.className(android.widget.TextView.class.getName()), "YAACC");
yaaccApp.clickAndWaitForNewWindow();
}
示例9: start_target_app
import com.android.uiautomator.core.UiObject; //导入方法依赖的package包/类
private void start_target_app() throws UiObjectNotFoundException {
// 0. Start fromIndex HOME
dev.pressHome();
// 1. Find and click "Apps" button
// TODO: this is ad hoc fix for CM-10.2 nightly snapshot only
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
// int cnt = 0;
// boolean end = false;
// while (!end) {
// UiObject obj = new UiObject(new UiSelector().packageName("com.cyanogenmod.trebuchet").className("android.widget.TextView").instance(cnt));
// cnt++;
//
// try {
// obj.getBounds();
// } catch (UiObjectNotFoundException exception) {
// end = true;
// }
// }
// Util.log("HOME: " + (cnt - 1) + " TextViews");
//
// if ((cnt - 1) < 5) {
// Util.err("ERR: NOT_AT_HOME");
// System.exit(-1);
// }
//
// // Now there are (cnt-1) TextViews, "Apps" should be the (cnt-4)-th.
// UiObject allAppsButton = new UiObject(new UiSelector().packageName("com.cyanogenmod.trebuchet").className("android.widget.TextView").instance(cnt - 4));
allAppsButton.clickAndWaitForNewWindow();
// 2. Find and click “Apps” tab
if (android.os.Build.VERSION.SDK_INT < 21) {
//Add by Ruiyi He to avoid "Apps" cause in 5.0 this feature didnt exist
UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
launcherPackName = appsTab.getPackageName(); // remember the launcher package
appsTab.click();
}
// 3. Select scrollable "container view"
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
// Set the swiping mode to horizontal (the default is vertical)
appViews.setAsHorizontalList();
// 4. This API does not work properly in 4.2.2
appViews.scrollTextIntoView(appName);
// 5. Click target app
UiObject targetApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), appName, true);
boolean done = targetApp.clickAndWaitForNewWindow();
// Util.log("clickAndWaitForNewWindow: " + done);
waitForNetworkUpdate();
// AccessibilityEventProcessor.waitForLastEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED, WINDOW_CONTENT_UPDATE_TIMEOUT);
}
示例10: restartTSAP
import com.android.uiautomator.core.UiObject; //导入方法依赖的package包/类
/**
* Launches the Tribler Play app on the device
*
* @throws UiObjectNotFoundException
* @throws RemoteException
*/
private void restartTSAP() throws UiObjectNotFoundException,
RemoteException {
// 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 Tribler Play 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.clickAndWaitForNewWindow();
// Next, in the apps tabs, we can simulate a user swiping until
// they come to the Tribler Play 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 Tribler Play app and simulate
// a user click to launch the app.
UiObject tsapApp = appViews.getChildByText(
new UiSelector().className("android.widget.TextView"),
"Tribler Play", true);
tsapApp.clickAndWaitForNewWindow();
// Set the rotation to normal (=portrait mode)
getUiDevice().setOrientationNatural();
}
示例11: clickByDescription
import com.android.uiautomator.core.UiObject; //导入方法依赖的package包/类
/**
* Helper to click on objects that match the content-description text
* @param text
* @throws UiObjectNotFoundException
*/
private void clickByDescription(String text) throws UiObjectNotFoundException {
UiObject obj = new UiObject(new UiSelector().description(text));
obj.clickAndWaitForNewWindow();
}
示例12: clickByText
import com.android.uiautomator.core.UiObject; //导入方法依赖的package包/类
/**
* Helper to click on object that match the text value
* @param text
* @throws UiObjectNotFoundException
*/
private void clickByText(String text) throws UiObjectNotFoundException {
UiObject obj = new UiObject(new UiSelector().text(text));
obj.clickAndWaitForNewWindow();
}