diff --git a/src/Plugin.Maui.UITestHelpers.Appium/AppiumAndroidApp.cs b/src/Plugin.Maui.UITestHelpers.Appium/AppiumAndroidApp.cs index 2451119..8d28791 100644 --- a/src/Plugin.Maui.UITestHelpers.Appium/AppiumAndroidApp.cs +++ b/src/Plugin.Maui.UITestHelpers.Appium/AppiumAndroidApp.cs @@ -5,89 +5,88 @@ namespace Plugin.Maui.UITestHelpers.Appium { - public class AppiumAndroidApp : AppiumApp, IAndroidApp - { - private AppiumAndroidApp(Uri remoteAddress, IConfig config) - : base(new AndroidDriver(remoteAddress, GetOptions(config)), config) - { - _commandExecutor.AddCommandGroup(new AppiumAndroidVirtualKeyboardActions(this)); - _commandExecutor.AddCommandGroup(new AppiumAndroidAlertActions(this)); - _commandExecutor.AddCommandGroup(new AppiumAndroidSpecificActions(this)); - _commandExecutor.AddCommandGroup(new AppiumAndroidThemeChangeAction()); + public class AppiumAndroidApp : AppiumApp, IAndroidApp + { + private AppiumAndroidApp(Uri remoteAddress, IConfig config) + : base(new AndroidDriver(remoteAddress, GetOptions(config)), config) + { + _commandExecutor.AddCommandGroup(new AppiumAndroidVirtualKeyboardActions(this)); + _commandExecutor.AddCommandGroup(new AppiumAndroidAlertActions(this)); + _commandExecutor.AddCommandGroup(new AppiumAndroidSpecificActions(this)); + _commandExecutor.AddCommandGroup(new AppiumAndroidThemeChangeAction()); } - public static AppiumAndroidApp CreateAndroidApp(Uri remoteAddress, IConfig config) - { - var device = config.GetProperty("EmulatorDeviceName"); - var apkPath = config.GetProperty("AppPath"); - var pkgName = config.GetProperty("AppId"); - var outDir = config.GetProperty("ReportDirectory"); - var enableDebugPopup = config.GetProperty("EnableDebugPopup"); - var avdForce = config.GetProperty("AvdForceInstall"); + public static AppiumAndroidApp CreateAndroidApp(Uri remoteAddress, IConfig config) + { + var device = config.GetProperty("EmulatorDeviceName"); + var apkPath = config.GetProperty("AppPath"); + var pkgName = config.GetProperty("AppId"); + var outDir = config.GetProperty("ReportDirectory"); + var enableDebugPopup = config.GetProperty("EnableDebugPopup"); + var avdForce = config.GetProperty("AvdForceInstall"); - if (enableDebugPopup) - Environment.SetEnvironmentVariable("SWIFTSHADER_DISABLE_DEBUGGER_WAIT_DIALOG", "0"); - else - Environment.SetEnvironmentVariable("SWIFTSHADER_DISABLE_DEBUGGER_WAIT_DIALOG", "1"); + if (enableDebugPopup) + Environment.SetEnvironmentVariable("SWIFTSHADER_DISABLE_DEBUGGER_WAIT_DIALOG", "0"); + else + Environment.SetEnvironmentVariable("SWIFTSHADER_DISABLE_DEBUGGER_WAIT_DIALOG", "1"); - //// Will check if AVD with device name already exists first and not reinstall - //AndroidEmulator.AvdCreate(device, force: avdForce); - //// StartEmulator will return immediately if emulator is already running - //AndroidEmulator.StartEmulator(device); - //// TODO: Check for installed package first? - //AndroidEmulator.InstallPackage(apkPath, pkgName, outDir); - var androidApp = new AppiumAndroidApp(remoteAddress, config); - androidApp.Driver.ActivateApp(pkgName); - return androidApp; - } + //// Will check if AVD with device name already exists first and not reinstall + //AndroidEmulator.AvdCreate(device, force: avdForce); + //// StartEmulator will return immediately if emulator is already running + //AndroidEmulator.StartEmulator(device); + //// TODO: Check for installed package first? + //AndroidEmulator.InstallPackage(apkPath, pkgName, outDir); + var androidApp = new AppiumAndroidApp(remoteAddress, config); + androidApp.Driver.ActivateApp(pkgName); + return androidApp; + } - public override IUIElementQueryable Query => new AppiumAndroidQueryable(this); + public override IUIElementQueryable Query => new AppiumAndroidQueryable(this); - public override ApplicationState AppState - { - get - { - var appId = Config.GetProperty("AppId") ?? throw new InvalidOperationException($"{nameof(AppState)} could not get the appid property"); - var state = _driver?.ExecuteScript("mobile: queryAppState", new Dictionary - { - { "appId", appId }, - }); + public override ApplicationState AppState + { + get + { + var appId = Config.GetProperty("AppId") ?? throw new InvalidOperationException($"{nameof(AppState)} could not get the appid property"); + var state = _driver?.ExecuteScript("mobile: queryAppState", new Dictionary + { + { "appId", appId }, + }); - // https://github.com/appium/appium-uiautomator2-driver#mobile-queryappstate - if (state == null) - { - return ApplicationState.Unknown; - } + // https://github.com/appium/appium-uiautomator2-driver#mobile-queryappstate + if (state == null) + { + return ApplicationState.Unknown; + } - return Convert.ToInt32(state) switch - { - 0 => ApplicationState.NotInstalled, - 1 => ApplicationState.NotRunning, - 3 or - 4 => ApplicationState.Running, - _ => ApplicationState.Unknown, - }; - } - } + return Convert.ToInt32(state) switch + { + 0 => ApplicationState.NotInstalled, + 1 => ApplicationState.NotRunning, + 3 or + 4 => ApplicationState.Running, + _ => ApplicationState.Unknown, + }; + } + } - private static AppiumOptions GetOptions(IConfig config) - { - config.SetProperty("PlatformName", "Android"); - config.SetProperty("AutomationName", "UIAutomator2"); - var appId = config.GetProperty("AppId"); + private static AppiumOptions GetOptions(IConfig config) + { + config.SetProperty("PlatformName", "Android"); + config.SetProperty("AutomationName", "UIAutomator2"); + var appId = config.GetProperty("AppId"); - var options = new AppiumOptions(); + var options = new AppiumOptions(); - SetGeneralAppiumOptions(config, options); + SetGeneralAppiumOptions(config, options); - if (!string.IsNullOrWhiteSpace(appId)) - { - options.AddAdditionalAppiumOption(MobileCapabilityType.NoReset, "true"); - options.AddAdditionalAppiumOption(AndroidMobileCapabilityType.AppPackage, appId); - options.AddAdditionalAppiumOption(AndroidMobileCapabilityType.AppActivity, $"{appId}.MainActivity"); - } + if (!string.IsNullOrWhiteSpace(appId)) + { + options.AddAdditionalAppiumOption(AndroidMobileCapabilityType.AppPackage, appId); + options.AddAdditionalAppiumOption(AndroidMobileCapabilityType.AppActivity, $"{appId}.MainActivity"); + } - return options; - } - } -} + return options; + } + } +} \ No newline at end of file