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;
}
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;
}
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;
}
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());
}
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.");
}
Aggregations