本文整理汇总了Java中android.app.Instrumentation.ActivityMonitor类的典型用法代码示例。如果您正苦于以下问题:Java ActivityMonitor类的具体用法?Java ActivityMonitor怎么用?Java ActivityMonitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ActivityMonitor类属于android.app.Instrumentation包,在下文中一共展示了ActivityMonitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testShowBasicShareDialog
import android.app.Instrumentation.ActivityMonitor; //导入依赖的package包/类
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());
}
示例2: 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;
}
示例3: testShow
import android.app.Instrumentation.ActivityMonitor; //导入依赖的package包/类
@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));
}
示例4: 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);
}
示例5: 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);
}
示例6: 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);
}
示例7: 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);
}
示例8: 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());
}
示例9: 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());
}
示例10: launchCreateExperimentActivity
import android.app.Instrumentation.ActivityMonitor; //导入依赖的package包/类
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;
}
示例11: viewMostRecentExperiment
import android.app.Instrumentation.ActivityMonitor; //导入依赖的package包/类
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;
}
示例12: cloneExperiment
import android.app.Instrumentation.ActivityMonitor; //导入依赖的package包/类
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;
}
示例13: testClickButton
import android.app.Instrumentation.ActivityMonitor; //导入依赖的package包/类
@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");
}
示例14: testClickButton
import android.app.Instrumentation.ActivityMonitor; //导入依赖的package包/类
@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();
}
示例15: testUserHomeButtonClick
import android.app.Instrumentation.ActivityMonitor; //导入依赖的package包/类
/**
* 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
}