Java 类android.app.Instrumentation.ActivityMonitor 实例源码

项目:RNLearn_Project1    文件:ShareTestCase.java   
public void testShowBasicShareDialog() {
  final WritableMap content = new WritableNativeMap();
  content.putString("message", "Hello, ReactNative!");
  final WritableMap options = new WritableNativeMap();

  IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CHOOSER);
  intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
  ActivityMonitor monitor = getInstrumentation().addMonitor(intentFilter, null, true);

  getTestModule().showShareDialog(content, options);

  waitForBridgeAndUIIdle();
  getInstrumentation().waitForIdleSync();

  assertEquals(1, monitor.getHits());
  assertEquals(1, mRecordingModule.getOpened());
  assertEquals(0, mRecordingModule.getErrors());

}
项目:RNLearn_Project1    文件:ShareTestCase.java   
public void testShowBasicShareDialog() {
  final WritableMap content = new WritableNativeMap();
  content.putString("message", "Hello, ReactNative!");
  final WritableMap options = new WritableNativeMap();

  IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CHOOSER);
  intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
  ActivityMonitor monitor = getInstrumentation().addMonitor(intentFilter, null, true);

  getTestModule().showShareDialog(content, options);

  waitForBridgeAndUIIdle();
  getInstrumentation().waitForIdleSync();

  assertEquals(1, monitor.getHits());
  assertEquals(1, mRecordingModule.getOpened());
  assertEquals(0, mRecordingModule.getErrors());

}
项目:Ironman    文件:ShareTestCase.java   
public void testShowBasicShareDialog() {
  final WritableMap content = new WritableNativeMap();
  content.putString("message", "Hello, ReactNative!");
  final WritableMap options = new WritableNativeMap();

  IntentFilter intentFilter = new IntentFilter(Intent.ACTION_CHOOSER);
  intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
  ActivityMonitor monitor = getInstrumentation().addMonitor(intentFilter, null, true);

  getTestModule().showShareDialog(content, options);

  waitForBridgeAndUIIdle();
  getInstrumentation().waitForIdleSync();

  assertEquals(1, monitor.getHits());
  assertEquals(1, mRecordingModule.getOpened());
  assertEquals(0, mRecordingModule.getErrors());

}
项目:test_agent_android    文件:Waiter.java   
/**
 * 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;
}
项目:test_agent_android    文件:Waiter.java   
/**
 * 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;
}
项目:welcome-android    文件:WelcomeScreenHelperAndroidTest.java   
@Test
public void testShow() {
    ActivityMonitor monitor = new ActivityMonitor(DefaultWelcomeActivity.class.getName(), null, false);
    instrumentation.addMonitor(monitor);

    String key = WelcomeUtils.getKey(DefaultWelcomeActivity.class);

    WelcomeSharedPreferencesHelper.storeWelcomeCompleted(activity, key);
    assertFalse(helper.show(null));
    assertFalse(helper.show(new Bundle()));

    WelcomeSharedPreferencesHelper.removeWelcomeCompleted(activity, key);

    assertTrue(helper.show(null));
    assertFalse(helper.show(null));

    Activity welcomeActivity = instrumentation.waitForMonitor(monitor);
    assertNotNull(welcomeActivity);

    WelcomeSharedPreferencesHelper.removeWelcomeCompleted(activity, key);

    Bundle state = new Bundle();
    helper.onSaveInstanceState(state);
    assertFalse(helper.show(state));
}
项目:evend    文件:StartupActivityFunctionalTest.java   
public void testOnCreateWithNoUserData() throws Exception {
    Context context = getInstrumentation().getTargetContext();
    identifier = null;

    StorageHelper.PreferencesHelper.setIdentifier(context, identifier);

    // Add monitor to check for the welcome activity
    ActivityMonitor monitor = getInstrumentation().addMonitor(
            WelcomeActivity.class.getName(), null, false);

    startupActivity = getActivity();

    // Wait 2 seconds for the start of the activity
    WelcomeActivity welcomeActivity = (WelcomeActivity) monitor
            .waitForActivityWithTimeout(2000);

    startupActivity.finish();

    assertNull(welcomeActivity);
}
项目:TravelTracker    文件:ClaimInfoActivityTest.java   
public void testViewExpenseItems() throws InterruptedException {
    startWithClaim(UserRole.CLAIMANT);

    ActivityMonitor monitor = instrumentation.addMonitor(ExpenseItemsListActivity.class.getName(), null, false);

    final Button viewItemsButton = (Button) activity.findViewById(R.id.claimInfoViewItemsButton);
    instrumentation.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            viewItemsButton.performClick();
        }
    });

    final Activity newActivity = monitor.waitForActivityWithTimeout(3000);

    assertNotNull("Expense list activity should start", newActivity);

    newActivity.finish();
    instrumentation.waitForIdleSync();

    // This is a stupid hack, but Android sometimes fails to back out in time
    Thread.sleep(100);
}
项目:TravelTracker    文件:ClaimsListActivityTest.java   
public void testCreateExpenseClaim() throws Throwable {

    ClaimsListActivity activity = startActivity(new UserData(user2.getUUID(), user2.getUserName(), UserRole.CLAIMANT));
    ActivityMonitor monitor = getInstrumentation().addMonitor(ClaimInfoActivity.class.getName(), null, false);
    ListView listView = (ListView) activity.findViewById(R.id.claimsListClaimListView);

    assertEquals(1, listView.getCount());

    boolean success = getInstrumentation().invokeMenuActionSync(activity, R.id.claims_list_add_claim, 0);
    assertTrue(success);
    Activity newActivity = monitor.waitForActivityWithTimeout(3000);
    assertNotNull(newActivity);
    newActivity.finish();
    getInstrumentation().waitForIdleSync();
    Thread.sleep(300);
    assertEquals(2, listView.getCount());

}
项目:robotium-tech    文件:Waiter.java   
/**
 * 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;
}
项目:robotium-tech    文件:Waiter.java   
/**
 * 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;
}
项目:SensorDataCollector    文件:TestHelper.java   
public static Activity launchCreateExperimentActivity(
        ActivityInstrumentationTestCase2<?> testCase, Activity activity) {

    // click the Create-New-Experiment button
    ActivityMonitor activityMonitor = testCase.getInstrumentation().addMonitor(
            CreateExperimentActivity.class.getName(), null, false);

    Button buttonCreateExperiment = (Button) activity
            .findViewById(R.id.button_create_experiment);
    Assert.assertNotNull("The Create-Experiment Button should not be null",
            buttonCreateExperiment);

    TouchUtils.clickView(testCase, buttonCreateExperiment);

    testCase.getInstrumentation().waitForIdleSync();

    activity = testCase.getInstrumentation().waitForMonitor(activityMonitor);

    testCase.getInstrumentation().removeMonitor(activityMonitor);
    return activity;
}
项目:SensorDataCollector    文件:TestHelper.java   
public static Activity viewMostRecentExperiment(ActivityInstrumentationTestCase2<?> testCase,
        Activity activity) {
    // view the most recent experiment
    Fragment fragment = ((SensorDataCollectorActivity) activity).getSupportFragmentManager()
            .findFragmentById(R.id.fragment_container);
    Assert.assertNotNull("The Sensor List Fragment should not be null.", fragment);

    ListView listView = ((ListFragment) fragment).getListView();
    Assert.assertNotNull("ListView should not be null.", listView);

    ActivityMonitor monitor = testCase.getInstrumentation().addMonitor(
            ViewExperimentActivity.class.getName(), null, false);
    TouchUtils.clickView(testCase, listView.getChildAt(listView.getHeaderViewsCount()));
    testCase.getInstrumentation().waitForIdleSync();

    ViewExperimentActivity viewExperimentActivity = (ViewExperimentActivity) testCase
            .getInstrumentation().waitForMonitor(monitor);
    Assert.assertTrue("activity should be a ViewExperimentActivity.",
            viewExperimentActivity instanceof ViewExperimentActivity);
    testCase.getInstrumentation().removeMonitor(monitor);

    // clone the experiment
    testCase.getInstrumentation().waitForIdleSync();
    return viewExperimentActivity;
}
项目:SensorDataCollector    文件:TestHelper.java   
public static Activity cloneExperiment(ActivityInstrumentationTestCase2<?> testCase,
        Activity activity) {
    Assert.assertTrue("The acitivty must be a ViewExperimentActivity.",
            activity instanceof ViewExperimentActivity);

    Button buttonCloneExperiment = (Button) activity
            .findViewById(R.id.button_experiment_view_clone);
    Assert.assertNotNull("Button should not be null.", buttonCloneExperiment);

    ActivityMonitor monitor = testCase.getInstrumentation().addMonitor(
            CreateExperimentActivity.class.getName(), null, false);
    TouchUtils.clickView(testCase, buttonCloneExperiment);
    activity = testCase.getInstrumentation().waitForMonitorWithTimeout(monitor, 5000);
    Assert.assertTrue("activity should be CreateExperimentActivity.",
            activity instanceof CreateExperimentActivity);
    testCase.getInstrumentation().removeMonitor(monitor);

    return activity;
}
项目:AndroidMavenDevelopment    文件:BookActivityTest.java   
@SmallTest
public void testClickButton() {
    Spoon.screenshot(bookActivity, "Book_Activity_started");
    ActivityMonitor activityMonitor = getInstrumentation().addMonitor(AuthorActivity.class.getName(), null, false);
    bookActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            button.performClick();
        }
    });

    AuthorActivity authorActivity = (AuthorActivity) getInstrumentation().waitForMonitorWithTimeout(activityMonitor, 5000);
    assertNotNull(authorActivity);
    authorActivity.finish();
    Spoon.screenshot(authorActivity, "Author_Activity_opened");
}
项目:AndroidMavenDevelopment    文件:BookActivityTest.java   
@SmallTest
public void testClickButton() {
    Spoon.screenshot(bookActivity, "Book_Activity_started");
    ActivityMonitor activityMonitor = getInstrumentation().addMonitor(AuthorActivity.class.getName(), null, false);
    bookActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            button.performClick();
        }
    });

    AuthorActivity authorActivity = (AuthorActivity) getInstrumentation().waitForMonitorWithTimeout(activityMonitor, 5000);
    assertNotNull(authorActivity);
    authorActivity.finish();
    Spoon.screenshot(authorActivity, "Author_Activity_opened");
}
项目:AndroidMavenDevelopment    文件:FreeActivityTest.java   
@SmallTest
public void testClickButton() {
    // register next activity that need to be monitored.
    ActivityMonitor activityMonitor = getInstrumentation().addMonitor(AuthorActivity.class.getName(), null, false);

    // open current activity.
    bookActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // click button and open next activity.
            button.performClick();
        }
    });

    AuthorActivity authorActivity = (AuthorActivity) getInstrumentation().waitForMonitorWithTimeout(activityMonitor, 5000);
    // next activity is opened and captured.
    assertNotNull(authorActivity);

    authorActivity.finish();
}
项目:lotsofcodingkitty    文件:UserHomeUITest.java   
/**
 * Testing that when the favorites button is clicked, a new activity pops up.<br>
 * Also tests that the mode sent to that activity (through intent) is the correct
 * one (in this case 0 meaning favorites).
 * 
 */
