diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/Application.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/Application.cs
index 4470a57..4330263 100644
--- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/Application.cs
+++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/Application.cs
@@ -3,7 +3,6 @@
using Aquality.Selenium.Core.Configurations;
using Aquality.Selenium.Core.Localization;
using Aquality.WinAppDriver.Actions;
-using Microsoft.Extensions.DependencyInjection;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Remote;
@@ -25,15 +24,14 @@ public class Application : IWindowsApplication
///
/// Function to create an instance of WinAppDriver for current application
/// Function to create an instance of WinAppDriver for desktop session
- /// Service provider to resolve all dependencies from DI container
- public Application(Func> createApplicationSession, Func> createRootSession, IServiceProvider serviceProvider)
+ public Application(Func> createApplicationSession, Func> createRootSession)
{
this.createApplicationSession = createApplicationSession;
this.createDesktopSession = createRootSession;
- Logger = serviceProvider.GetRequiredService();
- KeyboardActions = serviceProvider.GetRequiredService();
- MouseActions = serviceProvider.GetRequiredService();
- var timeoutConfiguration = serviceProvider.GetRequiredService();
+ Logger = AqualityServices.LocalizedLogger;
+ KeyboardActions = AqualityServices.KeyboardActions;
+ MouseActions = AqualityServices.MouseActions;
+ var timeoutConfiguration = AqualityServices.Get();
implicitWait = timeoutConfiguration.Implicit;
}
diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationFactory.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationFactory.cs
index c97c707..5ef47ea 100644
--- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationFactory.cs
+++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationFactory.cs
@@ -1,7 +1,6 @@
using Aquality.Selenium.Core.Configurations;
using Aquality.Selenium.Core.Localization;
using Aquality.WinAppDriver.Configurations;
-using Microsoft.Extensions.DependencyInjection;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using System;
@@ -14,21 +13,19 @@ public abstract class ApplicationFactory : IApplicationFactory
protected ILocalizedLogger LocalizedLogger { get; }
protected IDriverSettings DriverSettings { get; }
- protected IServiceProvider ServiceProvider { get; }
- protected ApplicationFactory(IServiceProvider serviceProvider)
+ protected ApplicationFactory()
{
- LocalizedLogger = serviceProvider.GetRequiredService();
- DriverSettings = serviceProvider.GetRequiredService();
- timeoutConfiguration = serviceProvider.GetRequiredService();
- ServiceProvider = serviceProvider;
+ LocalizedLogger = AqualityServices.LocalizedLogger;
+ DriverSettings = AqualityServices.Get();
+ timeoutConfiguration = AqualityServices.Get();
}
public abstract Application Application { get; }
protected virtual Application GetApplication(Uri driverServerUri)
{
- return new Application(() => GetApplicationSession(driverServerUri), () => GetRootSession(driverServerUri), ServiceProvider);
+ return new Application(() => GetApplicationSession(driverServerUri), () => GetRootSession(driverServerUri));
}
protected virtual WindowsDriver GetApplicationSession(Uri driverServerUri)
diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationStartup.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationStartup.cs
index 12b6d2e..2a26426 100644
--- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationStartup.cs
+++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationStartup.cs
@@ -29,9 +29,9 @@ public override IServiceCollection ConfigureServices(IServiceCollection services
services.AddSingleton(serviceProvider => new DriverSettings(settings));
services.AddSingleton(serviceProvider => new ApplicationProfile(settings, serviceProvider.GetRequiredService()));
services.AddSingleton(serviceProvider => new LocalizationManager(serviceProvider.GetRequiredService(), serviceProvider.GetRequiredService(), Assembly.GetExecutingAssembly()));
- services.AddSingleton(serviceProvider => new KeyboardActions(serviceProvider.GetRequiredService(), () => ApplicationManager.Application.Driver));
- services.AddSingleton(serviceProvider => new MouseActions(serviceProvider.GetRequiredService(), () => ApplicationManager.Application.Driver));
- services.AddTransient(serviceProvider => ApplicationManager.ApplicationFactory);
+ services.AddSingleton(serviceProvider => new KeyboardActions(serviceProvider.GetRequiredService(), () => AqualityServices.Application.Driver));
+ services.AddSingleton(serviceProvider => new MouseActions(serviceProvider.GetRequiredService(), () => AqualityServices.Application.Driver));
+ services.AddTransient(serviceProvider => AqualityServices.ApplicationFactory);
services.AddTransient();
services.AddTransient();
return services;
diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationManager.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/AqualityServices.cs
similarity index 71%
rename from Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationManager.cs
rename to Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/AqualityServices.cs
index 17e821f..d5b43ae 100644
--- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationManager.cs
+++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/AqualityServices.cs
@@ -1,31 +1,68 @@
-using Aquality.Selenium.Core.Configurations;
-using System;
+using System;
using Microsoft.Extensions.DependencyInjection;
using Aquality.Selenium.Core.Localization;
-using CoreElementFactory = Aquality.Selenium.Core.Elements.Interfaces.IElementFactory;
-using Aquality.WinAppDriver.Elements.Interfaces;
-using Aquality.WinAppDriver.Elements;
using Aquality.Selenium.Core.Applications;
using System.Threading;
using Aquality.WinAppDriver.Configurations;
using OpenQA.Selenium.Appium.Service;
using Aquality.Selenium.Core.Logging;
-using System.Reflection;
-using Aquality.WinAppDriver.Actions;
-using Aquality.WinAppDriver.Utilities;
using OpenQA.Selenium.Appium.Windows;
+using Aquality.Selenium.Core.Waitings;
+using Aquality.WinAppDriver.Utilities;
+using Aquality.WinAppDriver.Actions;
namespace Aquality.WinAppDriver.Applications
{
///
/// Controls application and Aquality services
///
- public class ApplicationManager : ApplicationManager
+ public class AqualityServices : AqualityServices
{
private static readonly ThreadLocal ApplicationStartupContainer = new ThreadLocal(() => new ApplicationStartup());
private static readonly ThreadLocal ApplicationFactoryContainer = new ThreadLocal();
private static readonly ThreadLocal AppiumLocalServiceContainer = new ThreadLocal(AppiumLocalService.BuildDefaultService);
+ ///
+ /// Check if application already started.
+ ///
+ /// true if application started and false otherwise.
+ public new static bool IsApplicationStarted => IsApplicationStarted();
+
+ ///
+ /// Gets registered instance of localized logger
+ ///
+ public static ILocalizedLogger LocalizedLogger => Get();
+
+ ///
+ /// Gets registered instance of Logger
+ ///
+ public static Logger Logger => Get();
+
+ ///
+ /// Gets ConditionalWait object
+ ///
+ public static ConditionalWait ConditionalWait => Get();
+
+ ///
+ /// Gets KeyboardActions object
+ ///
+ public static IKeyboardActions KeyboardActions => Get();
+
+ ///
+ /// Gets MouseActions object
+ ///
+ public static IMouseActions MouseActions => Get();
+
+ ///
+ /// Gets WinAppDriverLauncher object
+ ///
+ public static IWinAppDriverLauncher WinAppDriverLauncher => Get();
+
+ ///
+ /// Gets ProcessManager object
+ ///
+ public static IProcessManager ProcessManager => Get();
+
///
/// Stops appium local service.
///
@@ -34,7 +71,7 @@ public static bool TryToStopAppiumLocalService()
{
if(AppiumLocalServiceContainer.IsValueCreated && AppiumLocalServiceContainer.Value.IsRunning)
{
- GetRequiredService().Info("loc.application.driver.service.local.stop");
+ Get().Info("loc.application.driver.service.local.stop");
AppiumLocalServiceContainer.Value.Dispose();
return true;
}
@@ -49,16 +86,7 @@ public static Application Application
{
get => GetApplication(StartApplicationFunction, ConfigureServices);
set => SetApplication(value);
- }
-
- ///
- /// Provides access to Aquality services, registered in DI container.
- ///
- public static IServiceProvider ServiceProvider
- {
- get => GetServiceProvider(services => Application, ConfigureServices);
- set => SetServiceProvider(value);
- }
+ }
///
/// Method which allow user to override or add custom services.
@@ -95,7 +123,7 @@ public static IApplicationFactory ApplicationFactory
/// type of required service
/// Thrown if there is no service of the required type.
///
- public static T GetRequiredService()
+ public static T Get()
{
return ServiceProvider.GetRequiredService();
}
@@ -106,15 +134,15 @@ public static T GetRequiredService()
///
public static void SetDefaultFactory()
{
- var appProfile = GetRequiredService();
+ var appProfile = Get();
IApplicationFactory applicationFactory;
if (appProfile.IsRemote)
{
- applicationFactory = new RemoteApplicationFactory(appProfile.RemoteConnectionUrl, ServiceProvider);
+ applicationFactory = new RemoteApplicationFactory(appProfile.RemoteConnectionUrl);
}
else
{
- applicationFactory = new LocalApplicationFactory(AppiumLocalServiceContainer.Value, ServiceProvider);
+ applicationFactory = new LocalApplicationFactory(AppiumLocalServiceContainer.Value);
}
ApplicationFactory = applicationFactory;
@@ -126,11 +154,13 @@ public static void SetDefaultFactory()
/// Function to get window handle via RootSession of Application
public static void SetWindowHandleApplicationFactory(Func, string> getWindowHandleFunction)
{
- var appProfile = GetRequiredService();
+ var appProfile = Get();
var serviceUri = appProfile.IsRemote ? appProfile.RemoteConnectionUrl : AppiumLocalServiceContainer.Value.ServiceUrl;
- ApplicationFactory = new WindowHandleApplicationFactory(serviceUri, ServiceProvider, getWindowHandleFunction);
+ ApplicationFactory = new WindowHandleApplicationFactory(serviceUri, getWindowHandleFunction);
}
+ private static IServiceProvider ServiceProvider => GetServiceProvider(services => Application, ConfigureServices);
+
private static Func StartApplicationFunction
{
get
diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/LocalApplicationFactory.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/LocalApplicationFactory.cs
index 83687c8..25f8c5a 100644
--- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/LocalApplicationFactory.cs
+++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/LocalApplicationFactory.cs
@@ -7,8 +7,7 @@ public class LocalApplicationFactory : ApplicationFactory
{
private readonly AppiumLocalService driverService;
- public LocalApplicationFactory(AppiumLocalService driverService, IServiceProvider serviceProvider)
- : base(serviceProvider)
+ public LocalApplicationFactory(AppiumLocalService driverService) : base()
{
this.driverService = driverService;
}
@@ -20,7 +19,7 @@ public override Application Application
driverService.Start();
var serviceUrl = driverService.ServiceUrl;
LocalizedLogger.Info("loc.application.driver.service.local.start", serviceUrl);
- return new Application(() => GetApplicationSession(serviceUrl), () => GetRootSession(serviceUrl), ServiceProvider);
+ return new Application(() => GetApplicationSession(serviceUrl), () => GetRootSession(serviceUrl));
}
}
}
diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/RemoteApplicationFactory.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/RemoteApplicationFactory.cs
index b7a6868..cdfb64e 100644
--- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/RemoteApplicationFactory.cs
+++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/RemoteApplicationFactory.cs
@@ -9,8 +9,7 @@ public class RemoteApplicationFactory : ApplicationFactory
{
private readonly Uri driverServerUri;
- public RemoteApplicationFactory(Uri driverServerUri, IServiceProvider serviceProvider)
- : base(serviceProvider)
+ public RemoteApplicationFactory(Uri driverServerUri) : base()
{
this.driverServerUri = driverServerUri;
}
diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/WindowHandleApplicationFactory.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/WindowHandleApplicationFactory.cs
index 2e26f28..c0164e6 100644
--- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/WindowHandleApplicationFactory.cs
+++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/WindowHandleApplicationFactory.cs
@@ -1,5 +1,4 @@
using Aquality.WinAppDriver.Configurations;
-using Microsoft.Extensions.DependencyInjection;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Remote;
@@ -15,12 +14,12 @@ public class WindowHandleApplicationFactory : ApplicationFactory
private readonly Func, string> getWindowHandleFunction;
private readonly bool isRemote;
- public WindowHandleApplicationFactory(Uri driverServerUri, IServiceProvider serviceProvider, Func, string> getWindowHandleFunction)
- : base(serviceProvider)
+ public WindowHandleApplicationFactory(Uri driverServerUri, Func, string> getWindowHandleFunction)
+ : base()
{
this.driverServerUri = driverServerUri;
this.getWindowHandleFunction = getWindowHandleFunction;
- isRemote = serviceProvider.GetRequiredService().IsRemote;
+ isRemote = AqualityServices.Get().IsRemote;
}
public override Application Application
diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.csproj b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.csproj
index 5b5a0d7..54c9888 100644
--- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.csproj
+++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.csproj
@@ -45,8 +45,8 @@
-
-
+
+
diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.xml b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.xml
index 6c4d5f8..e8d86a8 100644
--- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.xml
+++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.xml
@@ -333,7 +333,7 @@
- Instantiates Aplication actions.
+ Instantiates Application actions.
Logger for localized values.
Method to get current application session.
@@ -495,13 +495,12 @@
Provides functionality to work with Windows application via WinAppDriver.
-
+
Instantiate application.
Function to create an instance of WinAppDriver for current application
Function to create an instance of WinAppDriver for desktop session
- Service provider to resolve all dependencies from DI container
@@ -515,63 +514,99 @@
Quit application.
-
+
+
+ Provides functionality to register services
+
+
+
Controls application and Aquality services
-
+
- Stops appium local service.
+ Check if application already started.
- True if service was running, false otherwise
+ true if application started and false otherwise.
-
+
- Provides current instance of application
+ Gets registered instance of localized logger
-
+
- Provides access to Aquality services, registered in DI container.
+ Gets registered instance of Logger
-
+
+
+ Gets ConditionalWait object
+
+
+
+
+ Gets KeyboardActions object
+
+
+
+
+ Gets MouseActions object
+
+
+
+
+ Gets WinAppDriverLauncher object
+
+
+
+
+ Gets ProcessManager object
+
+
+
+
+ Stops appium local service.
+
+ True if service was running, false otherwise
+
+
+
+ Provides current instance of application
+
+
+
Method which allow user to override or add custom services.
> object with custom or overriden services.
-
+
Factory for application creation.
-
+
- Resolves required service from
+ Resolves required service from
type of required service
Thrown if there is no service of the required type.
-
+
Sets default factory responsible for application creation.
RemoteApplicationFactory if value set in configuration and LocalApplicationFactory otherwise.
-
+
Sets window handle factory, which attaches to already running application by it's window handle
Function to get window handle via RootSession of Application
-
-
- Provides functionality to register services
-
-
Provides instance of Windows Driver for current application
diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Elements/Element.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Elements/Element.cs
index fb325fd..a870975 100644
--- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Elements/Element.cs
+++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Elements/Element.cs
@@ -20,24 +20,24 @@ protected Element(By locator, string name, ElementState elementState = ElementSt
{
}
- protected override ElementActionRetrier ActionRetrier => ApplicationManager.GetRequiredService();
+ protected override ElementActionRetrier ActionRetrier => AqualityServices.Get();
- protected override IApplication Application => ApplicationManager.Application;
+ protected override IApplication Application => AqualityServices.Application;
- protected override ConditionalWait ConditionalWait => ApplicationManager.GetRequiredService();
+ protected override ConditionalWait ConditionalWait => AqualityServices.ConditionalWait;
protected override CoreElementFactory Factory => CustomFactory;
- protected virtual IElementFactory CustomFactory => ApplicationManager.GetRequiredService();
+ protected virtual IElementFactory CustomFactory => AqualityServices.Get();
public virtual IKeyboardActions KeyboardActions => new KeyboardActions(this, ElementType, () => Application, LocalizedLogger, ActionRetrier);
public virtual IMouseActions MouseActions => new MouseActions(this, ElementType, () => Application, LocalizedLogger, ActionRetrier);
- protected override CoreElementFinder Finder => ApplicationManager.GetRequiredService();
+ protected override CoreElementFinder Finder => AqualityServices.Get();
- protected override ILocalizedLogger LocalizedLogger => ApplicationManager.GetRequiredService();
+ protected override ILocalizedLogger LocalizedLogger => AqualityServices.LocalizedLogger;
- protected ILocalizationManager LocalizationManager => ApplicationManager.GetRequiredService();
+ protected ILocalizationManager LocalizationManager => AqualityServices.Get();
}
}
diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Windows/Window.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Windows/Window.cs
index 0a33563..27b2f50 100644
--- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Windows/Window.cs
+++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Windows/Window.cs
@@ -26,7 +26,7 @@ protected Window(By locator, string name) : base(locator, name)
/// Element factory
///
/// Element factory.
- protected IElementFactory ElementFactory => ApplicationManager.GetRequiredService();
+ protected IElementFactory ElementFactory => AqualityServices.Get();
///
/// Finds element relative to current window.
diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/KeyboardActionsTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/KeyboardActionsTests.cs
index 7d3380a..a99c656 100644
--- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/KeyboardActionsTests.cs
+++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/KeyboardActionsTests.cs
@@ -11,7 +11,7 @@ public class KeyboardActionsTests : TestWithApplication
{
private const string ValueToSend = "abc";
- protected virtual IKeyboardActions KeyboardActions => ApplicationManager.GetRequiredService();
+ protected virtual IKeyboardActions KeyboardActions => AqualityServices.KeyboardActions;
protected ITextBox RightArgumentTextBox => new CalculatorWindow().RightArgumentTextBox;
diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/MouseActionsTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/MouseActionsTests.cs
index 80177b3..06cda4d 100644
--- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/MouseActionsTests.cs
+++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/MouseActionsTests.cs
@@ -8,7 +8,7 @@ namespace Aquality.WinAppDriver.Tests.Actions
{
public class MouseActionsTests : TestWithApplication
{
- protected virtual IMouseActions MouseActions => ApplicationManager.GetRequiredService();
+ protected virtual IMouseActions MouseActions => AqualityServices.MouseActions;
protected ITextBox RightArgumentTextBox => new CalculatorWindow().RightArgumentTextBox;
diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/ApplicationManagerTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/ApplicationManagerTests.cs
deleted file mode 100644
index 40ad5e2..0000000
--- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/ApplicationManagerTests.cs
+++ /dev/null
@@ -1,91 +0,0 @@
-using Aquality.Selenium.Core.Applications;
-using Aquality.Selenium.Core.Elements.Interfaces;
-using Aquality.WinAppDriver.Applications;
-using Aquality.WinAppDriver.Tests.Windows;
-using Microsoft.Extensions.DependencyInjection;
-using NUnit.Framework;
-
-namespace Aquality.WinAppDriver.Tests.Applications
-{
- public class ApplicationManagerTests : TestWithApplication
- {
- private readonly CalculatorWindow calculatorWindow = new CalculatorWindow();
-
- [Test]
- public void Should_WorkWithCalculator()
- {
- ApplicationManager.Application.Driver.FindElement(calculatorWindow.OneButton.Locator).Click();
- ApplicationManager.Application.Driver.FindElement(calculatorWindow.PlusButton.Locator).Click();
- ApplicationManager.Application.Driver.FindElement(calculatorWindow.TwoButton.Locator).Click();
- ApplicationManager.Application.Driver.FindElement(calculatorWindow.EqualsButton.Locator).Click();
- var result = ApplicationManager.Application.Driver.FindElement(calculatorWindow.ResultsLabel.Locator).Text;
- StringAssert.Contains("3", result);
- }
-
- [Test]
- public void Should_WorkWithCalculator_ViaElementFinder()
- {
- ApplicationManager.GetRequiredService().FindElement(calculatorWindow.OneButton.Locator).Click();
- ApplicationManager.GetRequiredService().FindElement(calculatorWindow.PlusButton.Locator).Click();
- ApplicationManager.GetRequiredService().FindElement(calculatorWindow.TwoButton.Locator).Click();
- ApplicationManager.GetRequiredService().FindElement(calculatorWindow.EqualsButton.Locator).Click();
- var result = ApplicationManager.GetRequiredService().FindElement(calculatorWindow.ResultsLabel.Locator).Text;
- StringAssert.Contains("3", result);
- }
-
- [Test]
- public void Should_GetCurrentApplicationFactory_AfterSetDefaultFactory()
- {
- var firstFactory = ApplicationManager.GetRequiredService();
- ApplicationManager.SetDefaultFactory();
- var secondFactory = ApplicationManager.GetRequiredService();
- Assert.AreNotSame(firstFactory, secondFactory);
- ApplicationManager.ApplicationFactory = firstFactory;
- Assert.AreSame(firstFactory, ApplicationManager.GetRequiredService());
- Assert.AreNotSame(secondFactory, ApplicationManager.GetRequiredService());
- }
-
- [Test]
- public void Should_GetCurrentApplication_AfterSetApplication()
- {
- IApplication firstApplication;
- using(var scope = ApplicationManager.ServiceProvider.CreateScope())
- {
- firstApplication = scope.ServiceProvider.GetRequiredService();
- }
-
- // Creating a second instance of Application
- ApplicationManager.Application = ApplicationManager.ApplicationFactory.Application;
-
- using (var scope = ApplicationManager.ServiceProvider.CreateScope())
- {
- var secondApplication = scope.ServiceProvider.GetRequiredService();
- Assert.AreNotSame(firstApplication, secondApplication);
- secondApplication.Driver.Quit();
- }
-
- // Switching back to a first instance of Application
- ApplicationManager.Application = firstApplication as Application;
-
- using (var scope = ApplicationManager.ServiceProvider.CreateScope())
- {
- Assert.AreSame(firstApplication, scope.ServiceProvider.GetRequiredService());
- }
- }
-
- [Test]
- public void Should_GetCurrentApplication_AfterQuit()
- {
- var firstApplication = ApplicationManager.Application;
- firstApplication.Quit();
- var secondApplication = ApplicationManager.Application;
- Assert.AreNotSame(firstApplication, secondApplication);
- using (var scope = ApplicationManager.ServiceProvider.CreateScope())
- {
- var secondApplicationFromServiceProvider = scope.ServiceProvider.GetRequiredService();
- Assert.AreNotSame(firstApplication, secondApplicationFromServiceProvider);
- Assert.AreSame(secondApplication, secondApplicationFromServiceProvider);
- }
- }
- }
-}
diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/AqualityServicesTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/AqualityServicesTests.cs
new file mode 100644
index 0000000..b661478
--- /dev/null
+++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/AqualityServicesTests.cs
@@ -0,0 +1,152 @@
+using Aquality.Selenium.Core.Applications;
+using Aquality.Selenium.Core.Elements.Interfaces;
+using Aquality.WinAppDriver.Applications;
+using Aquality.WinAppDriver.Tests.Windows;
+using Microsoft.Extensions.DependencyInjection;
+using NUnit.Framework;
+using System;
+
+namespace Aquality.WinAppDriver.Tests.Applications
+{
+ public class AqualityServicesTests : TestWithApplication
+ {
+ private readonly CalculatorWindow calculatorWindow = new CalculatorWindow();
+
+ [Test]
+ public void Should_WorkWithCalculator()
+ {
+ AqualityServices.Application.Driver.FindElement(calculatorWindow.OneButton.Locator).Click();
+ AqualityServices.Application.Driver.FindElement(calculatorWindow.PlusButton.Locator).Click();
+ AqualityServices.Application.Driver.FindElement(calculatorWindow.TwoButton.Locator).Click();
+ AqualityServices.Application.Driver.FindElement(calculatorWindow.EqualsButton.Locator).Click();
+ var result = AqualityServices.Application.Driver.FindElement(calculatorWindow.ResultsLabel.Locator).Text;
+ StringAssert.Contains("3", result);
+ }
+
+ [Test]
+ public void Should_WorkWithCalculator_ViaElementFinder()
+ {
+ AqualityServices.Get().FindElement(calculatorWindow.OneButton.Locator).Click();
+ AqualityServices.Get().FindElement(calculatorWindow.PlusButton.Locator).Click();
+ AqualityServices.Get().FindElement(calculatorWindow.TwoButton.Locator).Click();
+ AqualityServices.Get().FindElement(calculatorWindow.EqualsButton.Locator).Click();
+ var result = AqualityServices.Get().FindElement(calculatorWindow.ResultsLabel.Locator).Text;
+ StringAssert.Contains("3", result);
+ }
+
+ [Test]
+ public void Should_GetCurrentApplicationFactory_AfterSetDefaultFactory()
+ {
+ var firstFactory = AqualityServices.Get();
+ AqualityServices.SetDefaultFactory();
+ var secondFactory = AqualityServices.Get();
+ Assert.AreNotSame(firstFactory, secondFactory);
+ AqualityServices.ApplicationFactory = firstFactory;
+ Assert.AreSame(firstFactory, AqualityServices.Get());
+ Assert.AreNotSame(secondFactory, AqualityServices.Get());
+ }
+
+ [Test]
+ public void Should_GetCurrentApplication_AfterSetApplication()
+ {
+ IApplication firstApplication;
+ using (var scope = AqualityServices.Get().CreateScope())
+ {
+ firstApplication = scope.ServiceProvider.GetRequiredService();
+ }
+
+ // Creating a second instance of Application
+ AqualityServices.Application = AqualityServices.ApplicationFactory.Application;
+
+ using (var scope = AqualityServices.Get().CreateScope())
+ {
+ var secondApplication = scope.ServiceProvider.GetRequiredService();
+ Assert.AreNotSame(firstApplication, secondApplication);
+ secondApplication.Driver.Quit();
+ }
+
+ // Switching back to a first instance of Application
+ AqualityServices.Application = firstApplication as Application;
+
+ using (var scope = AqualityServices.Get().CreateScope())
+ {
+ Assert.AreSame(firstApplication, scope.ServiceProvider.GetRequiredService());
+ }
+ }
+
+ [Test]
+ public void Should_GetCurrentApplication_AfterQuit()
+ {
+ var firstApplication = AqualityServices.Application;
+ firstApplication.Quit();
+ var secondApplication = AqualityServices.Application;
+ Assert.AreNotSame(firstApplication, secondApplication);
+ using (var scope = AqualityServices.Get().CreateScope())
+ {
+ var secondApplicationFromServiceProvider = scope.ServiceProvider.GetRequiredService();
+ Assert.AreNotSame(firstApplication, secondApplicationFromServiceProvider);
+ Assert.AreSame(secondApplication, secondApplicationFromServiceProvider);
+ }
+ }
+
+ [Test]
+ public void Should_BeAbleGetApplication()
+ {
+ Assert.DoesNotThrow(() => AqualityServices.Application.Driver.Manage());
+ }
+
+ [Test]
+ [Parallelizable]
+ public void Should_BeAbleCheck_IsApplicationNotStarted()
+ {
+ Assert.IsFalse(AqualityServices.IsApplicationStarted, "Application is not started");
+ }
+
+ [Test]
+ public void Should_BeAbleCheck_IsApplicationStarted()
+ {
+ AqualityServices.Application.Driver.Manage();
+ Assert.IsTrue(AqualityServices.IsApplicationStarted, "Application is started");
+ }
+
+ [Test]
+ [Parallelizable]
+ public void Should_BeAbleToGet_Logger()
+ {
+ Assert.DoesNotThrow(() => AqualityServices.Logger.Info("message"), "Logger should not be null");
+ }
+
+ [Test]
+ [Parallelizable]
+ public void Should_BeAbleToGet_ConditionalWait()
+ {
+ Assert.DoesNotThrow(() => AqualityServices.ConditionalWait.WaitForTrue(() => true), "ConditionalWait should not be null");
+ }
+
+ [Test]
+ public void Should_BeAbleToGet_KeyboardActions()
+ {
+ Assert.DoesNotThrow(() => AqualityServices.KeyboardActions.SendKeys(WinAppDriver.Actions.ActionKey.Space), "KeyboardActions should not be null");
+ }
+
+ [Test]
+ public void Should_BeAbleToGet_MouseActions()
+ {
+ Assert.DoesNotThrow(() => AqualityServices.MouseActions.MoveByOffset(1,1), "MouseActions should not be null");
+ }
+
+ [Test]
+ [Parallelizable]
+ public void Should_BeAbleToGet_WinAppDriverLauncher()
+ {
+ Assert.IsNotNull(AqualityServices.WinAppDriverLauncher, "WinAppDriverLauncher should not be null");
+ }
+
+ [Test]
+ [Parallelizable]
+ public void Should_BeAbleToGet_ProcessManager()
+ {
+ Assert.DoesNotThrow(() => AqualityServices.ProcessManager.IsProcessRunning(string.Empty), "ProcessManager should not be null");
+ }
+ }
+}
diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/KeyboardActionsTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/KeyboardActionsTests.cs
index faaa143..568c42b 100644
--- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/KeyboardActionsTests.cs
+++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/KeyboardActionsTests.cs
@@ -5,6 +5,6 @@ namespace Aquality.WinAppDriver.Tests.Applications
{
public class KeyboardActionsTests : Actions.KeyboardActionsTests
{
- protected override IKeyboardActions KeyboardActions => ApplicationManager.Application.KeyboardActions;
+ protected override IKeyboardActions KeyboardActions => AqualityServices.Application.KeyboardActions;
}
}
diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/MouseActionsTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/MouseActionsTests.cs
index f92483a..039d6f6 100644
--- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/MouseActionsTests.cs
+++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/MouseActionsTests.cs
@@ -5,6 +5,6 @@ namespace Aquality.WinAppDriver.Tests.Applications
{
public class MouseActionsTests : Actions.MouseActionsTests
{
- protected override IMouseActions MouseActions => ApplicationManager.Application.MouseActions;
+ protected override IMouseActions MouseActions => AqualityServices.Application.MouseActions;
}
}
diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/WindowHandleApplicationFactoryTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/WindowHandleApplicationFactoryTests.cs
index 1d76757..567a7fd 100644
--- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/WindowHandleApplicationFactoryTests.cs
+++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/WindowHandleApplicationFactoryTests.cs
@@ -9,16 +9,16 @@ namespace Aquality.WinAppDriver.Tests.Applications
{
public class WindowHandleApplicationFactoryTests : TestWithApplication
{
- private IProcessManager ProcessManager => ApplicationManager.GetRequiredService();
- private string ApplicationPath => ApplicationManager.GetRequiredService().ApplicationPath;
+ private IProcessManager ProcessManager => AqualityServices.ProcessManager;
+ private string ApplicationPath => AqualityServices.Get().ApplicationPath;
[Test]
public void Should_BePossibleTo_SetWindowHandleApplicationFactory()
{
const string appName = "Day Maxi Calc v.1.5 Freeware";
ProcessManager.Start(ApplicationPath);
- ApplicationManager.SetWindowHandleApplicationFactory(
- rootSession => GetWindowHandle(rootSession.FindElementByName(appName)));
+
+ AqualityServices.SetWindowHandleApplicationFactory(rootSession => GetWindowHandle(rootSession, appName));
Assert.IsTrue(new CalculatorWindow().IsDisplayed);
}
@@ -26,7 +26,7 @@ public void Should_BePossibleTo_SetWindowHandleApplicationFactory()
public new void CleanUp()
{
base.CleanUp();
- ApplicationManager.SetDefaultFactory();
+ AqualityServices.SetDefaultFactory();
var executableName = ApplicationPath.Contains('\\') ? ApplicationPath.Substring(ApplicationPath.LastIndexOf('\\') + 1) : ApplicationPath;
ProcessManager.TryToStopExecutables(executableName);
}
@@ -35,9 +35,21 @@ public void Should_BePossibleTo_SetWindowHandleApplicationFactory()
/// returns window handle attribute, converted to HEX format
///
///
- public string GetWindowHandle(WindowsElement element)
+ private string GetWindowHandle(WindowsDriver webDriver, string appName)
{
- var nativeWindowHandle = element.GetAttribute("NativeWindowHandle");
+ AqualityServices.ConditionalWait.WaitForTrue(() =>
+ {
+ try
+ {
+ return webDriver.FindElementByName(appName) != null;
+ }
+ catch
+ {
+ return false;
+ }
+ });
+
+ var nativeWindowHandle = webDriver.FindElementByName(appName).GetAttribute("NativeWindowHandle");
return int.Parse(nativeWindowHandle).ToString("x");
}
}
diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementFactoryTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementFactoryTests.cs
index 9958a8c..9951c7c 100644
--- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementFactoryTests.cs
+++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementFactoryTests.cs
@@ -11,7 +11,7 @@ namespace Aquality.WinAppDriver.Tests.Elements
public class ElementFactoryTests : TestWithApplication
{
private static readonly CalculatorWindow calculatorWindow = new CalculatorWindow();
- private IElementFactory Factory => ApplicationManager.GetRequiredService();
+ private IElementFactory Factory => AqualityServices.Get();
[Test]
public void Should_WorkWithCalculator_ViaElementFactory()
diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementStateProviderTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementStateProviderTests.cs
index 818d61c..4b62d5c 100644
--- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementStateProviderTests.cs
+++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementStateProviderTests.cs
@@ -16,7 +16,7 @@ public class ElementStateProviderTests : TestWithApplication
private static readonly IButton EmptyButton = CalculatorWindow.EmptyButton;
private static readonly TimeSpan FromSeconds = TimeSpan.FromSeconds(5);
- private readonly IElement notPresentLabel = ApplicationManager.GetRequiredService()
+ private readonly IElement notPresentLabel = AqualityServices.Get()
.GetLabel(By.XPath("//*[@id='111111']"), "Not present element");
private static Stopwatch StartedStopwatch
diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementTests.cs
index 0ef4b04..b63bbae 100644
--- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementTests.cs
+++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementTests.cs
@@ -14,7 +14,7 @@ public class ElementTests : TestWithApplication
private static readonly By ElementLocator = By.XPath("//*[@id='111111']");
private const string ElementDescription = "Not present element";
- private IElementFactory Factory => ApplicationManager.GetRequiredService();
+ private IElementFactory Factory => AqualityServices.Get();
private IElement Label => Factory.GetLabel(ElementLocator, ElementDescription);
[Test]
diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Localization/LocalizationFilesTest.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Localization/LocalizationFilesTest.cs
index 8f0fb0e..844315e 100644
--- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Localization/LocalizationFilesTest.cs
+++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Localization/LocalizationFilesTest.cs
@@ -15,14 +15,14 @@ public class LocalizationFilesTest
{
private const string EnglishLanguageCode = "en";
private static readonly string[] SupportedLanguages = { "be", EnglishLanguageCode, "ru" };
- private static readonly Assembly LibraryAssembly = Assembly.GetAssembly(typeof(ApplicationManager));
+ private static readonly Assembly LibraryAssembly = Assembly.GetAssembly(typeof(AqualityServices));
private static readonly IList> LocalizationFileEnglishDictionary = GetLocalizationDictionaryAsList(EnglishLanguageCode);
private static readonly IEnumerable KeysWithoutParams = LocalizationFileEnglishDictionary.Where(pair => !pair.Value.Contains("{0}")).Select(pair => pair.Key);
private static readonly IEnumerable KeysWithOneParameter = LocalizationFileEnglishDictionary.Where(pair => pair.Value.Contains("{0}") && !pair.Value.Contains("{1}")).Select(pair => pair.Key);
private static readonly IEnumerable KeysWithTwoAndMoreParameters = LocalizationFileEnglishDictionary.Where(pair => pair.Value.Contains("{1}")).Select(pair => pair.Key);
private static readonly IEnumerable KeysWithParameters = LocalizationFileEnglishDictionary.Where(pair => pair.Value.Contains("{0}")).Select(pair => pair.Key);
- private ILocalizationManager LocalizationManager => ApplicationManager.GetRequiredService();
+ private ILocalizationManager LocalizationManager => AqualityServices.Get();
[Test]
public void Should_BePossibleTo_UseLocalizationManager_OnCustomLanguage_ForClicking()
diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/TestWithApplication.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/TestWithApplication.cs
index 9006f81..4f8fd5d 100644
--- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/TestWithApplication.cs
+++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/TestWithApplication.cs
@@ -1,38 +1,19 @@
using Aquality.WinAppDriver.Applications;
-using Aquality.WinAppDriver.Configurations;
-using Aquality.WinAppDriver.Utilities;
using NUnit.Framework;
-using System.Diagnostics;
namespace Aquality.WinAppDriver.Tests
{
[NonParallelizable]
public class TestWithApplication
{
- private Process winAppDriverProcess;
-
- [SetUp]
- public void SetUp()
- {
- if (ApplicationManager.GetRequiredService().IsRemote)
- {
- winAppDriverProcess =
- ApplicationManager.GetRequiredService().StartWinAppDriverIfRequired();
- }
- }
-
[TearDown]
public void CleanUp()
{
- if (ApplicationManager.IsApplicationStarted())
- {
- ApplicationManager.Application.Quit();
- }
- ApplicationManager.TryToStopAppiumLocalService();
- if (winAppDriverProcess != null)
+ if (AqualityServices.IsApplicationStarted)
{
- ApplicationManager.GetRequiredService().TryToStopWinAppDriver();
+ AqualityServices.Application.Quit();
}
+ AqualityServices.TryToStopAppiumLocalService();
}
}
}
diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Unit/Configuration/ConfigurationTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Unit/Configuration/ConfigurationTests.cs
index e5eabf8..c4991c9 100644
--- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Unit/Configuration/ConfigurationTests.cs
+++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Unit/Configuration/ConfigurationTests.cs
@@ -8,7 +8,6 @@
namespace Aquality.WinAppDriver.Tests.Unit.Configuration
{
[TestFixture]
- [Parallelizable(ParallelScope.All)]
internal class CustomConfigurationTests
{
private const string SpecialLoggerLanguage = "SpecialLoggerLanguage";
@@ -18,31 +17,31 @@ internal class CustomConfigurationTests
[SetUp]
public static void SetUp()
{
- ApplicationManager.SetStartup(new CustomStartup());
+ AqualityServices.SetStartup(new CustomStartup());
}
[Test]
public void Should_BeAbleOverrideDependencies_AndGetCustomService()
{
- Assert.AreEqual(SpecialLoggerLanguage, ApplicationManager.GetRequiredService().Language, "Configuration value should be overriden.");
+ Assert.AreEqual(SpecialLoggerLanguage, AqualityServices.Get().Language, "Configuration value should be overriden.");
}
[Test]
public void Should_BeAbleAdd_CustomService()
{
- Assert.AreEqual(SpecialCustomValue, ApplicationManager.GetRequiredService().CustomValue, "Custom service should have value");
+ Assert.AreEqual(SpecialCustomValue, AqualityServices.Get().CustomValue, "Custom service should have value");
}
[Test]
public void Should_BeAbleGet_DefaultService()
{
- Assert.AreEqual(DefaultCommandTimeout, ApplicationManager.GetRequiredService().Command, "Default service value should have default value");
+ Assert.AreEqual(DefaultCommandTimeout, AqualityServices.Get().Command, "Default service value should have default value");
}
[TearDown]
public static void TearDown()
{
- ApplicationManager.SetStartup(new ApplicationStartup());
+ AqualityServices.SetStartup(new ApplicationStartup());
}
private class CustomLoggerConfiguration : ILoggerConfiguration
diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Utilities/ProcessManagerTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Utilities/ProcessManagerTests.cs
index f0cb47d..f986ec3 100644
--- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Utilities/ProcessManagerTests.cs
+++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Utilities/ProcessManagerTests.cs
@@ -10,7 +10,7 @@ namespace Aquality.WinAppDriver.Tests.Utilities
public class ProcessManagerTests
{
private const string TestProcess = "cmd.exe";
- private static IProcessManager ProcessManager => ApplicationManager.GetRequiredService();
+ private static IProcessManager ProcessManager => AqualityServices.ProcessManager;
private static IEnumerable> FunctionsReturnTrueWhenProcessStarted
{