当前位置: 首页>>代码示例>>Java>>正文


Java ActivityMonitor.waitForActivityWithTimeout方法代码示例

本文整理汇总了Java中android.app.Instrumentation.ActivityMonitor.waitForActivityWithTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java ActivityMonitor.waitForActivityWithTimeout方法的具体用法?Java ActivityMonitor.waitForActivityWithTimeout怎么用?Java ActivityMonitor.waitForActivityWithTimeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.Instrumentation.ActivityMonitor的用法示例。


在下文中一共展示了ActivityMonitor.waitForActivityWithTimeout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: waitForActivity

import android.app.Instrumentation.ActivityMonitor; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:IfengAutomation,项目名称:test_agent_android,代码行数:32,代码来源:Waiter.java

示例2: testOnCreateWithVerifiedUserData

import android.app.Instrumentation.ActivityMonitor; //导入方法依赖的package包/类
public void testOnCreateWithVerifiedUserData() throws Exception {
	Context context = getInstrumentation().getTargetContext();
	identifier = "[email protected]";
	userData.setIsVerified(true);

	StorageHelper.PreferencesHelper.setIdentifier(context, identifier);
	StorageHelper.PreferencesHelper.setUserData(context, identifier,
			userData);

	// 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();

	assertNotNull(welcomeActivity);
}
 
开发者ID:cherrymathew,项目名称:evend,代码行数:24,代码来源:StartupActivityFunctionalTest.java

示例3: testOnCreateWithUnverifiedUserData

import android.app.Instrumentation.ActivityMonitor; //导入方法依赖的package包/类
public void testOnCreateWithUnverifiedUserData() throws Exception {
	Context context = getInstrumentation().getTargetContext();
	identifier = "[email protected]";
	userData.setIsVerified(false);

	StorageHelper.PreferencesHelper.setIdentifier(context, identifier);
	StorageHelper.PreferencesHelper.setUserData(context, identifier,
			userData);

	// 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);
}
 
开发者ID:cherrymathew,项目名称:evend,代码行数:24,代码来源:StartupActivityFunctionalTest.java

示例4: testOnCreateWithNoUserData

import android.app.Instrumentation.ActivityMonitor; //导入方法依赖的package包/类
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);
}
 
开发者ID:cherrymathew,项目名称:evend,代码行数:21,代码来源:StartupActivityFunctionalTest.java

示例5: testViewExpenseItems

import android.app.Instrumentation.ActivityMonitor; //导入方法依赖的package包/类
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);
}
 
开发者ID:TravelTracker,项目名称:TravelTracker,代码行数:24,代码来源:ClaimInfoActivityTest.java

示例6: testCreateExpenseClaim

import android.app.Instrumentation.ActivityMonitor; //导入方法依赖的package包/类
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());

}
 
开发者ID:TravelTracker,项目名称:TravelTracker,代码行数:19,代码来源:ClaimsListActivityTest.java

示例7: testViewExpenseClaimApprover

import android.app.Instrumentation.ActivityMonitor; //导入方法依赖的package包/类
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());
}
 
开发者ID:TravelTracker,项目名称:TravelTracker,代码行数:32,代码来源:ClaimsListActivityTest.java

示例8: addNewPlaylist