public void testUserHomeButtonClick() {
    // this tests that if you click on an item a new activity opens up that
    // is ViewQuestion activiy
    ActivityMonitor activityMonitor = getInstrumentation().addMonitor(
            UserListsActivity.class.getName(), null, false);
    assertNotNull("The button is being called and returning a null",activity.findViewById(R.id.user_fav_button));
    getInstrumentation().runOnMainSync(new Runnable() { // clicking on an
                                                        // item
                                                        // automatically
                @Override
                public void run() {
                    ((Button) activity.findViewById(R.id.user_fav_button))
                            .performClick();
                }
            });
    instrumentation.waitForIdleSync();
    UserListsActivity newActivity = (UserListsActivity) instrumentation
            .waitForMonitorWithTimeout(activityMonitor, 5);
    assertNotNull(newActivity); // check that new activity has been opened
    Bundle extras = newActivity.getIntent().getExtras();
    int button_id = extras.getInt("userListMode");
    assertEquals("The button did not send correct information", 0, button_id);
    // viewActivityUItest should be testing that the intent that has been
    // passed to this new activity is correct
}
项目:UK-Weather-repo    文件:MainActivityFunctionalTest.java   
@MediumTest
public void testStartActivity_CityManagementActivity() {
    ActivityMonitor activityMonitor = instrumentation.addMonitor(
            CityManagementActivity.class.getName(), null, false);
    instrumentation.invokeMenuActionSync(mainActivity,
            com.haringeymobile.ukweather.R.id.mi_city_management, 0);
    CityManagementActivity cityManagementActivity = (CityManagementActivity) instrumentation
            .waitForMonitorWithTimeout(activityMonitor,
                    ACTIVITY_MONITOR_TIMEOUT);

    assertNotNull("The started CityManagementActivity is null",
            cityManagementActivity);
    assertTrue("Monitor for CityManagementActivity has not been called",
            instrumentation.checkMonitorHit(activityMonitor, 1));

    instrumentation.removeMonitor(activityMonitor);
    cityManagementActivity.finish();
}
项目:UK-Weather-repo    文件:MainActivityFunctionalTest.java   
@MediumTest
public void testStartActivity_SettingsActivity() {
    @SuppressWarnings("rawtypes")
    Class settingsClass = GlobalConstants.IS_BUILD_VERSION_AT_LEAST_HONEYCOMB_11 ? SettingsActivity.class
            : SettingsActivityPreHoneycomb.class;
    ActivityMonitor activityMonitor = instrumentation.addMonitor(
            settingsClass.getName(), null, false);
    instrumentation.invokeMenuActionSync(mainActivity,
            com.haringeymobile.ukweather.R.id.mi_settings, 0);
    Activity settingsActivity = instrumentation.waitForMonitorWithTimeout(
            activityMonitor, ACTIVITY_MONITOR_TIMEOUT);

    assertNotNull("The started settings activity is null", settingsActivity);
    assertTrue("Monitor for settings activity has not been called",
            instrumentation.checkMonitorHit(activityMonitor, 1));

    instrumentation.removeMonitor(activityMonitor);
    settingsActivity.finish();
}
项目:UK-Weather-repo    文件:MainActivityFunctionalTest.java   
@MediumTest
public void testStartActivity_AboutActivity() {
    ActivityMonitor activityMonitor = instrumentation.addMonitor(
            AboutActivity.class.getName(), null, false);
    instrumentation.invokeMenuActionSync(mainActivity,
            com.haringeymobile.ukweather.R.id.mi_about, 0);
    AboutActivity aboutActivity = (AboutActivity) instrumentation
            .waitForMonitorWithTimeout(activityMonitor,
                    ACTIVITY_MONITOR_TIMEOUT);

    assertNotNull("The started AboutActivity is null", aboutActivity);
    assertTrue("Monitor for AboutActivity has not been called",
            instrumentation.checkMonitorHit(activityMonitor, 1));

    instrumentation.removeMonitor(activityMonitor);
    aboutActivity.finish();
}
项目:Android-Application-Using-CAF-Library    文件:TestPlaylist.java   
/**
 *  Start the trackBrowserActivity and add the new playlist
 */
