Source:
<code>private void handleCredentials(final ActivityMonitor monitor, String username, String password, boolean federated, String federatedPageUrl) throws InterruptedException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException { final TextView textViewStatus = (TextView)activity.findViewById(R.id.textViewStatus); waitUntil(PAGE_LOAD_TIMEOUT, new ResponseVerifier() { @Override public boolean hasCondition() throws IllegalArgumentException, NoSuchFieldException, IllegalAccessException { String tokenMsg = (String)textViewStatus.getText(); return tokenMsg == MainActivity.GETTING_TOKEN; } }); final String startText = textViewStatus.getText().toString(); assertEquals("Token action", MainActivity.GETTING_TOKEN, startText); AuthenticationActivity startedActivity = (AuthenticationActivity)monitor .waitForActivityWithTimeout(ACTIVITY_WAIT_TIMEOUT); assertNotNull(startedActivity); Log.v(TAG, "Sleeping until it gets the login page"); sleepUntilLoginDisplays(startedActivity); Log.v(TAG, "Entering credentials to login page"); enterCredentials(startedActivity, username, password); if (federated) { Log.v(TAG, "Sleep for redirect"); sleepUntilFederatedPageDisplays(federatedPageUrl); Log.v(TAG, "Sleeping until it gets login page"); sleepUntilLoginDisplays(startedActivity); Log.v(TAG, "Entering credentials to login page"); enterCredentials(startedActivity, username, password); } Log.v(TAG, "Wait for the page to set the result"); <START> waitUntil(PAGE_LOAD_TIMEOUT * 3, new ResponseVerifier() { <END> @Override public boolean hasCondition() throws IllegalArgumentException, NoSuchFieldException, IllegalAccessException { String tokenMsg = (String)textViewStatus.getText(); return tokenMsg != startText; } }); if (!startedActivity.isFinishing()) { Log.w(TAG, "AuthenticationActivity was not closed"); startedActivity.finish(); } }</code><technical_language>Consider adding a separate timeout here</technical_language>

Target:
private void handleCredentials(final ActivityMonitor monitor, String username, String password, boolean federated, String federatedPageUrl) throws InterruptedException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException { final TextView textViewStatus = (TextView)activity.findViewById(R.id.textViewStatus); waitUntil(PAGE_LOAD_TIMEOUT, new ResponseVerifier() { @Override public boolean hasCondition() throws IllegalArgumentException, NoSuchFieldException, IllegalAccessException { String tokenMsg = (String)textViewStatus.getText(); return tokenMsg == MainActivity.GETTING_TOKEN; } }); final String startText = textViewStatus.getText().toString(); assertEquals("Token action", MainActivity.GETTING_TOKEN, startText); AuthenticationActivity startedActivity = (AuthenticationActivity)monitor .waitForActivityWithTimeout(ACTIVITY_WAIT_TIMEOUT); assertNotNull(startedActivity); Log.v(TAG, "Sleeping until it gets the login page"); sleepUntilLoginDisplays(startedActivity); Log.v(TAG, "Entering credentials to login page"); enterCredentials(federated, federatedPageUrl, startedActivity, username, password); Log.v(TAG, "Wait for the page to set the result"); waitUntil(PAGE_STATUS_SET_TIME_OUT, new ResponseVerifier() { @Override public boolean hasCondition() throws IllegalArgumentException, NoSuchFieldException, IllegalAccessException { String tokenMsg = (String)textViewStatus.getText(); return tokenMsg != startText; } }); if (!startedActivity.isFinishing()) { Log.w(TAG, "AuthenticationActivity was not closed"); startedActivity.finish(); } }