diff --git a/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/broker/AbstractTestBroker.java b/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/broker/AbstractTestBroker.java index de6027aaac..d878d62a00 100644 --- a/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/broker/AbstractTestBroker.java +++ b/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/broker/AbstractTestBroker.java @@ -218,4 +218,9 @@ protected PromptHandlerParameters getDefaultBrokerPromptHandlerParameters(@NonNu .loginHint(username) .build(); } + + @Override + public void enableScreenCapture() { + // Default implementation, Do nothing. + } } diff --git a/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/broker/BrokerMicrosoftAuthenticator.java b/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/broker/BrokerMicrosoftAuthenticator.java index 29b24602a4..6529f77aef 100644 --- a/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/broker/BrokerMicrosoftAuthenticator.java +++ b/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/broker/BrokerMicrosoftAuthenticator.java @@ -29,6 +29,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Build; +import android.util.Log; import android.widget.Button; import android.widget.EditText; @@ -272,6 +273,34 @@ private String createPowerLiftIncidentInSharedDeviceMode() { } } + + public void enableScreenCapture() { + Log.i(TAG, "Enable Screen Capture.."); + try { + launch(); // launch Authenticator app + handleFirstRun(); // handle first run experience + + // click the 3 dot menu icon in top right + UiAutomatorUtils.handleButtonClick("com.azure.authenticator:id/menu_overflow"); + + // select Settings from drop down + final UiObject settings = UiAutomatorUtils.obtainUiObjectWithText("Settings"); + settings.click(); + + final UiObject screenCapture = UiAutomatorUtils.obtainChildInScrollable( + "settingsScrollView", + "Screen Capture" + ); + + screenCapture.click(); + Log.i(TAG, "Screen Capture is enabled.."); + forceStop(); + Log.i(TAG, "App is force stopped.."); + } catch (final UiObjectNotFoundException e) { + throw new AssertionError(e); + } + } + @Override public DeviceAdmin getAdminName() { Logger.i(TAG, "Get Admin Name.."); @@ -282,10 +311,10 @@ public DeviceAdmin getAdminName() { * Open the device registration page in the Authenticator App */ public void openDeviceRegistrationPage() { - Logger.i(TAG, "Open the device registration page in the Authenticator App.."); + Log.i(TAG, "Open the device registration page in the Authenticator App.."); launch(); // launch Authenticator app - handleFirstRun(); // handle first run experience + //handleFirstRun(); // handle first run experience goToDeviceRegistrationPage(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { @@ -404,6 +433,7 @@ public void handleFirstRun() { UiAutomatorUtils.handleButtonClick("com.azure.authenticator:id/frx_skip_button"); // This is required for auth app as it has increased the compile sdk version to 34 UiAutomatorUtils.handleButtonClickForObjectWithTextSafely("NOT NOW"); + shouldHandleFirstRun = false; } } diff --git a/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/broker/ITestBroker.java b/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/broker/ITestBroker.java index 679f523ca8..fe5684b938 100644 --- a/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/broker/ITestBroker.java +++ b/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/broker/ITestBroker.java @@ -142,4 +142,6 @@ public interface ITestBroker extends IApp { * @return the flight information set for this broker app */ String getFlights(); + + void enableScreenCapture(); } diff --git a/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/utils/AdbShellUtils.java b/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/utils/AdbShellUtils.java index 210b8da8be..2fd6993ecf 100644 --- a/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/utils/AdbShellUtils.java +++ b/uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/utils/AdbShellUtils.java @@ -35,6 +35,8 @@ import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; +import android.util.Log; + /** * This class contains utility methods that can be used to interact with the ADB Shell from within * code during the execution of a UI Test. @@ -146,8 +148,13 @@ public static void clearPackage(@NonNull final String packageName) { * @param packageName the package to force stop */ public static void forceStopPackage(@NonNull final String packageName) { - Logger.i(TAG, "Force stop the " + packageName + " App.."); + Log.i(TAG, "Force stop the " + packageName + " App.."); executeShellCommand("am force-stop " + packageName); + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } } private static void putGlobalSettings(final String settingName, final String value) {