public void addNewPlaylist(String playListName) throws Exception{
    Instrumentation inst = getInstrumentation();
    Activity trackBrowserActivity;
    ActivityMonitor trackBrowserMon = inst.addMonitor("com.android.music.TrackBrowserActivity", 
            null, false);
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_PICK);
    intent.setClassName("com.android.music", "com.android.music.TrackBrowserActivity");
    getActivity().startActivity(intent);     
    Thread.sleep(MusicPlayerNames.WAIT_LONG_TIME);
    trackBrowserActivity = trackBrowserMon.waitForActivityWithTimeout(2000);
    inst.invokeContextMenuAction(trackBrowserActivity, MusicUtils.Defs.NEW_PLAYLIST, 0);
    Thread.sleep(MusicPlayerNames.WAIT_SHORT_TIME);
    //Remove the default playlist name
    clearSearchString(MusicPlayerNames.DEFAULT_PLAYLIST_LENGTH);
    inst.sendStringSync(playListName);
    inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
    inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
    Thread.sleep(MusicPlayerNames.WAIT_LONG_TIME);
    trackBrowserActivity.finish();
    clearSearchString(playListName.length());

}
项目:ChooseYourAdventure    文件:TestViewStoriesActivity.java   
public void testClick() {

        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                activity.refresh();
                listView.performItemClick(listView.getAdapter().getView(0, null, null),
                        0,
                        listView.getAdapter().getItemId(0));
            }
        });


        //Wait for the view page activity to start
        ActivityMonitor monitor = new ActivityMonitor(ViewPageActivity.class.getName(), null, false);
        getInstrumentation().addMonitor(monitor);
        Activity nextActivity = monitor.waitForActivityWithTimeout(5 * 1000);
        assertNotNull("Activity was not started", nextActivity);

        //Verify state properly set
        assertTrue(((ApplicationController)activity.getApplication()).getStoryController().getStory() == testStory);
        //assertTrue(((ApplicationController)activity.getApplication()).getS.getPage() == testPage);

        nextActivity.finish();
    }
