com.android.uiautomator.core.UiSelector Java Examples

The following examples show how to use com.android.uiautomator.core.UiSelector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UiAutomatorInputTest.java    From uiautomator-unicode-input-helper with Apache License 2.0 7 votes vote down vote up
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で入力しています。"));
    }
 
Example #2
Source File: AbstractChildCountAction.java    From honeydew with MIT License 5 votes vote down vote up
@Override
public final Result execute(Map<String, Object> arguments) throws UiObjectNotFoundException {
    Log.d(TAG, "Entering " + TAG);
    String parentDescription = (String) arguments.get("parent_description");
    String childDescription = (String) arguments.get("child_description");
    int expectedCount = ((Double) arguments.get("child_count")).intValue();

    UiCollection parentElement = new UiCollection(new UiSelector().description(parentDescription));
    int actualCount = parentElement.getChildCount(new UiSelector().description(childDescription));
    Log.d(TAG, "Actual count was: " + actualCount + " when " + expectedCount + " was expected");
    return new Result(isTrue(expectedCount, actualCount), "Actual count was: " + actualCount + " when " + expectedCount + " was expected");

}
 
Example #3
Source File: LaunchApp.java    From PUMA with Apache License 2.0 4 votes vote down vote up
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
	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);
}
 
Example #4
Source File: LaunchSettings.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
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());
	}
 
Example #5
Source File: LaunchSettings.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
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());
	}