-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement device settings [+semver: feature] (#21)
* Implement device settings * Fix pipeline and review comment * Fix tests * Change android emulator in pipeline * Change Android emulator in pipeline * Change android sdk id for emulator * Update pipeline
- Loading branch information
Showing
14 changed files
with
290 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 12 additions & 1 deletion
13
Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Aquality.Appium.Mobile.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Configurations/DeviceSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Aquality.Selenium.Core.Configurations; | ||
using Aquality.Selenium.Core.Logging; | ||
using Aquality.Selenium.Core.Utilities; | ||
using OpenQA.Selenium.Appium; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Aquality.Appium.Mobile.Configurations | ||
{ | ||
public class DeviceSettings : IDeviceSettings | ||
{ | ||
private readonly ISettingsFile settingsFile; | ||
private readonly string deviceKey; | ||
|
||
public DeviceSettings(string deviceKey) | ||
{ | ||
settingsFile = GetDevicesSettings(); | ||
this.deviceKey = deviceKey; | ||
} | ||
|
||
private ISettingsFile GetDevicesSettings() | ||
{ | ||
var deviceProfileName = EnvironmentConfiguration.GetVariable("devicesProfile"); | ||
var devicesProfile = deviceProfileName == null | ||
? "devices.json" | ||
: $"devices.{deviceProfileName}.json"; | ||
Logger.Instance.Debug($"Get devices settings from: {devicesProfile}"); | ||
return new JsonSettingsFile(devicesProfile); | ||
} | ||
|
||
public AppiumOptions AppiumOptions | ||
{ | ||
get | ||
{ | ||
var deviceOptions = new AppiumOptions(); | ||
Capabilities.ToList().ForEach(capability => deviceOptions.AddAdditionalCapability(capability.Key, capability.Value)); | ||
return deviceOptions; | ||
} | ||
} | ||
|
||
private IDictionary<string, object> Capabilities => settingsFile.GetValueOrNew<Dictionary<string, object>>($"{deviceKey}.capabilities"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Configurations/IDeviceSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using OpenQA.Selenium.Appium; | ||
|
||
namespace Aquality.Appium.Mobile.Configurations | ||
{ | ||
/// <summary> | ||
/// Describes desired device settings. | ||
/// </summary> | ||
public interface IDeviceSettings | ||
{ | ||
/// <summary> | ||
/// Options (capabilities) related to desired device. | ||
/// </summary> | ||
AppiumOptions AppiumOptions { get; } | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Aquality.Appium.Mobile/src/Aquality.Appium.Mobile/Resources/devices.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"iOS_Simulator": { | ||
"capabilities": { | ||
"platformVersion": "<iOS_platform_version>", | ||
"deviceName": "<iOS_simulator_name>" | ||
} | ||
}, | ||
"iPhone_NAME": { | ||
"capabilities": { | ||
"platformVersion": "<iOS_platform_version>", | ||
"deviceName": "<iOS_device_name>", | ||
"udid": "<iOS_device_udidi>", | ||
"wdaLocalPort": "<wda_local_port>" | ||
} | ||
}, | ||
"Android_Emulator": { | ||
"capabilities": { | ||
"deviceName": "<Android_emulator_name>" | ||
} | ||
}, | ||
"Android_NAME": { | ||
"capabilities": { | ||
"deviceName": "<Android_device_name>", | ||
"udid": "<Android_device_udid>", | ||
"systemPort": "<appium_system_port>" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
Aquality.Appium.Mobile/tests/Aquality.Appium.Mobile.Tests/Integration/DeviceSettingsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using Aquality.Appium.Mobile.Applications; | ||
using Aquality.Appium.Mobile.Configurations; | ||
using Castle.Core.Internal; | ||
using NUnit.Framework; | ||
using System; | ||
|
||
namespace Aquality.Appium.Mobile.Tests.Integration | ||
{ | ||
public class DeviceSettingsTests | ||
{ | ||
private const string PlatformNamePropertyKey = "platformName"; | ||
private const string DevicesProfilePropertyKey = "devicesProfile"; | ||
private const string DevicesKeyPropertyKey = "driverSettings.android.deviceKey"; | ||
|
||
[Test] | ||
public void Should_BePossible_ToGetDeviceCapabilities() | ||
{ | ||
var deviceSettings = new DeviceSettings("iPhone_11"); | ||
var options = deviceSettings.AppiumOptions; | ||
Assert.IsNotNull(options); | ||
Assert.IsFalse(options.ToDictionary().IsNullOrEmpty()); | ||
} | ||
|
||
[Test] | ||
public void Should_BePossible_ToGetEmptyCapabilitiesWhenDeviceKeyIsNull() | ||
{ | ||
var deviceSettings = new DeviceSettings(null); | ||
var options = deviceSettings.AppiumOptions; | ||
Assert.IsNotNull(options); | ||
Assert.IsTrue(options.ToDictionary().IsNullOrEmpty()); | ||
} | ||
|
||
[Test] | ||
public void Should_BePossible_ToUseDifferentDevicesProfiles() | ||
{ | ||
Environment.SetEnvironmentVariable(DevicesProfilePropertyKey, "test"); | ||
var deviceSettings = new DeviceSettings("iPhone_11"); | ||
var options = deviceSettings.AppiumOptions; | ||
Assert.AreEqual("iPhone 11 test", options.ToDictionary()["deviceName"]); | ||
|
||
Environment.SetEnvironmentVariable(DevicesProfilePropertyKey, null); | ||
deviceSettings = new DeviceSettings("iPhone_11"); | ||
options = deviceSettings.AppiumOptions; | ||
Assert.AreEqual("iPhone 11", options.ToDictionary()["deviceName"]); | ||
} | ||
|
||
[Test] | ||
public void Should_BePossible_ToGetDefaultDeviceSettingsForIosPlatform() | ||
{ | ||
Environment.SetEnvironmentVariable(PlatformNamePropertyKey, "ios"); | ||
Environment.SetEnvironmentVariable(DevicesKeyPropertyKey, "iPhone_11"); | ||
var options = AqualityServices.Get<IApplicationProfile>().DriverSettings.AppiumOptions; | ||
Assert.AreEqual("iPhone 11", options.ToDictionary()["deviceName"]); | ||
} | ||
|
||
[Test] | ||
public void Should_BePossible_ToGetDefaultDeviceSettingsForAndroidPlatform() | ||
{ | ||
Environment.SetEnvironmentVariable(PlatformNamePropertyKey, "android"); | ||
Environment.SetEnvironmentVariable(DevicesKeyPropertyKey, "Nexus"); | ||
var options = AqualityServices.Get<IApplicationProfile>().DriverSettings.AppiumOptions; | ||
Assert.AreEqual("Nexus", options.ToDictionary()["deviceName"]); | ||
} | ||
|
||
[Test] | ||
public void Should_BePossible_ToOverrideDefaultDevice() | ||
{ | ||
Environment.SetEnvironmentVariable(PlatformNamePropertyKey, "android"); | ||
Environment.SetEnvironmentVariable(DevicesKeyPropertyKey, "Samsung_Galaxy"); | ||
var options = AqualityServices.Get<IApplicationProfile>().DriverSettings.AppiumOptions; | ||
Assert.AreEqual("Samsung Galaxy", options.ToDictionary()["deviceName"]); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
Environment.SetEnvironmentVariable(PlatformNamePropertyKey, null); | ||
Environment.SetEnvironmentVariable(DevicesProfilePropertyKey, null); | ||
Environment.SetEnvironmentVariable(DevicesKeyPropertyKey, null); | ||
AqualityServices.SetStartup(new MobileStartup()); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Aquality.Appium.Mobile/tests/Aquality.Appium.Mobile.Tests/Resources/devices.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"iOS_Simulator": { | ||
"capabilities": { | ||
"platformVersion": "13.3", | ||
"deviceName": "iPhone 11" | ||
} | ||
}, | ||
"iPhone_11": { | ||
"capabilities": { | ||
"platformVersion": "13.3", | ||
"deviceName": "iPhone 11", | ||
"udid": "device_udid", | ||
"wdaLocalPort": "8081" | ||
} | ||
}, | ||
"Android_Emulator": { | ||
"capabilities": { | ||
"deviceName": "Android Emulator" | ||
} | ||
}, | ||
"Nexus": { | ||
"capabilities": { | ||
"deviceName": "Nexus", | ||
"udid": "device_udid", | ||
"systemPort": "8082" | ||
} | ||
}, | ||
"Samsung_Galaxy": { | ||
"capabilities": { | ||
"deviceName": "Samsung Galaxy", | ||
"udid": "device_udid", | ||
"systemPort": "8082" | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Aquality.Appium.Mobile/tests/Aquality.Appium.Mobile.Tests/Resources/devices.test.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"iPhone_11": { | ||
"capabilities": { | ||
"platformVersion": "13.3", | ||
"deviceName": "iPhone 11 test", | ||
"udid": "device_udid", | ||
"wdaLocalPort": "8085" | ||
} | ||
}, | ||
"Nexus": { | ||
"capabilities": { | ||
"deviceName": "Nexus test", | ||
"udid": "device_udid", | ||
"systemPort": "8082" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.