Skip to content

Commit

Permalink
Add fingerprint endpoint and toggle data endpoints (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgraham authored Apr 15, 2019
1 parent 1dcb236 commit 4ec4c8b
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ packages
.idea
.vs/
env.json

.vscode/
4 changes: 4 additions & 0 deletions src/Appium.Net/Appium/AppiumCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions src/Appium.Net/Appium/AppiumCommandExecutionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public static void PushFile(IExecuteMethod executeMethod, string pathOnDevice, b
executeMethod.Execute(AppiumDriverCommand.PushFile, new Dictionary<string, object>()
{ ["path"] = pathOnDevice, ["data"] = base64Data });

public static void FingerPrint(IExecuteMethod executeMethod, int fingerprintId) =>
executeMethod.Execute(AppiumDriverCommand.FingerPrint, new Dictionary<string, object>()
{ ["fingerprintId"] = fingerprintId});

public static void PushFile(IExecuteMethod executeMethod, string pathOnDevice, FileInfo file)
{
if (file == null)
Expand All @@ -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

/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions src/Appium.Net/Appium/AppiumDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
12 changes: 12 additions & 0 deletions src/Appium.Net/Appium/AppiumDriverCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public class AppiumDriverCommand
/// </summary>
public const string ToggleAirplaneMode = "toggleAirplaneMode";


/// <summary>
/// Toggle Network Data Command
/// </summary>
public static string ToggleData = "toggleData";

/// <summary>
/// Press key code
/// </summary>
Expand Down Expand Up @@ -275,6 +281,11 @@ public class AppiumDriverCommand
/// </summary>
public const string TouchID = "touchId";

/// <summary>
/// Represents the fingerPrint command
public const string FingerPrint = "fingerPrint";
/// </summary>

public const string ReplaceValue = "replaceValue";

public const string SetValue = "setValue";
Expand All @@ -288,5 +299,6 @@ public class AppiumDriverCommand
public const string StopRecordingScreen = "stopRecordingScreen";

#endregion JSON Wire Protocol

}
}
55 changes: 55 additions & 0 deletions test/integration/Android/DeviceTest.cs
Original file line number Diff line number Diff line change
@@ -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<IWebElement> _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<IWebElement>(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();
}
}
}

0 comments on commit 4ec4c8b

Please sign in to comment.