diff --git a/src/Appium.Net/Appium/iOS/IOSCommandExecutionHelper.cs b/src/Appium.Net/Appium/iOS/IOSCommandExecutionHelper.cs index bcbdad48..0eebb481 100644 --- a/src/Appium.Net/Appium/iOS/IOSCommandExecutionHelper.cs +++ b/src/Appium.Net/Appium/iOS/IOSCommandExecutionHelper.cs @@ -89,5 +89,17 @@ public static Image GetClipboardImage(IExecuteMethod executeMethod) return null; } + + public static Dictionary GetSettings(IExecuteMethod executeMethod) => + (Dictionary)executeMethod.Execute(AppiumDriverCommand.GetSettings).Value; + + public static void SetSetting(IExecuteMethod executeMethod, string setting, object value) + { + var settings = new Dictionary() + { [setting] = value }; + var parameters = new Dictionary() + { ["settings"] = settings }; + executeMethod.Execute(AppiumDriverCommand.UpdateSettings, parameters); + } } } \ No newline at end of file diff --git a/src/Appium.Net/Appium/iOS/IOSDriver.cs b/src/Appium.Net/Appium/iOS/IOSDriver.cs index 662a2794..22c71146 100644 --- a/src/Appium.Net/Appium/iOS/IOSDriver.cs +++ b/src/Appium.Net/Appium/iOS/IOSDriver.cs @@ -25,7 +25,7 @@ namespace OpenQA.Selenium.Appium.iOS { public class IOSDriver : AppiumDriver, IFindByIosUIAutomation, IFindsByIosClassChain, IFindsByIosNSPredicate, IHidesKeyboardWithKeyName, IHasClipboard, - IShakesDevice, IPerformsTouchID where W : IWebElement + IShakesDevice, IPerformsTouchID, IHasSettings where W : IWebElement { private static readonly string Platform = MobilePlatform.IOS; @@ -149,6 +149,23 @@ public IReadOnlyCollection FindElementsByIosNsPredicate(string selector) => #endregion IFindsByIosNSPredicate Members + + public void SetSetting(string setting, object value) => + IOSCommandExecutionHelper.SetSetting(this, setting, value); + + public Dictionary Settings + { + get => IOSCommandExecutionHelper.GetSettings(this); + + set + { + foreach (var entry in value) + { + SetSetting(entry.Key, entry.Value); + } + } + } + public void ShakeDevice() => IOSCommandExecutionHelper.ShakeDevice(this); public void HideKeyboard(string key, string strategy = null) => diff --git a/src/Appium.Net/Appium/iOS/Interfaces/IHasSettings.cs b/src/Appium.Net/Appium/iOS/Interfaces/IHasSettings.cs new file mode 100644 index 00000000..23dfeddf --- /dev/null +++ b/src/Appium.Net/Appium/iOS/Interfaces/IHasSettings.cs @@ -0,0 +1,36 @@ +//Licensed under the Apache License, Version 2.0 (the "License"); +//you may not use this file except in compliance with the License. +//See the NOTICE file distributed with this work for additional +//information regarding copyright ownership. +//You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +//Unless required by applicable law or agreed to in writing, software +//distributed under the License is distributed on an "AS IS" BASIS, +//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +//See the License for the specific language governing permissions and +//limitations under the License. + +using OpenQA.Selenium.Appium.Interfaces; +using System.Collections.Generic; + +namespace OpenQA.Selenium.Appium.iOS.Interfaces +{ + public interface IHasSettings : IExecuteMethod + { + /// + /// Set a setting for this test session It's probably better to use a + /// convenience function, rather than use this function directly. Try finding + /// the method for the specific setting you want to change. + /// + /// Setting you wish to set. + /// value of the setting. + void SetSetting(string setting, object value); + + /// + /// Gets/Sets settings stored for this test session. + /// + Dictionary Settings { set; get; } + } +} \ No newline at end of file diff --git a/test/integration/IOS/SettingTest.cs b/test/integration/IOS/SettingTest.cs new file mode 100644 index 00000000..f7cc42f0 --- /dev/null +++ b/test/integration/IOS/SettingTest.cs @@ -0,0 +1,47 @@ +using Appium.Net.Integration.Tests.helpers; +using NUnit.Framework; +using OpenQA.Selenium.Appium; +using OpenQA.Selenium.Appium.iOS; + +namespace Appium.Net.Integration.Tests.iOS +{ + public class SettingTest + { + private IOSDriver _driver; + + [OneTimeSetUp] + public void BeforeAll() + { + var capabilities = Caps.GetIosCaps(Apps.Get("iosUICatalogApp")); + var serverUri = Env.ServerIsRemote() ? AppiumServers.RemoteServerUri : AppiumServers.LocalServiceUri; + _driver = new IOSDriver(serverUri, capabilities, Env.InitTimeoutSec); + _driver.Manage().Timeouts().ImplicitWait = Env.ImplicitTimeoutSec; + } + + [OneTimeTearDown] + public void AfterEach() + { + _driver?.Quit(); + if (!Env.ServerIsRemote()) + { + AppiumServers.StopLocalService(); + } + } + + [Test] + public void SettingsUpdateTest() + { + _driver.SetSetting( + setting: "useJSONSource", + value: true); + + Assert.IsTrue((bool)_driver.Settings["useJSONSource"]); + + _driver.SetSetting( + setting: "useJSONSource", + value: false); + + Assert.IsFalse((bool)_driver.Settings["useJSONSource"]); + } + } +} \ No newline at end of file