Search in sources :

Example 11 with UiSelector

use of com.android.uiautomator.core.UiSelector in project android-player-samples by BrightcoveOS.

the class OnceUxUiAutomatorBase method tearDown.

/**
     * In the tearDown, using UiAutomator API, it goes back to home, reopens the 
     * applications menu, sifts through and finds the settings app, and then force 
     * closes the Sample App. Then, it opens up the recent apps screen, and swipes
     * away the Sample App from that screen. By doing so we entirely remove it 
     * from the device's cached memory. This allows us to have a totally clean 
     * environment when beginning a new test.
     */
@Override
protected void tearDown() throws Exception {
    // We now want to leave the app and close it entirely. The first step is to go to the all apps menu and navigate through it.
    getUiDevice().pressHome();
    Log.v(TAG, "Pressing the Home button.");
    TimeUnit.SECONDS.sleep(1);
    UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
    allAppsButton.clickAndWaitForNewWindow();
    Log.v(TAG, "Pressing the All Apps button.");
    // Next, we have to navigate through the apps menu.
    UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
    appsTab.click();
    Log.v(TAG, "Pressing the Apps tab.");
    UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
    appViews.setAsHorizontalList();
    // Next, we open the settings app, and open the particular section that specifies settings for Apps.
    UiObject settingsApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), "Settings");
    settingsApp.click();
    Log.v(TAG, "Pressing the Settings app.");
    UiObject settingsAppsTab = new UiObject(new UiSelector().text("Apps"));
    settingsAppsTab.click();
    Log.v(TAG, "Pressing the Apps tab in the Settings App.");
    // Next, we must choose the "Basic ONCE UX Sample App".
    UiObject basicOnceUxSampleAppSettings = new UiObject(new UiSelector().text("Basic ONCE UX Sample App"));
    basicOnceUxSampleAppSettings.click();
    Log.v(TAG, "Pressing the Basic ONCE UX Sample App in the Apps Settings field.");
    // And we Force stop the sample app, pressing OK when the clarification prompt appears, and leave settings.
    UiObject forceStopButton = new UiObject(new UiSelector().text("Force stop"));
    forceStopButton.clickAndWaitForNewWindow();
    UiObject okButton = new UiObject(new UiSelector().text("OK").className(android.widget.Button.class));
    okButton.click();
    getUiDevice().pressHome();
    Log.v(TAG, "Pressing the Home button.");
    // The following could serve as an alternative to the first method, or can be used in conjunction 
    // with it. It only works for android devices that have a recent apps button.
    // First, we open the recent apps screen.
    getUiDevice().pressHome();
    Log.v(TAG, "Pressing the Home button.");
    getUiDevice().pressRecentApps();
    Log.v(TAG, "Pressing the Recent Apps button.");
    // Then we register the UiObject and swipe it down in order to remove it from the recent activity screen, and return to home.
    UiObject basicOnceUxSampleAppRecentActivity = new UiObject(new UiSelector().description("Basic ONCE UX Sample App"));
    basicOnceUxSampleAppRecentActivity.swipeDown(20);
    Log.v(TAG, "Swiping away the Basic Once Ux Sample App activity Ui Object.");
    getUiDevice().pressHome();
    Log.v(TAG, "Pressing the Home button.");
}
Also used : UiObject(com.android.uiautomator.core.UiObject) UiSelector(com.android.uiautomator.core.UiSelector) UiScrollable(com.android.uiautomator.core.UiScrollable)

Example 12 with UiSelector

use of com.android.uiautomator.core.UiSelector in project android-player-samples by BrightcoveOS.

the class OnceUxUiAutomatorBase method setUp.

// Universal setUp and tearDown methods.
/**
     * Test represents a setUp method for the other tests. Using the UiAutomator API, it
     * goes to the home menu, opens up applications, sifts through and opens up the Basic
     * OnceUx Sample App. It opens the application with the name that matches "Basic ONCE 
     * UX Sample App."
     */
