From 9b035fe6093ac9c5389e217b931d5240413042fe Mon Sep 17 00:00:00 2001 From: Dor Blayzer <59066376+Dor-bl@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:38:50 +0200 Subject: [PATCH] feat: 'IOSDriver' to use modern `mobile:` commands for Lock, IsLocked and Unlock (#875) * feat: `AppiumDriver` to use modern `mobile:` commands for Lock, IsLocked. feat: `IOSDriver` to use modern `mobile:` command for Unlock * Revert changes for AppiumDriver Make Lock methods specfic for iOS and Android --- src/Appium.Net/Appium/AppiumCommand.cs | 6 ---- .../Appium/AppiumCommandExecutionHelper.cs | 5 ---- src/Appium.Net/Appium/AppiumDriverCommand.cs | 15 ---------- .../Appium/iOS/IOSCommandExecutionHelper.cs | 9 ------ src/Appium.Net/Appium/iOS/IOSDriver.cs | 30 ++++++++++++++----- 5 files changed, 23 insertions(+), 42 deletions(-) diff --git a/src/Appium.Net/Appium/AppiumCommand.cs b/src/Appium.Net/Appium/AppiumCommand.cs index 82edd80e..9258fb71 100644 --- a/src/Appium.Net/Appium/AppiumCommand.cs +++ b/src/Appium.Net/Appium/AppiumCommand.cs @@ -78,12 +78,6 @@ public class AppiumCommand new AppiumCommand(HttpCommandInfo.PostCommand, AppiumDriverCommand.ShakeDevice, "/session/{sessionId}/appium/device/shake"), - new AppiumCommand(HttpCommandInfo.PostCommand, AppiumDriverCommand.LockDevice, - "/session/{sessionId}/appium/device/lock"), - new AppiumCommand(HttpCommandInfo.PostCommand, AppiumDriverCommand.IsLocked, - "/session/{sessionId}/appium/device/is_locked"), - new AppiumCommand(HttpCommandInfo.PostCommand, AppiumDriverCommand.UnlockDevice, - "/session/{sessionId}/appium/device/unlock"), new AppiumCommand(HttpCommandInfo.PostCommand, AppiumDriverCommand.PressKeyCode, "/session/{sessionId}/appium/device/press_keycode"), new AppiumCommand(HttpCommandInfo.PostCommand, AppiumDriverCommand.LongPressKeyCode, diff --git a/src/Appium.Net/Appium/AppiumCommandExecutionHelper.cs b/src/Appium.Net/Appium/AppiumCommandExecutionHelper.cs index 47ff9b66..acda289e 100644 --- a/src/Appium.Net/Appium/AppiumCommandExecutionHelper.cs +++ b/src/Appium.Net/Appium/AppiumCommandExecutionHelper.cs @@ -82,11 +82,6 @@ public static bool IsKeyboardShown(IExecuteMethod executeMethod) #endregion - public static void Lock(IExecuteMethod executeMethod, int seconds) => - executeMethod.Execute(AppiumDriverCommand.LockDevice, - new Dictionary() - {["seconds"] = seconds}); - public static void SetClipboard(IExecuteMethod executeMethod, ClipboardContentType clipboardContentType, string base64Content) { diff --git a/src/Appium.Net/Appium/AppiumDriverCommand.cs b/src/Appium.Net/Appium/AppiumDriverCommand.cs index 6b9b371c..958a83da 100644 --- a/src/Appium.Net/Appium/AppiumDriverCommand.cs +++ b/src/Appium.Net/Appium/AppiumDriverCommand.cs @@ -23,21 +23,6 @@ public class AppiumDriverCommand /// public const string ShakeDevice = "shakeDevice"; - /// - /// Represents the Lock Device Mapping command - /// - public const string LockDevice = "lockDevice"; - - /// - /// Represents the Unlock Device Mapping command - /// - public const string UnlockDevice = "unlockDevice"; - - /// - /// Represents the Is Device Locked Mapping command - /// - public const string IsLocked = "isLocked"; - /// /// Toggle's the Airplane Mode ("Flight Safe Mode") Command /// diff --git a/src/Appium.Net/Appium/iOS/IOSCommandExecutionHelper.cs b/src/Appium.Net/Appium/iOS/IOSCommandExecutionHelper.cs index 0eebb481..f9c498ad 100644 --- a/src/Appium.Net/Appium/iOS/IOSCommandExecutionHelper.cs +++ b/src/Appium.Net/Appium/iOS/IOSCommandExecutionHelper.cs @@ -33,15 +33,6 @@ public static void PerformTouchID(IExecuteMethod executeMethod, bool match) => executeMethod.Execute(AppiumDriverCommand.TouchID, new Dictionary {["match"] = match}); - public static bool IsLocked(IExecuteMethod executeMethod) => - (bool)executeMethod.Execute(AppiumDriverCommand.IsLocked).Value; - - public static void Unlock(IExecuteMethod executeMethod) => - executeMethod.Execute(AppiumDriverCommand.UnlockDevice); - - public static void Lock(IExecuteMethod executeMethod) => - executeMethod.Execute(AppiumDriverCommand.LockDevice); - public static void SetClipboardUrl(IExecuteMethod executeMethod, string url) { var urlEncoded = WebUtility.UrlEncode(url); diff --git a/src/Appium.Net/Appium/iOS/IOSDriver.cs b/src/Appium.Net/Appium/iOS/IOSDriver.cs index a8cbe552..87232e3f 100644 --- a/src/Appium.Net/Appium/iOS/IOSDriver.cs +++ b/src/Appium.Net/Appium/iOS/IOSDriver.cs @@ -187,19 +187,35 @@ public Dictionary Settings public void HideKeyboard(string key, string strategy = null) => AppiumCommandExecutionHelper.HideKeyboard(this, strategy, key); + public void PerformTouchID(bool match) => IOSCommandExecutionHelper.PerformTouchID(this, match); + /// - /// Locks the device. + /// Check if the device is locked /// - /// The number of seconds during which the device need to be locked for. - public void Lock(int seconds) => AppiumCommandExecutionHelper.Lock(this, seconds); + /// true if device is locked, false otherwise + public bool IsLocked() => (bool)ExecuteScript("mobile: isLocked"); - public void PerformTouchID(bool match) => IOSCommandExecutionHelper.PerformTouchID(this, match); + /// + /// Locks the device. Optionally, unlocks it after a specified number of seconds. + /// + /// + /// The number of seconds after which the device will be automatically unlocked. + /// Set to 0 or leave it empty to require manual unlock. + /// + /// Thrown if the command execution fails. + public void Lock(int? seconds = null) + { + var parameters = new Dictionary(); - public bool IsLocked() => IOSCommandExecutionHelper.IsLocked(this); + if (seconds.HasValue && seconds.Value > 0) + { + parameters["seconds"] = seconds.Value; + } - public void Unlock() => IOSCommandExecutionHelper.Unlock(this); + ExecuteScript("mobile: lock", parameters); + } - public void Lock() => IOSCommandExecutionHelper.Lock(this); + public void Unlock() => ExecuteScript("mobile: unlock"); /// /// Sets the content to the clipboard