Skip to content

Commit 2e0a914

Browse files
committed
Merge pull request #60 from Jonahss/master
added GetSettings() and IgnoreUnimportantViews()
2 parents 0f20b93 + ae0984b commit 2e0a914

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

appium-dotnet-driver/Appium/AppiumDriver.cs

+38-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
using System.Reflection;
2929
using OpenQA.Selenium.Appium.src.Appium.Interfaces;
3030
using System.Diagnostics.Contracts;
31+
using Newtonsoft.Json;
3132

3233
namespace OpenQA.Selenium.Appium
3334
{
@@ -741,6 +742,40 @@ public void PerformTouchAction(TouchAction touchAction)
741742

742743
#endregion Multi Actions
743744

745+
#region Settings
746+
747+
/// <summary>
748+
/// Get appium settings currently set for the session
749+
/// See: https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/settings.md
750+
/// </summary>
751+
public Dictionary<String, Object> GetSettings()
752+
{
753+
var commandResponse = this.Execute(AppiumDriverCommand.GetSettings, null);
754+
return JsonConvert.DeserializeObject<Dictionary<String, Object>>((String) commandResponse.Value);
755+
}
756+
757+
/// <summary>
758+
/// Set "ignoreUnimportantViews" setting.
759+
/// See: https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/settings.md
760+
/// </summary>
761+
public void IgnoreUnimportantViews(bool value)
762+
{
763+
this.UpdateSetting ("ignoreUnimportantViews", value);
764+
}
765+
766+
/// <summary>
767+
/// Update an appium Setting, on the session
768+
/// </summary>
769+
private void UpdateSetting(String setting, Object value)
770+
{
771+
var parameters = new Dictionary<string, object>();
772+
var settings = new Dictionary<string, object>();
773+
settings.Add(setting, value);
774+
parameters.Add("settings", settings);
775+
this.Execute(AppiumDriverCommand.UpdateSettings, parameters);
776+
}
777+
#endregion Settings
778+
744779
#endregion Public Methods
745780

746781
#region Internal Methods
@@ -862,7 +897,9 @@ private static void _AddAppiumCommands()
862897
new _Commands(CommandInfo.PostCommand, AppiumDriverCommand.HideKeyboard, "/session/{sessionId}/appium/device/hide_keyboard"),
863898
new _Commands(CommandInfo.PostCommand, AppiumDriverCommand.OpenNotifications, "/session/{sessionId}/appium/device/open_notifications"),
864899
new _Commands(CommandInfo.PostCommand, AppiumDriverCommand.StartActivity, "/session/{sessionId}/appium/device/start_activity"),
865-
#endregion Appium Commands
900+
new _Commands(CommandInfo.GetCommand, AppiumDriverCommand.GetSettings, "/session/{sessionId}/appium/settings"),
901+
new _Commands(CommandInfo.PostCommand, AppiumDriverCommand.UpdateSettings, "/session/{sessionId}/appium/settings"),
902+
#endregion Appium Commands
866903
#region Touch Commands
867904
new _Commands(CommandInfo.PostCommand, AppiumDriverCommand.MultiActionV2Perform, "/session/{sessionId}/touch/multi/perform"),
868905
new _Commands(CommandInfo.PostCommand, AppiumDriverCommand.TouchActionV2Perform, "/session/{sessionId}/touch/perform"),

appium-dotnet-driver/Appium/AppiumDriverCommand.cs

+10
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,16 @@ public class AppiumDriverCommand
225225
/// </summary>
226226
public const string GetScreenshot = "screenshot";
227227

228+
/// <summary>
229+
/// Represents the GetSettings Command
230+
/// </summary>
231+
public const string GetSettings = "getSettings";
232+
233+
/// <summary>
234+
/// Represents the UpdateSettings Command
235+
/// </summary>
236+
public const string UpdateSettings = "updateSettings";
237+
228238
#endregion JSON Wire Protocol
229239
}
230240
}

test/specs/MJsonMethodTest.cs

+18
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,24 @@ public void HideKeyboardTestCase ()
246246
}
247247
}
248248

249+
[Test]
250+
public void SettingsTestCase ()
251+
{
252+
{
253+
var data = "{\"setting\": true}";
254+
Dictionary<String, Object> simpleDict = new Dictionary<string, object> ();
255+
simpleDict.Add ("setting", true);
256+
server.respondTo ("GET", "/appium/settings", data);
257+
var result = driver.GetSettings ();
258+
Assert.AreEqual (result, simpleDict);
259+
}
260+
{
261+
RequestProcessor re = server.respondTo ("POST", "/appium/settings", null);
262+
driver.IgnoreUnimportantViews (true);
263+
Assert.AreEqual (re.inputData, "{\"settings\":{\"ignoreUnimportantViews\":true}}");
264+
}
265+
}
266+
249267
}
250268
}
251269

0 commit comments

Comments
 (0)