Skip to content

Commit 135c1d3

Browse files
feat: Settings implementation for iOS driver (#466)
1 parent 4570d11 commit 135c1d3

File tree

4 files changed

+113
-1
lines changed

4 files changed

+113
-1
lines changed

src/Appium.Net/Appium/iOS/IOSCommandExecutionHelper.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,17 @@ public static Image GetClipboardImage(IExecuteMethod executeMethod)
8989

9090
return null;
9191
}
92+
93+
public static Dictionary<string, object> GetSettings(IExecuteMethod executeMethod) =>
94+
(Dictionary<string, object>)executeMethod.Execute(AppiumDriverCommand.GetSettings).Value;
95+
96+
public static void SetSetting(IExecuteMethod executeMethod, string setting, object value)
97+
{
98+
var settings = new Dictionary<string, object>()
99+
{ [setting] = value };
100+
var parameters = new Dictionary<string, object>()
101+
{ ["settings"] = settings };
102+
executeMethod.Execute(AppiumDriverCommand.UpdateSettings, parameters);
103+
}
92104
}
93105
}

src/Appium.Net/Appium/iOS/IOSDriver.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace OpenQA.Selenium.Appium.iOS
2525
{
2626
public class IOSDriver<W> : AppiumDriver<W>, IFindByIosUIAutomation<W>, IFindsByIosClassChain<W>,
2727
IFindsByIosNSPredicate<W>, IHidesKeyboardWithKeyName, IHasClipboard,
28-
IShakesDevice, IPerformsTouchID where W : IWebElement
28+
IShakesDevice, IPerformsTouchID, IHasSettings where W : IWebElement
2929
{
3030
private static readonly string Platform = MobilePlatform.IOS;
3131

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

150150
#endregion IFindsByIosNSPredicate Members
151151

152+
153+
public void SetSetting(string setting, object value) =>
154+
IOSCommandExecutionHelper.SetSetting(this, setting, value);
155+
156+
public Dictionary<string, object> Settings
157+
{
158+
get => IOSCommandExecutionHelper.GetSettings(this);
159+
160+
set
161+
{
162+
foreach (var entry in value)
163+
{
164+
SetSetting(entry.Key, entry.Value);
165+
}
166+
}
167+
}
168+
152169
public void ShakeDevice() => IOSCommandExecutionHelper.ShakeDevice(this);
153170

154171
public void HideKeyboard(string key, string strategy = null) =>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//Licensed under the Apache License, Version 2.0 (the "License");
2+
//you may not use this file except in compliance with the License.
3+
//See the NOTICE file distributed with this work for additional
4+
//information regarding copyright ownership.
5+
//You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
//Unless required by applicable law or agreed to in writing, software
10+
//distributed under the License is distributed on an "AS IS" BASIS,
11+
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
//See the License for the specific language governing permissions and
13+
//limitations under the License.
14+
15+
using OpenQA.Selenium.Appium.Interfaces;
16+
using System.Collections.Generic;
17+
18+
namespace OpenQA.Selenium.Appium.iOS.Interfaces
19+
{
20+
public interface IHasSettings : IExecuteMethod
21+
{
22+
/// <summary>
23+
/// Set a setting for this test session It's probably better to use a
24+
/// convenience function, rather than use this function directly. Try finding
25+
/// the method for the specific setting you want to change.
26+
/// </summary>
27+
/// <param name="setting">Setting you wish to set.</param>
28+
/// <param name="value">value of the setting.</param>
29+
void SetSetting(string setting, object value);
30+
31+
/// <summary>
32+
/// Gets/Sets settings stored for this test session.
33+
/// </summary>
34+
Dictionary<string, object> Settings { set; get; }
35+
}
36+
}

test/integration/IOS/SettingTest.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Appium.Net.Integration.Tests.helpers;
2+
using NUnit.Framework;
3+
using OpenQA.Selenium.Appium;
4+
using OpenQA.Selenium.Appium.iOS;
5+
6+
namespace Appium.Net.Integration.Tests.iOS
7+
{
8+
public class SettingTest
9+
{
10+
private IOSDriver<AppiumWebElement> _driver;
11+
12+
[OneTimeSetUp]
13+
public void BeforeAll()
14+
{
15+
var capabilities = Caps.GetIosCaps(Apps.Get("iosUICatalogApp"));
16+
var serverUri = Env.ServerIsRemote() ? AppiumServers.RemoteServerUri : AppiumServers.LocalServiceUri;
17+
_driver = new IOSDriver<AppiumWebElement>(serverUri, capabilities, Env.InitTimeoutSec);
18+
_driver.Manage().Timeouts().ImplicitWait = Env.ImplicitTimeoutSec;
19+
}
20+
21+
[OneTimeTearDown]
22+
public void AfterEach()
23+
{
24+
_driver?.Quit();
25+
if (!Env.ServerIsRemote())
26+
{
27+
AppiumServers.StopLocalService();
28+
}
29+
}
30+
31+
[Test]
32+
public void SettingsUpdateTest()
33+
{
34+
_driver.SetSetting(
35+
setting: "useJSONSource",
36+
value: true);
37+
38+
Assert.IsTrue((bool)_driver.Settings["useJSONSource"]);
39+
40+
_driver.SetSetting(
41+
setting: "useJSONSource",
42+
value: false);
43+
44+
Assert.IsFalse((bool)_driver.Settings["useJSONSource"]);
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)