Skip to content
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
12 changes: 12 additions & 0 deletions src/Appium.Net/Appium/iOS/IOSCommandExecutionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,17 @@ public static Image GetClipboardImage(IExecuteMethod executeMethod)

return null;
}

public static Dictionary<string, object> GetSettings(IExecuteMethod executeMethod) =>
(Dictionary<string, object>)executeMethod.Execute(AppiumDriverCommand.GetSettings).Value;

public static void SetSetting(IExecuteMethod executeMethod, string setting, object value)
{
var settings = new Dictionary<string, object>()
{ [setting] = value };
var parameters = new Dictionary<string, object>()
{ ["settings"] = settings };
executeMethod.Execute(AppiumDriverCommand.UpdateSettings, parameters);
}
}
}
19 changes: 18 additions & 1 deletion src/Appium.Net/Appium/iOS/IOSDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace OpenQA.Selenium.Appium.iOS
{
public class IOSDriver<W> : AppiumDriver<W>, IFindByIosUIAutomation<W>, IFindsByIosClassChain<W>,
IFindsByIosNSPredicate<W>, IHidesKeyboardWithKeyName, IHasClipboard,
IShakesDevice, IPerformsTouchID where W : IWebElement
IShakesDevice, IPerformsTouchID, IHasSettings where W : IWebElement
{
private static readonly string Platform = MobilePlatform.IOS;

Expand Down Expand Up @@ -149,6 +149,23 @@ public IReadOnlyCollection<W> FindElementsByIosNsPredicate(string selector) =>

#endregion IFindsByIosNSPredicate Members


public void SetSetting(string setting, object value) =>
IOSCommandExecutionHelper.SetSetting(this, setting, value);

public Dictionary<string, object> 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) =>
Expand Down
36 changes: 36 additions & 0 deletions src/Appium.Net/Appium/iOS/Interfaces/IHasSettings.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// 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.
/// </summary>
/// <param name="setting">Setting you wish to set.</param>
/// <param name="value">value of the setting.</param>
void SetSetting(string setting, object value);

/// <summary>
/// Gets/Sets settings stored for this test session.
/// </summary>
Dictionary<string, object> Settings { set; get; }
}
}
47 changes: 47 additions & 0 deletions test/integration/IOS/SettingTest.cs
Original file line number Diff line number Diff line change
@@ -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<AppiumWebElement> _driver;

[OneTimeSetUp]
public void BeforeAll()
{
var capabilities = Caps.GetIosCaps(Apps.Get("iosUICatalogApp"));
var serverUri = Env.ServerIsRemote() ? AppiumServers.RemoteServerUri : AppiumServers.LocalServiceUri;
_driver = new IOSDriver<AppiumWebElement>(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"]);
}
}
}