Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 'IOSDriver' to use modern mobile: commands for Lock, IsLocked and Unlock #875

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/Appium.Net/Appium/AppiumCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions src/Appium.Net/Appium/AppiumCommandExecutionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object>()
{["seconds"] = seconds});

public static void SetClipboard(IExecuteMethod executeMethod, ClipboardContentType clipboardContentType,
string base64Content)
{
Expand Down
15 changes: 0 additions & 15 deletions src/Appium.Net/Appium/AppiumDriverCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,6 @@ public class AppiumDriverCommand
/// </summary>
public const string ShakeDevice = "shakeDevice";

/// <summary>
/// Represents the Lock Device Mapping command
/// </summary>
public const string LockDevice = "lockDevice";

/// <summary>
/// Represents the Unlock Device Mapping command
/// </summary>
public const string UnlockDevice = "unlockDevice";

/// <summary>
/// Represents the Is Device Locked Mapping command
/// </summary>
public const string IsLocked = "isLocked";

/// <summary>
/// Toggle's the Airplane Mode ("Flight Safe Mode") Command
/// </summary>
Expand Down
9 changes: 0 additions & 9 deletions src/Appium.Net/Appium/iOS/IOSCommandExecutionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ public static void PerformTouchID(IExecuteMethod executeMethod, bool match) =>
executeMethod.Execute(AppiumDriverCommand.TouchID,
new Dictionary<string, object> {["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);
Expand Down
30 changes: 23 additions & 7 deletions src/Appium.Net/Appium/iOS/IOSDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,35 @@ public Dictionary<string, object> Settings
public void HideKeyboard(string key, string strategy = null) =>
AppiumCommandExecutionHelper.HideKeyboard(this, strategy, key);

public void PerformTouchID(bool match) => IOSCommandExecutionHelper.PerformTouchID(this, match);

/// <summary>
/// Locks the device.
/// Check if the device is locked
/// </summary>
/// <param name="seconds">The number of seconds during which the device need to be locked for.</param>
public void Lock(int seconds) => AppiumCommandExecutionHelper.Lock(this, seconds);
/// <returns>true if device is locked, false otherwise</returns>
public bool IsLocked() => (bool)ExecuteScript("mobile: isLocked");

public void PerformTouchID(bool match) => IOSCommandExecutionHelper.PerformTouchID(this, match);
/// <summary>
/// Locks the device. Optionally, unlocks it after a specified number of seconds.
/// </summary>
/// <param name="seconds">
/// The number of seconds after which the device will be automatically unlocked.
/// Set to 0 or leave it empty to require manual unlock.
/// </param>
/// <exception cref="WebDriverException">Thrown if the command execution fails.</exception>
public void Lock(int? seconds = null)
{
var parameters = new Dictionary<string, object>();

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");

/// <summary>
/// Sets the content to the clipboard
Expand Down
Loading