public Activity waitForNextActivity(String methodExt, long timeOut) throws InterruptedException { Activity nextActivity = mInstrumentation.waitForMonitorWithTimeout(activityMonitor, timeOut); MyLog.v(methodExt, "After waitForMonitor: " + nextActivity); assertNotNull("Next activity is opened and captured", nextActivity); TestSuite.waitForListLoaded(mInstrumentation, nextActivity, 2); activityMonitor = null; return nextActivity; }
@Override protected void setUp() throws Exception { super.setUp(); TestSuite.initializeWithData(this); Intent intent = new Intent(); intent.putExtra(HelpActivity.EXTRA_IS_FIRST_ACTIVITY, true); intent.putExtra(HelpActivity.EXTRA_HELP_PAGE_INDEX, HelpActivity.PAGE_INDEX_CHANGELOG); setActivityIntent(intent); }
@Override protected void setUp() throws Exception { super.setUp(); MyLog.i(this, "setUp started"); TestSuite.initializeWithData(this); ma = MyContextHolder.get() .persistentAccounts() .fromAccountName(TestSuite.GNUSOCIAL_TEST_ACCOUNT_NAME); assertTrue(TestSuite.GNUSOCIAL_TEST_ACCOUNT_NAME + " exists", ma.isValid()); }
/** @return success */ public boolean invokeContextMenuAction4ListItemId( String methodExt, long listItemId, ContextMenuItem menuItem) throws InterruptedException { final String method = "invokeContextMenuAction4ListItemId"; boolean success = false; long id2 = listItemId; String msg = ""; for (long attempt = 1; attempt < 4; attempt++) { TestSuite.waitForIdleSync(mInstrumentation); int position = getPositionOfListItemId(listItemId); msg = "listItemId=" + listItemId + "; menu Item=" + menuItem + "; position=" + position + "; attempt=" + attempt; MyLog.v(this, msg); if (getListItemIdAtPosition(position) == listItemId) { selectListPosition(methodExt, position); if (invokeContextMenuAction(methodExt, mActivity, position, menuItem.getId())) { id2 = getListItemIdAtPosition(position); if (id2 == listItemId) { success = true; break; } else { MyLog.i( methodExt, method + "; Position changed, now pointing to listItemId=" + id2 + "; " + msg); } } } ; } MyLog.v(methodExt, method + " ended " + success + "; " + msg); TestSuite.waitForIdleSync(mInstrumentation); return success; }
private void longClickAtPosition(final String methodExt, final int position) throws InterruptedException { final View view = getListView().getChildAt(position); assertTrue("View at list position " + position + " exists", view != null); mInstrumentation.runOnMainSync( new Runnable() { @Override public void run() { MyLog.v(methodExt, "performLongClick on " + view + " at position " + position); view.performLongClick(); } }); TestSuite.waitForIdleSync(mInstrumentation); }
@Override protected void setUp() throws Exception { super.setUp(); MyLog.i(this, "setUp started"); TestSuite.initializeWithData(this); ma = MyContextHolder.get() .persistentAccounts() .fromAccountName(TestSuite.CONVERSATION_ACCOUNT_NAME); assertTrue(ma.isValid()); selectedMessageId = MyQuery.oidToId( OidEnum.MSG_OID, ma.getOriginId(), TestSuite.CONVERSATION_ENTRY_MESSAGE_OID); assertTrue("Selected message exists", selectedMessageId != 0); MyLog.i(this, "setUp ended"); }
public void clickView(final String methodExt, final View view) throws InterruptedException { assertTrue(view != null); Runnable clicker = new Runnable() { @Override public void run() { MyLog.v(methodExt, "Before click view"); view.performClick(); } }; mInstrumentation.runOnMainSync(clicker); MyLog.v(methodExt, "After click view"); TestSuite.waitForIdleSync(mInstrumentation); }
@Override protected void setUp() throws Exception { super.setUp(); TestSuite.initializeWithData(this); iteration = (iteration >= 4 ? 1 : iteration + 1); switch (iteration) { case 2: showAttachedImages = showAttachedImagesOld; showAvatars = !showAvatarsOld; break; case 3: showAttachedImages = !showAttachedImagesOld; showAvatars = showAvatarsOld; break; case 4: showAttachedImages = !showAttachedImagesOld; showAvatars = !showAvatarsOld; break; default: showAttachedImagesOld = MyPreferences.showAttachedImages(); showAvatarsOld = MyPreferences.showAvatars(); showAttachedImages = showAttachedImagesOld; showAvatars = showAvatarsOld; break; } setPreferences(); MyLog.setLogToFile(true); logStartStop("setUp started"); MyAccount ma = MyContextHolder.get() .persistentAccounts() .fromAccountName(TestSuite.CONVERSATION_ACCOUNT_NAME); assertTrue(ma.isValid()); MyContextHolder.get().persistentAccounts().setCurrentAccount(ma); Intent intent = new Intent( Intent.ACTION_VIEW, MatchedUri.getTimelineUri(ma.getUserId(), TimelineType.HOME, false, 0)); setActivityIntent(intent); activity = getActivity(); assertTrue("MyService is available", MyServiceManager.isServiceAvailable()); logStartStop("setUp ended"); }
public void clickListAtPosition(final String methodExt, final int position) throws InterruptedException { final String method = "clickListAtPosition"; mInstrumentation.runOnMainSync( new Runnable() { // See // http://stackoverflow.com/questions/8094268/android-listview-performitemclick @Override public void run() { long listItemId = mActivity.getListAdapter().getItemId(position); MyLog.v(methodExt, method + "; on performClick, listItemId=" + listItemId); getListView() .performItemClick( getListView().getAdapter().getView(position, null, null), position, listItemId); } }); MyLog.v(methodExt, method + " ended"); TestSuite.waitForIdleSync(mInstrumentation); }
/** * InstrumentationTestCase.getInstrumentation().invokeContextMenuAction doesn't work properly * * @return success * <p>Note: This method cannot be invoked on the main thread. See * https://github.com/google/google-authenticator-android/blob/master/tests/src/com/google/android/apps/authenticator/TestUtilities.java */ private boolean invokeContextMenuAction( final String methodExt, final MyListActivity activity, int position, final int menuItemId) throws InterruptedException { final String method = "invokeContextMenuAction"; MyLog.v( methodExt, method + " started on menuItemId=" + menuItemId + " at position=" + position); boolean success = false; int position1 = position; for (long attempt = 1; attempt < 4; attempt++) { longClickAtPosition(methodExt, position1); if (mActivity.getPositionOfContextMenu() == position) { success = true; break; } MyLog.i( methodExt, method + "; Context menu created for position " + mActivity.getPositionOfContextMenu() + " instead of " + position + "; was set to " + position1 + "; attempt " + attempt); position1 = position + (position1 - mActivity.getPositionOfContextMenu()); } if (success) { mInstrumentation.runOnMainSync( new Runnable() { @Override public void run() { MyLog.v(methodExt, method + "; before performContextMenuIdentifierAction"); activity.getWindow().performContextMenuIdentifierAction(menuItemId, 0); } }); TestSuite.waitForIdleSync(mInstrumentation); } MyLog.v(methodExt, method + " ended " + success); return success; }
public void selectListPosition(final String methodExt, final int positionIn) throws InterruptedException { final String method = "selectListPosition"; MyLog.v(methodExt, method + " started; position=" + positionIn); mInstrumentation.runOnMainSync( new Runnable() { @Override public void run() { int position = positionIn; ListAdapter la = getListView().getAdapter(); if (la.getCount() <= position) { position = la.getCount() - 1; } MyLog.v( methodExt, method + " on setSelection " + position + " of " + (la.getCount() - 1)); getListView().setSelectionFromTop(position, 0); } }); TestSuite.waitForIdleSync(mInstrumentation); MyLog.v(methodExt, method + " ended"); }
private void oneIteration() throws InterruptedException { TestSuite.waitForListLoaded(this, activity, 3); }