protected void setUp() throws Exception {
    // Simulate a short press on the HOME button and navigate to apps screen.
    getUiDevice().pressHome();
    Log.v(TAG, "Pressing the home button.");
    UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
    allAppsButton.clickAndWaitForNewWindow();
    Log.v(TAG, "Pressing the All Apps button.");
    // Next is the task of navigating to the sample app in the apps menu and scrolling through until it is found.
    UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
    appsTab.click();
    Log.v(TAG, "Pressing the Apps tab.");
    UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
    appViews.setAsHorizontalList();
    // If it exists, we want to press on the app's icon, launching it.
    basicOnceUxSampleApp = appViews.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), "Basic ONCE UX Sample App");
    if (basicOnceUxSampleApp != null) {
        basicOnceUxSampleApp.clickAndWaitForNewWindow();
        Log.v(TAG, "Pressing the Basic Once Ux Sample App.");
    }
}
Also used : UiObject(com.android.uiautomator.core.UiObject) UiSelector(com.android.uiautomator.core.UiSelector) UiScrollable(com.android.uiautomator.core.UiScrollable)

Example 13 with UiSelector

use of com.android.uiautomator.core.UiSelector in project android-player-samples by BrightcoveOS.

the class PlayStartMessTestCase method testPlayStartMessFFWDCheck.

/**
     * testPlayStartMessFFWDCheck creates the scenario described in the class level comment,
     * then waits for two seconds for the scenario to initialize. Then, the test asserts the
     * fast forward button will not be present. If it is present, the test will fail.
     */
public void testPlayStartMessFFWDCheck() throws Exception {
    Log.v(TAG, "Beginning testPlayStartMessFFWDCheck");
    playVideoSpecialized();
    TimeUnit.SECONDS.sleep(2);
    UiObject ffwdButton = new UiObject(new UiSelector().resourceId("android:id/ffwd"));
    assertFalse("Failure: Fast Forward button found.", ffwdButton.waitForExists(10000));
}
Also used : UiObject(com.android.uiautomator.core.UiObject) UiSelector(com.android.uiautomator.core.UiSelector)

Example 14 with UiSelector

use of com.android.uiautomator.core.UiSelector in project android-player-samples by BrightcoveOS.

the class PlayStartMessTestCase method testPlayStartMessREWCheck.

/**
     * testPlayStartMessREWCheck creates the scenario described in the class level comment,
     * then waits for two seconds for the scenario to initialize. Then, the test asserts the 
     * rewind button will not be there. If it is present, the test will fail.
     */
public void testPlayStartMessREWCheck() throws Exception {
    Log.v(TAG, "Beginning testPlayStartMessREWCheck");
    playVideoSpecialized();
    TimeUnit.SECONDS.sleep(2);
    UiObject rewButton = new UiObject(new UiSelector().resourceId("android:id/rew"));
    assertFalse("Failure: Rewind button found.", rewButton.waitForExists(10000));
}
Also used : UiObject(com.android.uiautomator.core.UiObject) UiSelector(com.android.uiautomator.core.UiSelector)

Example 15 with UiSelector

use of com.android.uiautomator.core.UiSelector in project android-player-samples by BrightcoveOS.

the class PlayStartMessTestCase method playVideoSpecialized.

/**
     * The scenario as described in the class level comment occurs based on an outdated 
     * version of the super.playVideo method. As a result, that version needed to be 
     * preserved here for testing that scenario. Unlike the current super.playVideo(),
     * playVideoSpecialized() does not wait for the video to load, and instead presses play
     * as soon as the sample app reveals seek controls.
     */
private void playVideoSpecialized() throws Exception {
    UiObject playButton = new UiObject(new UiSelector().resourceId("android:id/pause"));
    playButton.waitForExists(6000);
    Log.v(TAG, "Pressing Play...");
    try {
        playButton.click();
    } catch (UiObjectNotFoundException playButtonMissing) {
        playButtonMissing.printStackTrace();
        Log.v(TAG, "Play button not found. Trying again.");
        super.toggleSeekControlsVisibility();
        playButton.click();
    }
}
Also used : UiObject(com.android.uiautomator.core.UiObject) UiSelector(com.android.uiautomator.core.UiSelector) UiObjectNotFoundException(com.android.uiautomator.core.UiObjectNotFoundException)

Aggregations

UiObject (com.android.uiautomator.core.UiObject)16 UiSelector (com.android.uiautomator.core.UiSelector)16 UiScrollable (com.android.uiautomator.core.UiScrollable)4 UiObjectNotFoundException (com.android.uiautomator.core.UiObjectNotFoundException)3 FlakyTest (android.test.FlakyTest)2 LargeTest (android.test.suitebuilder.annotation.LargeTest)2 UiDevice (com.android.uiautomator.core.UiDevice)1