项目:Inside_Android_Testing    文件:MainActivityTest.java   
public void testLaunchActivity() {
    //register next activity that need to be monitored
    ActivityMonitor activityMonitor = getInstrumentation().addMonitor(OtherActivity.class.getName(), null, false);

    //open current activity
    final Button button = (Button)mainActivity.findViewById(R.id.bt_launch);
    mainActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            button.performClick();
        }
    });

    // let's wait to open the activity
    OtherActivity otherActivity = (OtherActivity)getInstrumentation().waitForMonitor(activityMonitor);

    // next activity is opened and captured.
    assertNotNull(otherActivity);
    otherActivity.finish();
}
项目:sagesmobile-mReceive    文件:FormCreatorTest.java   
@UiThreadTest   
public void testOnMenuOptions(){
    mFormName.setText("Living");
    mPrefix.setText("Live");
    mDescription.setText("This is a living test");

        try{

            ActivityMonitor am = getInstrumentation().addMonitor(AddField.class.getName(), null, false);

        // Click the menu option
        getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
        getInstrumentation().getContext();
        getInstrumentation().invokeMenuActionSync(mActivity, 3, 0);

        Activity a = getInstrumentation().waitForMonitorWithTimeout(am, 1000);
        assertEquals(true, getInstrumentation().checkMonitorHit(am, 1));
        a.finish();
        }catch(Exception e){Log.e("testOnMenuOptions, Activity start:", e.getMessage().toString());}

    }
