Skip to content

Commit 7a1be91

Browse files
melissaahnCopilotCopilot
authored
Edits to the WebApp UI Automated test, Fixes AB#3624552 (#2521)
### Summary Removing GetCookies and replacing it with GetAllSsoToken (the method which should actually be getting called by Edge). [AB#3624552](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3624552) --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent eaf3d1f commit 7a1be91

2 files changed

Lines changed: 31 additions & 16 deletions

File tree

  • msalautomationapp/src/androidTest/java/com/microsoft/identity/client/msal/automationapp/testpass/broker/brokerapi

msalautomationapp/src/androidTest/java/com/microsoft/identity/client/msal/automationapp/testpass/broker/brokerapi/TestCase3571739.java

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.microsoft.identity.client.ui.automation.utils.UiAutomatorUtils;
4040
import com.microsoft.identity.common.java.commands.webapps.WebAppsGetTokenSubOperationResponse;
4141
import com.microsoft.identity.common.java.util.ObjectMapper;
42+
import com.microsoft.identity.common.java.util.ThreadUtils;
4243
import com.microsoft.identity.labapi.utilities.client.ILabAccount;
4344
import com.microsoft.identity.labapi.utilities.client.LabQuery;
4445
import com.microsoft.identity.labapi.utilities.constants.AzureEnvironment;
@@ -49,8 +50,8 @@
4950
import 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

Comments
 (0)