diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationStartup.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationStartup.cs index 4c85cbd..98608ae 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationStartup.cs +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationStartup.cs @@ -26,8 +26,8 @@ public override IServiceCollection ConfigureServices(IServiceCollection services base.ConfigureServices(services, applicationProvider, settings); services.AddTransient(); services.AddTransient(); - services.AddSingleton(serviceProvider => new DriverSettings(settings)); - services.AddSingleton(serviceProvider => new ApplicationProfile(settings, serviceProvider.GetRequiredService())); + services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(serviceProvider => new LocalizationManager(serviceProvider.GetRequiredService(), serviceProvider.GetRequiredService(), Assembly.GetExecutingAssembly())); services.AddSingleton(serviceProvider => new KeyboardActions(serviceProvider.GetRequiredService(), () => AqualityServices.Application.Driver)); services.AddSingleton(serviceProvider => new MouseActions(serviceProvider.GetRequiredService(), () => AqualityServices.Application.Driver)); diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.csproj b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.csproj index 0daac36..3106d74 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.csproj +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.csproj @@ -46,7 +46,7 @@ - + diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Configurations/DriverSettings.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Configurations/DriverSettings.cs index 74b6abd..55f7aa0 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Configurations/DriverSettings.cs +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Configurations/DriverSettings.cs @@ -16,31 +16,32 @@ public class DriverSettings : IDriverSettings private const string ApplicationPathJPath = DriverSettingsPath + ".applicationPath"; private const string AppCapabilityKey = "app"; + private readonly ISettingsFile settingsFile; + /// /// Instantiates class using JSON file with general settings. /// /// JSON settings file. public DriverSettings(ISettingsFile settingsFile) { - SettingsFile = settingsFile; + this.settingsFile = settingsFile; } - protected ISettingsFile SettingsFile { get; } - - protected IDictionary Capabilities => SettingsFile.GetValueOrNew>($"{DriverSettingsPath}.capabilities"); - + protected virtual IDictionary Capabilities => settingsFile.GetValueOrNew>($"{DriverSettingsPath}.capabilities"); + /// /// Defines does the current settings have the application path defined /// - protected bool HasApplicationPath => SettingsFile.IsValuePresent(ApplicationPathJPath); + protected virtual bool HasApplicationPath => settingsFile.IsValuePresent(ApplicationPathJPath) || Capabilities.ContainsKey(AppCapabilityKey); - public AppiumOptions AppiumOptions + + public virtual AppiumOptions AppiumOptions { get { var options = new AppiumOptions(); Capabilities.ToList().ForEach(capability => options.AddAdditionalCapability(capability.Key, capability.Value)); - if (HasApplicationPath) + if (HasApplicationPath && ApplicationPath != null) { options.AddAdditionalCapability(AppCapabilityKey, ApplicationPath); } @@ -48,6 +49,14 @@ public AppiumOptions AppiumOptions } } - public string ApplicationPath => Path.GetFullPath(SettingsFile.GetValue(ApplicationPathJPath)); + public virtual string ApplicationPath + { + get + { + var appValue = settingsFile.GetValueOrDefault(ApplicationPathJPath, + defaultValue: (Capabilities.ContainsKey(AppCapabilityKey) ? Capabilities[AppCapabilityKey] : null)?.ToString()); + return appValue?.StartsWith(".") == true ? Path.GetFullPath(appValue) : appValue; + } + } } } diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Resources/settings.json b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Resources/settings.json index e0937c5..77976a9 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Resources/settings.json +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Resources/settings.json @@ -2,8 +2,8 @@ "isRemote": true, "remoteConnectionUrl": "http://127.0.0.1:4723/", "driverSettings": { - "applicationPath": "./Resources/Applications/Day Maxi Calc.exe", "capabilities": { + "app": "./Resources/Applications/Day Maxi Calc.exe", "platformVersion": "10", "platformName": "Windows", "deviceName": "WindowsPC", diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Aquality.WinAppDriver.Tests.csproj b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Aquality.WinAppDriver.Tests.csproj index 269429c..9ccc187 100644 --- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Aquality.WinAppDriver.Tests.csproj +++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Aquality.WinAppDriver.Tests.csproj @@ -12,7 +12,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Resources/settings.json b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Resources/settings.json index e47d448..d3cae0b 100644 --- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Resources/settings.json +++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Resources/settings.json @@ -2,8 +2,8 @@ "isRemote": true, "remoteConnectionUrl": "http://127.0.0.1:4723/", "driverSettings": { - "applicationPath": "./Resources/Applications/Day Maxi Calc.exe", "capabilities": { + "app": "./Resources/Applications/Day Maxi Calc.exe", "platformVersion": "10", "platformName": "Windows", "deviceName": "WindowsPC",