本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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);
}