From 4ec4c8b5447b7b5052f2b9c3a1a848ad62def410 Mon Sep 17 00:00:00 2001 From: Dan Graham Date: Sun, 14 Apr 2019 22:40:03 -0700 Subject: [PATCH] Add fingerprint endpoint and toggle data endpoints (#324) --- .gitignore | 2 +- src/Appium.Net/Appium/AppiumCommand.cs | 4 ++ .../Appium/AppiumCommandExecutionHelper.cs | 9 +++ src/Appium.Net/Appium/AppiumDriver.cs | 7 +++ src/Appium.Net/Appium/AppiumDriverCommand.cs | 12 ++++ test/integration/Android/DeviceTest.cs | 55 +++++++++++++++++++ 6 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 test/integration/Android/DeviceTest.cs diff --git a/.gitignore b/.gitignore index 81fbabda..11af94b6 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,4 @@ packages .idea .vs/ env.json - +.vscode/ \ No newline at end of file diff --git a/src/Appium.Net/Appium/AppiumCommand.cs b/src/Appium.Net/Appium/AppiumCommand.cs index 23644284..fb9b7afa 100644 --- a/src/Appium.Net/Appium/AppiumCommand.cs +++ b/src/Appium.Net/Appium/AppiumCommand.cs @@ -51,6 +51,8 @@ public class AppiumCommand "/session/{sessionId}/appium/device/unlock"), new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.ToggleAirplaneMode, "/session/{sessionId}/appium/device/toggle_airplane_mode"), + new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.ToggleData, + "/session/{sessionId}/appium/device/toggle_data"), new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.PressKeyCode, "/session/{sessionId}/appium/device/press_keycode"), new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.LongPressKeyCode, @@ -99,6 +101,8 @@ public class AppiumCommand "/session/{sessionId}/appium/settings"), new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.TouchID, "/session/{sessionId}/appium/simulator/touch_id"), + new AppiumCommand(CommandInfo.PostCommand, AppiumDriverCommand.FingerPrint, + "/session/{sessionId}/appium/device/finger_print"), #endregion Driver Commands diff --git a/src/Appium.Net/Appium/AppiumCommandExecutionHelper.cs b/src/Appium.Net/Appium/AppiumCommandExecutionHelper.cs index d04e31dd..2fd8af99 100644 --- a/src/Appium.Net/Appium/AppiumCommandExecutionHelper.cs +++ b/src/Appium.Net/Appium/AppiumCommandExecutionHelper.cs @@ -127,6 +127,10 @@ public static void PushFile(IExecuteMethod executeMethod, string pathOnDevice, b executeMethod.Execute(AppiumDriverCommand.PushFile, new Dictionary() { ["path"] = pathOnDevice, ["data"] = base64Data }); + public static void FingerPrint(IExecuteMethod executeMethod, int fingerprintId) => + executeMethod.Execute(AppiumDriverCommand.FingerPrint, new Dictionary() + { ["fingerprintId"] = fingerprintId}); + public static void PushFile(IExecuteMethod executeMethod, string pathOnDevice, FileInfo file) { if (file == null) @@ -144,6 +148,11 @@ public static void PushFile(IExecuteMethod executeMethod, string pathOnDevice, F PushFile(executeMethod, pathOnDevice, Convert.FromBase64String(fileBase64Data)); } + public static void ToggleData(IExecuteMethod executeMethod) + { + executeMethod.Execute(AppiumDriverCommand.ToggleData); + } + #endregion Device Commands /// diff --git a/src/Appium.Net/Appium/AppiumDriver.cs b/src/Appium.Net/Appium/AppiumDriver.cs index c6f5fce0..0ab5c4d5 100644 --- a/src/Appium.Net/Appium/AppiumDriver.cs +++ b/src/Appium.Net/Appium/AppiumDriver.cs @@ -254,6 +254,13 @@ public void PushFile(string pathOnDevice, FileInfo file) => public void ResetApp() => ((IExecuteMethod) this).Execute(AppiumDriverCommand.ResetApp); + public void FingerPrint(int fingerprintId) => + AppiumCommandExecutionHelper.FingerPrint(this, fingerprintId); + + public void ToggleData() => + AppiumCommandExecutionHelper.ToggleData(this); + + public void BackgroundApp() => Execute(AppiumDriverCommand.BackgroundApp, AppiumCommandExecutionHelper.PrepareArgument("seconds", AppiumCommandExecutionHelper.PrepareArgument("timeout", null))); diff --git a/src/Appium.Net/Appium/AppiumDriverCommand.cs b/src/Appium.Net/Appium/AppiumDriverCommand.cs index 46daa223..2010c2d0 100644 --- a/src/Appium.Net/Appium/AppiumDriverCommand.cs +++ b/src/Appium.Net/Appium/AppiumDriverCommand.cs @@ -45,6 +45,12 @@ public class AppiumDriverCommand /// public const string ToggleAirplaneMode = "toggleAirplaneMode"; + + /// + /// Toggle Network Data Command + /// + public static string ToggleData = "toggleData"; + /// /// Press key code /// @@ -275,6 +281,11 @@ public class AppiumDriverCommand /// public const string TouchID = "touchId"; + /// + /// Represents the fingerPrint command + public const string FingerPrint = "fingerPrint"; + /// + public const string ReplaceValue = "replaceValue"; public const string SetValue = "setValue"; @@ -288,5 +299,6 @@ public class AppiumDriverCommand public const string StopRecordingScreen = "stopRecordingScreen"; #endregion JSON Wire Protocol + } } \ No newline at end of file diff --git a/test/integration/Android/DeviceTest.cs b/test/integration/Android/DeviceTest.cs new file mode 100644 index 00000000..dcb6916b --- /dev/null +++ b/test/integration/Android/DeviceTest.cs @@ -0,0 +1,55 @@ +using System; +using System.Text.RegularExpressions; +using Appium.Net.Integration.Tests.helpers; +using NUnit.Framework; +using OpenQA.Selenium; +using OpenQA.Selenium.Appium.Android; +using OpenQA.Selenium.Appium.Enums; + +namespace Appium.Net.Integration.Tests.Android +{ + [TestFixture(Category = "Device")] + public class DeviceTest + { + private AndroidDriver _driver; + private const string ClipboardTestString = "Hello Clipboard"; + private const string Base64RegexPattern = @"^[a-zA-Z0-9\+/]*={0,2}$"; + + [OneTimeSetUp] + public void BeforeAll() + { + var capabilities = Caps.GetAndroidCaps(Apps.Get("androidApiDemos")); + capabilities.AddAdditionalCapability(MobileCapabilityType.FullReset, true); + var serverUri = Env.ServerIsRemote() ? AppiumServers.RemoteServerUri : AppiumServers.LocalServiceUri; + _driver = new AndroidDriver(serverUri, capabilities, Env.InitTimeoutSec); + _driver.Manage().Timeouts().ImplicitWait = Env.ImplicitTimeoutSec; + } + + [SetUp] + public void SetUp() + { + _driver?.LaunchApp(); + } + + [TearDown] + public void TearDown() + { + _driver?.CloseApp(); + } + + [Test] + public void TestSendFingerprint() + { + // There's no way to verify sending fingerprint had an effect, + // so just test that it's successfully called without an exception + _driver.FingerPrint(1); + } + + [Test] + public void TestToggleData() + { + _driver.ToggleData(); + _driver.ToggleData(); + } + } +}