项目:wva_sample    文件:DashboardActivityTest.java   
public void testChartLaunch() {
    ActivityMonitor am = getInstrumentation().addMonitor(ChartActivity.class.getName(), null, false);
    Log.d("DashboardActivityTest", "Invoking Chart launch");
    getInstrumentation().invokeMenuActionSync(getActivity(), R.id.launch_chart, 0);
    Activity activity = getInstrumentation().waitForMonitorWithTimeout(am, 5000);
    assertTrue("Chart activity not launched!", getInstrumentation().checkMonitorHit(am, 1));

       if (activity != null)
        activity.finish();
    try {
        // Seems like the code below gets called before onDestroy changes
        // propagate through the system if no delay like this is introduced.
        Thread.sleep(500);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
项目:test_agent_android    文件:Waiter.java   
/**
 * Removes the AcitivityMonitor
 * 
 * @param activityMonitor the ActivityMonitor to remove
 */

private void removeMonitor(ActivityMonitor activityMonitor){
    try{
        instrumentation.removeMonitor(activityMonitor); 
    }catch (Exception ignored) {}
}
项目:test_agent_android    文件:Solo.java   
/**
 * Returns the ActivityMonitor used by Robotium.
 *
 * @return the ActivityMonitor used by Robotium
 */

public ActivityMonitor getActivityMonitor(){
    if(config.commandLogging){
        Log.d(config.commandLoggingTag, "getActivityMonitor()");
    }

    return activityUtils.getActivityMonitor();
}
项目:welcome-android    文件:WelcomeScreenHelperAndroidTest.java   
@Test
public void testForceShow() {
    ActivityMonitor monitor = new ActivityMonitor(DefaultWelcomeActivity.class.getName(), null, false);
    instrumentation.addMonitor(monitor);

    helper.forceShow();

    Activity welcomeActivity = instrumentation.waitForMonitor(monitor);

    assertNotNull(welcomeActivity);
}
项目:TravelTracker    文件:ClaimsListActivityTest.java   
public void testEditExpenseClaim() throws Throwable {
    final ClaimsListActivity activity = startActivity(new UserData(user2.getUUID(), user2.getUserName(), UserRole.CLAIMANT));
    ActivityMonitor monitor = getInstrumentation().addMonitor(ClaimInfoActivity.class.getName(), null, false);
    final ListView listView = (ListView) activity.findViewById(R.id.claimsListClaimListView);
    @SuppressWarnings("unchecked")
    final ArrayAdapter<Claim> adapter = (ArrayAdapter<Claim>) listView.getAdapter();
    final int position = 0;

    runTestOnUiThread(new Runnable()
    {

        @Override
        public void run()
        {

            boolean success = listView.performItemClick(adapter.getView(position, null, null), position, adapter.getItemId(position));
            assertTrue(success);

        }
    });

    Activity newActivity = monitor.waitForActivityWithTimeout(3000);
    assertNotNull(newActivity);
    validateIntent(user2, adapter.getItem(position), newActivity);
    newActivity.finish();
    getInstrumentation().waitForIdleSync();


}
项目:TravelTracker    文件:ClaimsListActivityTest.java   
public void testViewExpenseClaimApprover() throws Throwable {
    claim1.setStatus(Status.SUBMITTED);
    final ClaimsListActivity activity = startActivity(new UserData(user2.getUUID(), user2.getUserName(), UserRole.APPROVER));
    ActivityMonitor monitor = getInstrumentation().addMonitor(ClaimInfoActivity.class.getName(), null, false);
    final ListView listView = (ListView) activity.findViewById(R.id.claimsListClaimListView);
    @SuppressWarnings("unchecked")
    final ArrayAdapter<Claim> adapter = (ArrayAdapter<Claim>) listView.getAdapter();

    assertEquals("Should only be 1 submitted claim", 1, listView.getCount());


    runTestOnUiThread(new Runnable()
    {

        @Override
        public void run()
        {
            int position = 0;
            boolean success = listView.performItemClick(adapter.getView(position, null, null), position, adapter.getItemId(position));
            assertTrue(success);

        }
    });

    Activity newActivity = monitor.waitForActivityWithTimeout(3000);
    assertNotNull(newActivity);
    validateIntent(user2, claim1, newActivity);
    newActivity.finish();
    getInstrumentation().waitForIdleSync();
    assertEquals("Count should not have changed", 1, listView.getCount());
}
项目:TravelTracker    文件:LoginActivityTest.java   
/**
 * Log in with the given details.
 * @param name The name to use.
 * @param role The role to use.
 * @return The intent passed to the activity (or null if no activity).
 * @throws InterruptedException 
 */
public Intent loginWithDetails(final String name, final UserRole role) throws InterruptedException {
    ActivityMonitor monitor = instrumentation.addMonitor(ClaimsListActivity.class.getName(), null, false);

    Runnable action = new Runnable() {
        @Override
        public void run() {
            nameEditText.setText(name);

            switch (role) {
            case APPROVER:
                approverButton.performClick();
                break;

            case CLAIMANT:
                claimantButton.performClick();
                break;
            }
            loginButton.performClick();
        }
    };

    instrumentation.runOnMainSync(action);
    final Activity newActivity = monitor.waitForActivityWithTimeout(3000);

    if (newActivity == null) {
        return null;
    }

    Intent intent = newActivity.getIntent();

    // Wait to finish
    newActivity.finish();
    instrumentation.waitForIdleSync();

    // This is a stupid hack, but Android sometimes fails to back out in time
    Thread.sleep(100);

    return intent;
}
项目:robotium-tech    文件:Waiter.java   
/**
 * Removes the AcitivityMonitor
 * 
 * @param activityMonitor the ActivityMonitor to remove
 */

private void removeMonitor(ActivityMonitor activityMonitor){
    try{
        instrumentation.removeMonitor(activityMonitor); 
    }catch (Exception ignored) {}
}
项目:robotium-tech    文件:Solo.java   
/**
 * Returns the ActivityMonitor used by Robotium.
 *
 * @return the ActivityMonitor used by Robotium
 */

public ActivityMonitor getActivityMonitor(){
    if(config.commandLogging){
        Log.d(config.commandLoggingTag, "getActivityMonitor()");
    }

    return activityUtils.getActivityMonitor();
}
项目:Office-365-SDK-for-Android    文件:AbstractTest.java   
private void prepare() {
    wasStarted = true;

    // Sets field name for reflection to work with various android version.
    if (android.os.Build.VERSION.SDK_INT >= 17) {
        windowManagerString = "sDefaultWindowManager";
    } else if (android.os.Build.VERSION.SDK_INT >= 13) {
        windowManagerString = "sWindowManager";
    } else {
        windowManagerString = "mWindowManager";
    }

    // Prepare reflection specific window manager for various android version.
    String windowManagerClassName;
    if (android.os.Build.VERSION.SDK_INT >= 17) {
        windowManagerClassName = "android.view.WindowManagerGlobal";
    } else {
        windowManagerClassName = "android.view.WindowManagerImpl";
    }
    try {
        windowManager = Class.forName(windowManagerClassName);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Set up odata clients.
    v3Client = ODataClientFactory.getV3();
    v4Client = ODataClientFactory.getV4();

    // Initialize activity monitor.
    activityMonitor = new ActivityMonitor((IntentFilter) null, null, false);
    getInstrumentation().addMonitor(activityMonitor);

    // Start and check main test activity.
    mainActivity = getActivity();
    assertNotNull(mainActivity);
}
项目:SensorDataCollector    文件:TestHelper.java   
public static Activity stopExperiment(ActivityInstrumentationTestCase2<?> testCase,
        Activity activity) {
    Assert.assertTrue("The activity must be a CreateExperimentActivity.",
            activity instanceof CreateExperimentActivity);

    Fragment fragment = ((CreateExperimentActivity) activity).getSupportFragmentManager()
            .findFragmentById(
                    R.id.fragment_container);
    Assert.assertNotNull("The ExperimentRunFragment should not be null.", fragment);
    Assert.assertTrue("The fragment should be an ExperimentRunFragment.",
            fragment instanceof ExperimentRunFragment);

    Button buttonExperimentDone = (Button) fragment.getView().findViewById(
            R.id.button_experiment_done);
    Assert.assertNotNull("The Experiment-Done button shoud not be null.", buttonExperimentDone);

    TouchUtils.clickView(testCase, buttonExperimentDone);
    testCase.getInstrumentation().waitForIdleSync();

    AlertDialog dialog = ((CreateExperimentActivity) activity).getAlertDialog();
    Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);

    ActivityMonitor monitor = testCase.getInstrumentation().addMonitor(
            SensorDataCollectorActivity.class.getName(), null, false);

    TouchUtils.clickView(testCase, positiveButton);
    testCase.getInstrumentation().waitForIdleSync();

    SensorDataCollectorActivity sensorDataCollectorActivity =
            (SensorDataCollectorActivity) testCase.getInstrumentation().waitForMonitor(monitor);
    testCase.getInstrumentation().removeMonitor(monitor);
    Assert.assertNotNull("SensorDataCollector Activity was not loaded",
            sensorDataCollectorActivity);

    return sensorDataCollectorActivity;
}
项目:AndroidMavenDevelopment    文件:BookActivityTest.java   
@SmallTest
public void testClickButton() {
    ActivityMonitor activityMonitor = getInstrumentation().addMonitor(AuthorActivity.class.getName(), null, false);
    bookActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            button.performClick();
        }
    });

    AuthorActivity authorActivity = (AuthorActivity) getInstrumentation().waitForMonitorWithTimeout(activityMonitor, 5000);
    assertNotNull(authorActivity);
    authorActivity.finish();
}
项目:AndroidMavenDevelopment    文件:BookActivityTest.java   
@SmallTest
public void testClickButton() {
    ActivityMonitor activityMonitor = getInstrumentation().addMonitor(AuthorActivity.class.getName(), null, false);
    bookActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            button.performClick();
        }
    });

    AuthorActivity authorActivity = (AuthorActivity) getInstrumentation().waitForMonitorWithTimeout(activityMonitor, 5000);
    assertNotNull(authorActivity);
    authorActivity.finish();
}