import android.app.Instrumentation.ActivityMonitor; //导入方法依赖的package包/类
/**
 *  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());

}
 
开发者ID:AndroidLearnerchn,项目名称:Android-Application-Using-CAF-Library,代码行数:27,代码来源:TestPlaylist.java

示例9: testClick

import android.app.Instrumentation.ActivityMonitor; //导入方法依赖的package包/类
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();
	}
 
开发者ID:CMPUT301F13T02,项目名称:ChooseYourAdventure,代码行数:26,代码来源:TestViewStoriesActivity.java

示例10: testEditExpenseClaim

import android.app.Instrumentation.ActivityMonitor; //导入方法依赖的package包/类
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();
    
    
}
 
开发者ID:TravelTracker,项目名称:TravelTracker,代码行数:30,代码来源:ClaimsListActivityTest.java

示例11: loginWithDetails

import android.app.Instrumentation.ActivityMonitor; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:TravelTracker,项目名称:TravelTracker,代码行数:47,代码来源:LoginActivityTest.java

示例12: testPlayAllSongs

import android.app.Instrumentation.ActivityMonitor; //导入方法依赖的package包/类
@LargeTest
public void testPlayAllSongs() {
  Activity mediaPlaybackActivity;
  try{
    Instrumentation inst = getInstrumentation();
    ActivityMonitor mediaPlaybackMon = inst.addMonitor("com.android.music.MediaPlaybackActivity", 
      null, false);
    inst.invokeMenuActionSync(getActivity(), MusicUtils.Defs.CHILD_MENU_BASE + 3, 0);
    Thread.sleep(MusicPlayerNames.WAIT_LONG_TIME);
    mediaPlaybackActivity = mediaPlaybackMon.waitForActivityWithTimeout(2000);
    for (int i=0;i< MusicPlayerNames.NO_SKIPPING_SONGS;i++){               
      Thread.sleep(MusicPlayerNames.SKIP_WAIT_TIME);
      if (i==0){
        //Set the repeat all
        inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_RIGHT);
        inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
        inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
 
        //Set focus on the next button
        inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
      }
      inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);      
    }   
    mediaPlaybackActivity.finish();
  }catch (Exception e){
    Log.e(TAG, e.toString());
  }
  //Verification: check if it is in low memory
  ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
  ((ActivityManager)getActivity().getSystemService(Context.ACTIVITY_SERVICE)).getMemoryInfo(mi);
  assertFalse(TAG, mi.lowMemory);      
}
 
开发者ID:AndroidLearnerchn,项目名称:Android-Application-Using-CAF-Library,代码行数:33,代码来源:MusicPlaybackStress.java

示例13: testEdit

import android.app.Instrumentation.ActivityMonitor; //导入方法依赖的package包/类
public void testEdit() {

		Solo solo = new Solo(getInstrumentation(), activity);
		getInstrumentation().waitForIdleSync();

		activity.runOnUiThread(new Runnable() {
			@Override
			public void run() {
				activity.refresh();
				activity.onLongListItemClick(null, 0, 0);
			}
		});

		//Find pop-up, click edit
		assertTrue("Couldn't find dialog", solo.searchText("Edit"));
		solo.clickOnText("Edit");

		//Wait for edit story activity to start
		ActivityMonitor monitor = new ActivityMonitor(EditStoryActivity.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);

		nextActivity.finish();
	}
 
开发者ID:CMPUT301F13T02,项目名称:ChooseYourAdventure,代码行数:29,代码来源:TestViewStoriesActivity.java

示例14: testAddNew

import android.app.Instrumentation.ActivityMonitor; //导入方法依赖的package包/类
public void testAddNew() {

		Solo solo = new Solo(getInstrumentation(), activity);
		getInstrumentation().waitForIdleSync();

		activity.runOnUiThread(new Runnable() {
			@Override
			public void run() {
				addNewButton.performClick();
			}
		});

		//Find dialog, and create a new story
		assertTrue("Couldn't find dialog", solo.searchText("Create New"));
		solo.enterText(0, "Test Story -- SOLO");
		solo.clickOnButton("Save");

		//Wait for Edit Story Activity to start
		ActivityMonitor monitor = new ActivityMonitor(EditStoryActivity.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().getTitle().equals("Test Story -- SOLO"));

		nextActivity.finish();
	}
 
开发者ID:CMPUT301F13T02,项目名称:ChooseYourAdventure,代码行数:29,代码来源:TestViewStoriesActivity.java

示例15: getInstrumentation

import android.app.Instrumentation.ActivityMonitor; //导入方法依赖的package包/类
public void test点击链接() {
	final Instrumentation inst = getInstrumentation();
	IntentFilter intentFilter = new IntentFilter(Intent.ACTION_VIEW);
	intentFilter.addDataScheme("http");
	intentFilter.addCategory(Intent.CATEGORY_BROWSABLE);
	View link = this.getActivity().findViewById(R.id.link);
	ActivityMonitor monitor = inst.addMonitor(
			intentFilter, null, false);
	assertEquals(0, monitor.getHits());
	TouchUtils.clickView(this, link);
	monitor.waitForActivityWithTimeout(5000);
	assertEquals(1, monitor.getHits());
	inst.removeMonitor(monitor);
}
 
开发者ID:shiyimin,项目名称:androidtestdebug,代码行数:15,代码来源:SampleTest.java


注:本文中的android.app.Instrumentation.ActivityMonitor.waitForActivityWithTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。