Search in sources :

Example 1 with UiObject

use of com.android.uiautomator.core.UiObject in project AndroidTraining by mixi-inc.

the class MainActivityAutomatorTestCase method testMainActivityButtonClick.

public void testMainActivityButtonClick() throws Exception {
    // デバイスオブジェクトの取得。このオブジェクトを介して、デバイスの状態を取得したり、UI の操作を行ったりする。
    UiDevice device = getUiDevice();
    // ホームボタンを押す
    device.pressHome();
    // ホームボタンに有るターゲットのアイコンをタップする
    UiObject launchIcon = new UiObject(new UiSelector().textContains("TestTarget"));
    launchIcon.clickAndWaitForNewWindow();
    // 起動した(指定したパッケージ名のアプリがフォアグラウンドに居て、オブジェクトの取得が無事に出来る)
    UiObject app = new UiObject(new UiSelector().packageName("jp.mixi.sample.test"));
    assertTrue(app.exists());
    device.pressBack();
    // もう一度タップ
    UiObject launchIcon2 = new UiObject(new UiSelector().textContains("TestTarget"));
    launchIcon2.clickAndWaitForNewWindow();
    // カウンターの初期値は 0
    UiObject firstCounterState = new UiObject(new UiSelector().text("0"));
    assertTrue(firstCounterState.exists());
    // カウントアップ
    UiObject countUp = new UiObject(new UiSelector().text("Count up"));
    countUp.click();
    // カウンターが更新される
    UiObject secondCounterState = new UiObject(new UiSelector().text("1"));
    assertTrue(secondCounterState.exists());
}
Also used : UiObject(com.android.uiautomator.core.UiObject) UiSelector(com.android.uiautomator.core.UiSelector) UiDevice(com.android.uiautomator.core.UiDevice)

Example 2 with UiObject

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

the class CompanionAdTestCase method companionCheck.

// Utility Methods
/**
     * companionCheck returns <code>true</code> if it finds the companion and, and <code>false</code> 
     * if it does not find it. The method searches for the companion ad frame,
     * then it finds the companion ad itself using the frame as a parent Ui Object.
     *
     * @return true if the companion ad is found, otherwise false.
     */
private boolean companionCheck() throws Exception {
    Log.v(TAG, "Beginning companionCheck");
    UiObject companionAdFrame = new UiObject(new UiSelector().resourceId("com.brightcove.player.samples.onceux.basic:id/ad_frame"));
    try {
        companionAd = companionAdFrame.getChild(new UiSelector().className(android.widget.ImageView.class));
        assertTrue(companionAd.isEnabled());
        return true;
    } catch (UiObjectNotFoundException companionAdNotFound) {
        return false;
    }
}
Also used : UiObject(com.android.uiautomator.core.UiObject) UiSelector(com.android.uiautomator.core.UiSelector) UiObjectNotFoundException(com.android.uiautomator.core.UiObjectNotFoundException)

Example 3 with UiObject

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

the class LearnMoreTestCase method adBreakHandler.

/**
     * adBreakHandler checks for the presence of the UiObject that is ubiquitous in every ad break,
     * a text view that reads "Your video will resume in" followed by a number of seconds. Upon seeing
     * that object and verifying if it is enabled, the test for Learn More is done, then the test 
     * waits for the object to disappear, signaling the end of the ad break.
     */
private void adBreakHandler() throws Exception {
    UiObject adMarkerText = new UiObject(new UiSelector().textStartsWith("Your video will resume in"));
    if (adMarkerText.exists() && adMarkerText.isEnabled()) {
        Log.v(TAG, "Ad Break started.");
        assertTrue("Conditions did not match.", learnMoreChecker());
    }
}
Also used : UiObject(com.android.uiautomator.core.UiObject) UiSelector(com.android.uiautomator.core.UiSelector)

Example 4 with UiObject

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

the class OnceUxUiAutomatorBase method playVideo.

// Other Universal Utility Methods
/**
     * playVideo provides a method that allows for universal access to the play function. It was
     * created as a separate entity to the tests and setUp to help prevent subtle changes from
     * breaking the sample app before function has begun. A universal method helps in this case,
     * and in order to keep the setUp method universal across all test cases, play was kept separate.
     *
     * @throws UiObjectNotFoundException playButtonMissing when the seek controls are hidden.
     */
protected void playVideo() throws Exception {
    // First, wait for the Sample App to entirely process the video and we tap the screen to reveal the seek controls and press play.
    TimeUnit.SECONDS.sleep(6);
    UiObject playButton = new UiObject(new UiSelector().resourceId("android:id/pause"));
    Log.v(TAG, "Pressing Play...");
    try {
        playButton.click();
    } catch (UiObjectNotFoundException playButtonMissing) {
        Log.v(TAG, "Play button not found. Trying again.");
        toggleSeekControlsVisibility();
        playButton.click();
    }
}
Also used : UiObject(com.android.uiautomator.core.UiObject) UiSelector(com.android.uiautomator.core.UiSelector) UiObjectNotFoundException(com.android.uiautomator.core.UiObjectNotFoundException)

Example 5 with UiObject

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

the class PlayStartMessTestCase method testPlayStartMessCompanionAd.

/**
     * testPlayStartMessCompanionAd creates the scenario described in the class level comment,
     * then waits for two seconds for the scenario to initialize. Then, the test toggles seek 
     * control viewability and asserts that the companion ad will not be there. The companion
     * ad was implemented after this scenario was discovered, but it also appeared when the 
     * scenario is initialized.
     */
public void testPlayStartMessCompanionAd() throws Exception {
    Log.v(TAG, "Beginning testPlayStartMessCompanionAd");
    playVideoSpecialized();
    TimeUnit.SECONDS.sleep(2);
    super.toggleSeekControlsVisibility();
    UiObject companionAd = new UiObject(new UiSelector().resourceId("com.brightcove.player.samples.onceux.basic:id/ad_frame"));
    assertFalse("Failure: Companion ad found.", companionAd.waitForExists(10000));
}
Also used : UiObject(com.android.uiautomator.core.UiObject) UiSelector(com.android.uiautomator.core.UiSelector)

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