当前位置: 首页>>代码示例>>Java>>正文


Java UiScrollable.setAsHorizontalList方法代码示例

本文整理汇总了Java中com.android.uiautomator.core.UiScrollable.setAsHorizontalList方法的典型用法代码示例。如果您正苦于以下问题:Java UiScrollable.setAsHorizontalList方法的具体用法?Java UiScrollable.setAsHorizontalList怎么用?Java UiScrollable.setAsHorizontalList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.android.uiautomator.core.UiScrollable的用法示例。


在下文中一共展示了UiScrollable.setAsHorizontalList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDemo

import com.android.uiautomator.core.UiScrollable; //导入方法依赖的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で入力しています。"));
    }
 
开发者ID:Xiangxingqian,项目名称:WeiXinGroupSend,代码行数:24,代码来源:UiAutomatorInputTest.java

示例2: testLaunch

import com.android.uiautomator.core.UiScrollable; //导入方法依赖的package包/类
/**
 * Play Store launch test.
 *
 * @throws UiObjectNotFoundException
 */
public void testLaunch() throws UiObjectNotFoundException {

    getUiDevice().pressHome();
    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 settingsApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()),
            "Play Store");
    settingsApp.clickAndWaitForNewWindow();

    UiObject settingsValidation = new UiObject(new UiSelector().packageName("com.android.vending"));
    assertTrue("Unable to detect Play Store", settingsValidation.exists());
}
 
开发者ID:croute,项目名称:UiAutomatorExample,代码行数:25,代码来源:LaunchSettings.java

示例3: findAndRunApp

import com.android.uiautomator.core.UiScrollable; //导入方法依赖的package包/类
private void findAndRunApp() throws UiObjectNotFoundException {
    // Go to main screen
    getUiDevice().pressHome();
    // Find menu button
    UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
    // Click on menu button and wait new window
    allAppsButton.clickAndWaitForNewWindow();
    // Find App tab
    UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
    // Click on app tab
    appsTab.click();
    // Find scroll object (menu scroll)
    UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
    // Set the swiping mode to horizontal (the default is vertical)
    appViews.setAsHorizontalList();
    // Find Messaging application
    UiObject settingsApp = appViews.getChildByText(new UiSelector().className("android.widget.TextView"), "My Files");
    // Open Messaging application
    settingsApp.clickAndWaitForNewWindow();

    // Validate that the package name is the expected one
    UiObject settingsValidation = new UiObject(new UiSelector().packageName("com.sec.android.app.myfiles"));
    assertTrue("Unable to detect MyFiles", settingsValidation.exists());
}
 
开发者ID:amazpyel,项目名称:uiautomator_sample,代码行数:25,代码来源:CopyFile.java

示例4: testDemo

import com.android.uiautomator.core.UiScrollable; //导入方法依赖的package包/类
/**
 * Script starts here
 * @throws UiObjectNotFoundException
 */
