Search in sources :

Example 1 with ActivityMonitor

use of android.app.Instrumentation.ActivityMonitor in project robotium by RobotiumTech.

the class Waiter method getActivityMonitor.

/**
	 * Creates a new ActivityMonitor and returns it
	 * 
	 * @return an ActivityMonitor
	 */
private ActivityMonitor getActivityMonitor() {
    IntentFilter filter = null;
    ActivityMonitor activityMonitor = instrumentation.addMonitor(filter, null, false);
    return activityMonitor;
}
Also used : IntentFilter(android.content.IntentFilter) ActivityMonitor(android.app.Instrumentation.ActivityMonitor)

Example 2 with ActivityMonitor

use of android.app.Instrumentation.ActivityMonitor in project robotium by RobotiumTech.

the class Waiter method waitForActivity.

/**
	 * Waits for the given {@link Activity}.
	 *
	 * @param name the name of the {@code Activity} to wait for e.g. {@code "MyActivity"}
	 * @param timeout the amount of time in milliseconds to wait
	 * @return {@code true} if {@code Activity} appears before the timeout and {@code false} if it does not
	 *
	 */
public boolean waitForActivity(String name, int timeout) {
    if (isActivityMatching(activityUtils.getCurrentActivity(false, false), name)) {
        return true;
    }
    boolean foundActivity = false;
    ActivityMonitor activityMonitor = getActivityMonitor();
    long currentTime = SystemClock.uptimeMillis();
    final long endTime = currentTime + timeout;
    while (currentTime < endTime) {
        Activity currentActivity = activityMonitor.waitForActivityWithTimeout(endTime - currentTime);
        if (isActivityMatching(currentActivity, name)) {
            foundActivity = true;
            break;
        }
        currentTime = SystemClock.uptimeMillis();
    }
    removeMonitor(activityMonitor);
    return foundActivity;
}
Also used : ActivityMonitor(android.app.Instrumentation.ActivityMonitor) FragmentActivity(android.support.v4.app.FragmentActivity) Activity(android.app.Activity)

Example 3 with ActivityMonitor

use of android.app.Instrumentation.ActivityMonitor in project robotium by RobotiumTech.

the class Waiter method waitForActivity.

/**
	 * Waits for the given {@link Activity}.
	 *
	 * @param activityClass the class of the {@code Activity} to wait for
	 * @param timeout the amount of time in milliseconds to wait
	 * @return {@code true} if {@code Activity} appears before the timeout and {@code false} if it does not
	 *
	 */
public boolean waitForActivity(Class<? extends Activity> activityClass, int timeout) {
    if (isActivityMatching(activityClass, activityUtils.getCurrentActivity(false, false))) {
        return true;
    }
    boolean foundActivity = false;
    ActivityMonitor activityMonitor = getActivityMonitor();
    long currentTime = SystemClock.uptimeMillis();
    final long endTime = currentTime + timeout;
    while (currentTime < endTime) {
        Activity currentActivity = activityMonitor.waitForActivityWithTimeout(endTime - currentTime);
        if (currentActivity != null && currentActivity.getClass().equals(activityClass)) {
            foundActivity = true;
            break;
        }
        currentTime = SystemClock.uptimeMillis();
    }
    removeMonitor(activityMonitor);
    return foundActivity;
}
Also used : ActivityMonitor(android.app.Instrumentation.ActivityMonitor) FragmentActivity(android.support.v4.app.FragmentActivity) Activity(android.app.Activity)

Example 4 with ActivityMonitor

use of android.app.Instrumentation.ActivityMonitor in project AndroidTraining by mixi-inc.

the class SampleActivityInstrumentationTestCase method testCallSubActivityAndReturn.

public void testCallSubActivityAndReturn() throws Exception {
    Activity activity = getActivity();
    // UI 操作による View の状態を見るために、View のインスタンスを取り出す
    TextView counter = (TextView) activity.findViewById(R.id.ClickCounter);
    Button button = (Button) activity.findViewById(R.id.CountEventTrigger);
    Button button2 = (Button) activity.findViewById(R.id.CallSubActivity);
    // 最初は 0
    assertEquals("0", counter.getText().toString());
    // ボタンのクリックをシミュレート
    TouchUtils.clickView(this, button);
    // クリックしたら、カウンタの値がインクリメントされる
    assertEquals("1", counter.getText().toString());
    // Activity の起動を監視する(厳密には Intent を監視する)オブジェクトを作る
    ActivityMonitor monitor = new ActivityMonitor(SubActivity.class.getCanonicalName(), null, true);
    // 監視オブジェクトを登録
    getInstrumentation().addMonitor(monitor);
    // Launch SubActivity をクリック
    TouchUtils.clickView(this, button2);
    // 起動を待つ
    Activity newActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, 3000L);
    // 1 つの Activity が起動しているはず
    assertEquals(1, monitor.getHits());
    // 終わる
    if (newActivity != null)
        newActivity.finish();
    // 戻ってきても状態が復帰できるはず
    assertEquals("1", counter.getText().toString());
}
Also used : SubActivity(jp.mixi.sample.test.SubActivity) ActivityMonitor(android.app.Instrumentation.ActivityMonitor) Button(android.widget.Button) SubActivity(jp.mixi.sample.test.SubActivity) MainActivity(jp.mixi.sample.test.MainActivity) Activity(android.app.Activity) TextView(android.widget.TextView)

Example 5 with ActivityMonitor

use of android.app.Instrumentation.ActivityMonitor in project newsrob by marianokamp.

the class DashboardListActivityTests method xtestLaunchFeedListActivity.

public void xtestLaunchFeedListActivity() {
    String className = FeedListActivity.class.getName();
    System.out.println("className=" + className);
    ActivityMonitor am = new ActivityMonitor(className, null, true);
    // "all articles"
    sendKeys("DPAD_DOWN DPAD_CENTER");
    SystemClock.sleep(3000);
    getInstrumentation().waitForIdleSync();
    if (am.getHits() == 0)
        fail("FeedListActitivy not called.");
}
Also used : ActivityMonitor(android.app.Instrumentation.ActivityMonitor)

Aggregations

ActivityMonitor (android.app.Instrumentation.ActivityMonitor)8 Activity (android.app.Activity)6 FragmentActivity (android.support.v4.app.FragmentActivity)2 DefaultWelcomeActivity (com.stephentuso.welcomeexample.DefaultWelcomeActivity)2 Test (org.junit.Test)2 Instrumentation (android.app.Instrumentation)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Bundle (android.os.Bundle)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 MainActivity (jp.mixi.sample.test.MainActivity)1 SubActivity (jp.mixi.sample.test.SubActivity)1