3939import com .microsoft .identity .client .ui .automation .utils .UiAutomatorUtils ;
4040import com .microsoft .identity .common .java .commands .webapps .WebAppsGetTokenSubOperationResponse ;
4141import com .microsoft .identity .common .java .util .ObjectMapper ;
42+ import com .microsoft .identity .common .java .util .ThreadUtils ;
4243import com .microsoft .identity .labapi .utilities .client .ILabAccount ;
4344import com .microsoft .identity .labapi .utilities .client .LabQuery ;
4445import com .microsoft .identity .labapi .utilities .constants .AzureEnvironment ;
4950import org .junit .Test ;
5051
5152// WebApps API Tests via BrokerHost Broker API tab
52- // Tests GetToken (interactive and silent), GetCookies, and SignOut operations
53- // of the WebApps APIs using the BrokerHost app's Broker API tab .
53+ // Tests GetToken (interactive and silent) and SignOut operations of the WebApps APIs using the BrokerHost app's Broker API tab.
54+ // GetAllSsoTokens is also tested here .
5455// https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3571739
5556@ SupportedBrokers (brokers = BrokerHost .class )
5657@ LocalBrokerHostDebugUiTest
@@ -68,14 +69,13 @@ public class TestCase3571739 extends AbstractMsalBrokerTest {
6869 private static final String CHECKBOX_IS_STS = BROKER_HOST_PKG + ":id/checkbox_is_sts" ;
6970 private static final String BUTTON_EXECUTE_GET_TOKEN = BROKER_HOST_PKG + ":id/button_execute_get_token" ;
7071 private static final String BUTTON_EXECUTE_SIGN_OUT = BROKER_HOST_PKG + ":id/button_execute_sign_out" ;
71- private static final String EDIT_TEXT_COOKIES_URL = BROKER_HOST_PKG + ":id/edit_text_webapps_cookie_url " ;
72- private static final String BUTTON_GET_COOKIES = BROKER_HOST_PKG + ":id/button_get_webapp_cookies " ;
72+ private static final String BUTTON_GET_ALL_SSO_TOKENS = BROKER_HOST_PKG + ":id/button_get_sso_tokens " ;
73+ private static final String TEXT_GET_ALL_SSO_TOKENS = BROKER_HOST_PKG + ":id/edit_sso_token " ;
7374 private static final String DIALOG_MESSAGE = "android:id/message" ;
7475 private static final String DIALOG_OK_BUTTON = "android:id/button1" ;
7576
7677 // Constants
7778 private static final String LEMON_GLACIER = "https://lemon-glacier-0fa89f11e.1.azurestaticapps.net/" ;
78- private static final String MICROSOFT_ONLINE = "https://login.microsoftonline.com" ;
7979 private static final String SCOPE = "User.Read" ;
8080 private static final String ACCESS_TOKEN_DESCRIPTION = "access_token" ;
8181 private static final long DIALOG_WAIT_TIMEOUT_MS = 5000L ;
@@ -197,22 +197,37 @@ public void test_3571739_webAppsOperations() throws Throwable {
197197 silentMsalJsResult .contains (ACCESS_TOKEN_DESCRIPTION )
198198 );
199199
200- // -------- Step 3: GetCookies --------
200+ // -------- Step 3: GetAllSsoTokens --------
201201 // Navigate to the Broker API tab
202202 brokerHost .brokerApiFragment .launch ();
203203
204- // Scroll down to make the cookies URL field and button visible
205- new UiScrollable (new UiSelector ().scrollable (true )).scrollIntoView (new UiSelector ().resourceId (BUTTON_GET_COOKIES ));
204+ // Scroll down to make the GetAllSsoTokens button visible
205+ new UiScrollable (new UiSelector ().scrollable (true )).scrollIntoView (new UiSelector ().resourceId (BUTTON_GET_ALL_SSO_TOKENS ));
206+ UiAutomatorUtils .handleButtonClick (BUTTON_GET_ALL_SSO_TOKENS );
206207
207- UiAutomatorUtils .handleInput (EDIT_TEXT_COOKIES_URL , MICROSOFT_ONLINE );
208- UiAutomatorUtils .handleButtonClick (BUTTON_GET_COOKIES );
209-
210- final String cookiesResult = dismissDialogAndGetText ();
208+ // The result is shown in the textbox next to the button (not a dialog)
209+ final UiObject allSsoTokensResultView = UiAutomatorUtils .obtainUiObjectWithResourceId (TEXT_GET_ALL_SSO_TOKENS );
210+ Assert .assertTrue (
211+ "GetAllSsoTokens result text view should be present" ,
212+ allSsoTokensResultView .waitForExists (DIALOG_WAIT_TIMEOUT_MS )
213+ );
214+ String allSsoTokensResult = "" ;
215+ final long waitUntil = System .currentTimeMillis () + DIALOG_WAIT_TIMEOUT_MS ;
216+ while (allSsoTokensResult .isEmpty () && System .currentTimeMillis () < waitUntil ) {
217+ try {
218+ allSsoTokensResult = allSsoTokensResultView .getText ();
219+ } catch (final UiObjectNotFoundException e ) {
220+ throw new AssertionError ("Could not read GetAllSsoTokens result text" , e );
221+ }
222+ if (allSsoTokensResult .isEmpty ()) {
223+ ThreadUtils .sleepSafely (250 , "Waiting for GetAllSsoTokens result text" , "Interrupted" );
224+ }
225+ }
211226
212- Assert .assertNotNull ("GetCookies result should not be null" , cookiesResult );
227+ Assert .assertNotNull ("GetAllSsoTokens result should not be null" , allSsoTokensResult );
213228 Assert .assertFalse (
214- "GetCookies result should not be empty" ,
215- cookiesResult .isEmpty ()
229+ "GetAllSsoTokens result should not be empty" ,
230+ allSsoTokensResult .isEmpty ()
216231 );
217232
218233 // -------- Step 4: SignOut --------
0 commit comments