public void testDemo() throws UiObjectNotFoundException {
    // The following code is documented in the LaunchSettings demo. For detailed description
    // of how this code works, look at the demo LaunchSettings

    // Good to start from here
    getUiDevice().pressHome();

    // open the All Apps view
    UiObject allAppsButton = new UiObject(LauncherHelper.ALL_APPS_BUTTON);
    allAppsButton.click();

    // clicking the APPS tab
    UiSelector appsTabSelector =
            new UiSelector().className(android.widget.TabWidget.class.getName())
                .childSelector(new UiSelector().text("Apps"));
    UiObject appsTab = new UiObject(appsTabSelector);
    appsTab.click();

    // Clicking the Settings
    UiScrollable allAppsScreen = new UiScrollable(LauncherHelper.LAUNCHER_CONTAINER);
    allAppsScreen.setAsHorizontalList();
    UiObject settingsApp =
            allAppsScreen.getChildByText(LauncherHelper.LAUNCHER_ITEM, "Settings");
    settingsApp.click();

    // Now we will select the settings we need to work with. To make this operation a little
    // more generic we will put it in a function. We will try it as a phone first then as a
    // tablet if phone is not our device type
    if (!selectSettingsFor("About phone"))
        selectSettingsFor("About tablet");

    // Now we need to read the Build number text and return it
    String buildNum = getAboutItem("Build number");

    // Log it - Use adb logcat to view the results
    Log.i(LOG_TAG, "Build = " + buildNum);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:42,代码来源:LogBuildNumber.java

示例5: testDemo

import com.android.uiautomator.core.UiScrollable; //导入方法依赖的package包/类
/**
 * Set an alarm 2 minutes from now and verify it goes off. Also check the notification
 * shades for an alarm. (Crude test but it demos the use of Android resources)
 * @throws UiObjectNotFoundException
 */
public void testDemo() throws UiObjectNotFoundException {
    // The following code is documented in the LaunchSettings demo. For detailed description
    // of how this code works, look at the demo LaunchSettings

    // Good to start from here
    getUiDevice().pressHome();

    // open the All Apps view
    UiObject allAppsButton = new UiObject(LauncherHelper.ALL_APPS_BUTTON);
    allAppsButton.click();

    // clicking the APPS tab
    UiSelector appsTabSelector =
            new UiSelector().className(android.widget.TabWidget.class.getName())
                .childSelector(new UiSelector().text("Apps"));
    UiObject appsTab = new UiObject(appsTabSelector);
    appsTab.click();

    // Clicking the Settings
    UiScrollable allAppsScreen = new UiScrollable(LauncherHelper.LAUNCHER_CONTAINER);
    allAppsScreen.setAsHorizontalList();
    UiObject clockApp =
            allAppsScreen.getChildByText(LauncherHelper.LAUNCHER_ITEM, "Clock");
    clockApp.click();

    // Set an alarm to go off in about 2 minutes
    setAlarm(2);

    // wait for the alarm alert dialog
    UiObject alarmAlert =
            new UiObject(new UiSelector().packageName("com.google.android.deskclock")
                    .className(TextView.class.getName()).text("Alarm"));

    assertTrue("Timeout while waiting for alarm to go off",
            alarmAlert.waitForExists(2 * 60 * 1000));

    clickByText("Dismiss");
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:44,代码来源:SetTwoMinuteAlarm.java

示例6: start_target_app

import com.android.uiautomator.core.UiScrollable; //导入方法依赖的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);
	}
 
开发者ID:MagicHry,项目名称:EnhancedPUMA,代码行数:34,代码来源:EnhancedPUMALauncher.java

示例7: startApp

import com.android.uiautomator.core.UiScrollable; //导入方法依赖的package包/类
/**
 * 無効化マネージャーを起動する
 */
private void startApp() throws Exception {
    getUiDevice().pressHome();
    getUiDevice().pressBack();

    Runtime.getRuntime().exec("am start -n com.nagopy.android.disablemanager2/.MainActivity");
    if (true) return;

    UiObject allAppsButton = new UiObject(
            new UiSelectorBuilder()
                    .description("アプリ").build()
    );
    allAppsButton.clickAndWaitForNewWindow();

    UiScrollable appViews = new UiScrollable(
            new UiSelectorBuilder().
                    scrollable(true).build()
    );
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        appViews.setAsHorizontalList();
    }
    UiObject settingsApp = appViews.getChildByText(
            new UiSelectorBuilder()
                    .className(TextView.class.getName()).build(),
            "無効化マネージャー");
    settingsApp.clickAndWaitForNewWindow();

    assertTrue("アプリ起動に失敗", TestUtils.isTargetApp(TestUtils.PACKAGE_NAME));
}
 
开发者ID:75py,项目名称:DisableManager,代码行数:32,代码来源:MainActivityTestCase.java

示例8: testDemo

import com.android.uiautomator.core.UiScrollable; //导入方法依赖的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());
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:66,代码来源:LaunchSettings.java

示例9: openYaacc

import com.android.uiautomator.core.UiScrollable; //导入方法依赖的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();
	
}
 
开发者ID:theopenbit,项目名称:yaacc-code,代码行数:42,代码来源:UITestCase.java

示例10: start_target_app

import com.android.uiautomator.core.UiScrollable; //导入方法依赖的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);
}
 
开发者ID:MagicHry,项目名称:EnhancedPUMA,代码行数:58,代码来源:LaunchApp.java

示例11: handle

import com.android.uiautomator.core.UiScrollable; //导入方法依赖的package包/类
@Override
public Object handle(Object[] args) throws Exception {
    ScrollDirection scrollDirection = (ScrollDirection) args[0];
    UiElementPropertiesContainer propertiesContainer = (UiElementPropertiesContainer) args[1];
    UiSelector selector = UiSelectorParser.convertSelector(propertiesContainer);

    Integer maxSwipes = (Integer) args[2];
    Integer maxSteps = (Integer) args[3];
    Boolean isVertical = (Boolean) args[4];

    UiScrollable scrollableView = new UiScrollable(selector);

    if (!isVertical) {
        scrollableView.setAsHorizontalList();
    }

    Boolean response = false;

    if (maxSteps != 0) {
        switch (scrollDirection) {
            case SCROLL_TO_BEGINNING:
                response = scrollableView.scrollToBeginning(maxSwipes, maxSteps);
                break;
            case SCROLL_TO_END:
                response = scrollableView.scrollToEnd(maxSwipes, maxSteps);
                break;
            case SCROLL_BACKWARD:
                response = scrollableView.scrollBackward(maxSteps);
                break;
            case SCROLL_FORWARD:
                response = scrollableView.scrollForward(maxSteps);
                break;
            default:
                break;
        }
    } else {
        switch (scrollDirection) {
            case SCROLL_TO_BEGINNING:
                response = scrollableView.scrollToBeginning(maxSwipes);
                break;
            case SCROLL_TO_END:
                response = scrollableView.scrollToEnd(maxSwipes);
                break;
            case SCROLL_BACKWARD:
                response = scrollableView.scrollBackward();
                break;
            case SCROLL_FORWARD:
                response = scrollableView.scrollForward();
                break;
            default:
                break;
        }
    }

    return response;
}
 
开发者ID:MusalaSoft,项目名称:atmosphere-uiautomator-bridge,代码行数:57,代码来源:ScrollableViewDirectionScroller.java

示例12: restartTSAP

import com.android.uiautomator.core.UiScrollable; //导入方法依赖的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();
}
 
开发者ID:Tribler,项目名称:tribler-android,代码行数:52,代码来源:SpecialEventsUiTest.java

示例13: start_target_app

import com.android.uiautomator.core.UiScrollable; //导入方法依赖的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
	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);
}
 
开发者ID:USC-NSL,项目名称:PUMA,代码行数:54,代码来源:LaunchApp.java

示例14: testDemo

import com.android.uiautomator.core.UiScrollable; //导入方法依赖的package包/类
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());
	}
 
开发者ID:vogellacompany,项目名称:codeexamples-android,代码行数:49,代码来源:LaunchSettings.java

示例15: testNavigate

import com.android.uiautomator.core.UiScrollable; //导入方法依赖的package包/类
public void testNavigate() throws UiObjectNotFoundException {
	getUiDevice().pressHome();

	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 apiDemos = appViews.getChildByText(
			new UiSelector().className(TextView.class.getName()), "API Demos");
	apiDemos.clickAndWaitForNewWindow();

	UiObject apiDemosPackage = new UiObject(new UiSelector().packageName("com.example.android.apis"));
	assertTrue("Should be on ApiDemos", apiDemosPackage.exists());   

	UiScrollable demosList = new UiScrollable(new UiSelector().className("android.widget.ListView"));
	
	UiObject graphicsDemo = demosList.getChildByText(
			new UiSelector().className(TextView.class.getName()), "Graphics");
	graphicsDemo.clickAndWaitForNewWindow();

	UiObject alphaBitmapDemo = new UiObject(new UiSelector().text("AlphaBitmap"));
	assertTrue("AlphaBitmap should be visible", alphaBitmapDemo.exists());   

	UiScrollable graphicsDemoList = new UiScrollable(new UiSelector().className("android.widget.ListView"));
	
	UiObject openGlesDemo = graphicsDemoList.getChildByText(
			new UiSelector().className(TextView.class.getName()), "OpenGL ES");
	openGlesDemo.clickAndWaitForNewWindow();

	// Validate that the package name is the expected one
	UiObject compressedTextureDemo = new UiObject(new UiSelector().text("Compressed Texture"));
	assertTrue("Compressed Texture should be visible", compressedTextureDemo.exists());   

	UiScrollable openGlesDemoList = new UiScrollable(new UiSelector().className("android.widget.ListView"));
	
	UiObject kubeDemo = openGlesDemoList.getChildByText(
			new UiSelector().className(TextView.class.getName()), "Kube");
	kubeDemo.clickAndWaitForNewWindow();

	try {
		Thread.sleep(3000);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	
	getUiDevice().pressBack();
	getUiDevice().pressBack();
	getUiDevice().pressBack();
	getUiDevice().pressBack();
}
 
开发者ID:snailee,项目名称:deview-2013-samples,代码行数:58,代码来源:ApiDemosUiAutoTest.java


注:本文中的com.android.uiautomator.core.UiScrollable.setAsHorizontalList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。