Skip to content

Commit

Permalink
Feature/36 separate window and form (#39) +semver: feature
Browse files Browse the repository at this point in the history
* Renamed namespaces and folders from "Windows" to "Forms"

* Separate Form and Window classes

* Extract interface from Form, add and update the tests

* extract locators from the forms to reduce the code duplication

* Update core lib, fix application session getting

* Replace Application implementation references with interface, extend the IWindowsApplication interface

* fix WindowsElementFinder to ensure that ElementStateProvider works as expected.
Fix application tests

* Update Aquality.Selenium.Core to the latest version and support changes

* Add chrome test to check multiple windows

* Update the test to pass on the Azure DevOps environment

* add test to FindChildElement from the root-session element.
corrected ElementFactory in the Element

* Rework session supplier setting logic in elements and forms

* update Aquality.Selenium.Core library and removed temporary fix at WindowsElementFinder

+semver: feature
  • Loading branch information
mialeska authored Jan 10, 2020
1 parent 39a21a7 commit d6bf0c1
Show file tree
Hide file tree
Showing 56 changed files with 1,001 additions and 389 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using Aquality.Selenium.Core.Configurations;
using Aquality.Selenium.Core.Localization;
using Aquality.WinAppDriver.Actions;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Remote;
using WindowsDriver = OpenQA.Selenium.Appium.Windows.WindowsDriver<OpenQA.Selenium.Appium.Windows.WindowsElement>;

namespace Aquality.WinAppDriver.Applications
{
Expand All @@ -14,17 +14,17 @@ namespace Aquality.WinAppDriver.Applications
public class Application : IWindowsApplication
{
private TimeSpan implicitWait;
private WindowsDriver<WindowsElement> applicationSession;
private WindowsDriver<WindowsElement> rootSession;
private readonly Func<WindowsDriver<WindowsElement>> createApplicationSession;
private readonly Func<WindowsDriver<WindowsElement>> createDesktopSession;
private WindowsDriver applicationSession;
private WindowsDriver rootSession;
private readonly Func<WindowsDriver> createApplicationSession;
private readonly Func<WindowsDriver> createDesktopSession;

/// <summary>
/// Instantiate application.
/// </summary>
/// <param name="createApplicationSession">Function to create an instance of WinAppDriver for current application</param>
/// <param name="createRootSession">Function to create an instance of WinAppDriver for desktop session</param>
public Application(Func<WindowsDriver<WindowsElement>> createApplicationSession, Func<WindowsDriver<WindowsElement>> createRootSession)
public Application(Func<WindowsDriver> createApplicationSession, Func<WindowsDriver> createRootSession)
{
this.createApplicationSession = createApplicationSession;
this.createDesktopSession = createRootSession;
Expand All @@ -39,11 +39,11 @@ public Application(Func<WindowsDriver<WindowsElement>> createApplicationSession,

RemoteWebDriver IApplication.Driver => Driver;

public WindowsDriver<WindowsElement> Driver
public virtual WindowsDriver Driver
{
get
{
if (applicationSession == null)
if (!IsSessionStarted(applicationSession))
{
applicationSession = createApplicationSession();
Logger.Info("loc.application.ready");
Expand All @@ -53,15 +53,15 @@ public WindowsDriver<WindowsElement> Driver
}
}

public IKeyboardActions KeyboardActions { get; }
public virtual IKeyboardActions KeyboardActions { get; }

public IMouseActions MouseActions { get; }
public virtual IMouseActions MouseActions { get; }

public WindowsDriver<WindowsElement> RootSession
public virtual WindowsDriver RootSession
{
get
{
if (rootSession == null)
if (!IsSessionStarted(rootSession))
{
rootSession = createDesktopSession();
rootSession.Manage().Timeouts().ImplicitWait = implicitWait;
Expand All @@ -70,12 +70,16 @@ public WindowsDriver<WindowsElement> RootSession
}
}

public virtual bool IsStarted => IsSessionStarted(applicationSession) || IsSessionStarted(rootSession);

private bool IsSessionStarted(WindowsDriver session) => session?.SessionId != null;

/// <summary>
/// Sets WinAppDriver ImplicitWait timeout.
/// Default value: <see cref="ITimeoutConfiguration.Implicit"/>.
/// </summary>
/// <param name="timeout">Desired Implicit wait timeout.</param>
public void SetImplicitWaitTimeout(TimeSpan timeout)
public virtual void SetImplicitWaitTimeout(TimeSpan timeout)
{
if (timeout != implicitWait)
{
Expand All @@ -94,10 +98,18 @@ public void SetImplicitWaitTimeout(TimeSpan timeout)
/// <summary>
/// Quit application.
/// </summary>
public void Quit()
public virtual void Quit()
{
Logger.Info("loc.application.quit");
Driver?.Quit();
applicationSession?.Quit();
rootSession?.Quit();
}

public virtual IWindowsApplication Launch()
{
var launchedAppTitle = Driver.Title;
AqualityServices.Logger.Debug(launchedAppTitle);
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ protected ApplicationFactory()
timeoutConfiguration = AqualityServices.Get<ITimeoutConfiguration>();
}

public abstract Application Application { get; }
public abstract IWindowsApplication Application { get; }

protected virtual Application GetApplication(Uri driverServerUri)
protected virtual IWindowsApplication GetApplication(Uri driverServerUri)
{
return new Application(() => GetApplicationSession(driverServerUri), () => GetRootSession(driverServerUri));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public override IServiceCollection ConfigureServices(IServiceCollection services
services.AddTransient(serviceProvider => AqualityServices.ApplicationFactory);
services.AddTransient<IProcessManager, ProcessManager>();
services.AddTransient<IWinAppDriverLauncher, WinAppDriverLauncher>();
services.AddScoped(serviceProvider => applicationProvider(serviceProvider) as IWindowsApplication);
return services;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Aquality.WinAppDriver.Applications
/// <summary>
/// Controls application and Aquality services
/// </summary>
public class AqualityServices : AqualityServices<Application>
public class AqualityServices : AqualityServices<IWindowsApplication>
{
private static readonly ThreadLocal<ApplicationStartup> ApplicationStartupContainer = new ThreadLocal<ApplicationStartup>(() => new ApplicationStartup());
private static readonly ThreadLocal<IApplicationFactory> ApplicationFactoryContainer = new ThreadLocal<IApplicationFactory>();
Expand Down Expand Up @@ -82,7 +82,7 @@ public static bool TryToStopAppiumLocalService()
/// <summary>
/// Provides current instance of application
/// </summary>
public static Application Application
public static IWindowsApplication Application
{
get => GetApplication(StartApplicationFunction, ConfigureServices);
set => SetApplication(value);
Expand Down Expand Up @@ -161,7 +161,7 @@ public static void SetWindowHandleApplicationFactory(Func<WindowsDriver<WindowsE

private static IServiceProvider ServiceProvider => GetServiceProvider(services => Application, ConfigureServices);

private static Func<IServiceProvider, Application> StartApplicationFunction
private static Func<IServiceProvider, IWindowsApplication> StartApplicationFunction
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public interface IApplicationFactory
{
Application Application { get; }
IWindowsApplication Application { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
using Aquality.Selenium.Core.Applications;
using Aquality.WinAppDriver.Actions;
using OpenQA.Selenium.Appium.Windows;

namespace Aquality.WinAppDriver.Applications
{
/// <summary>
/// Provides functionality to work with Windows application via WinAppDriver.
/// </summary>
public interface IWindowsApplication : IApplication
{
/// <summary>
/// Provides instance of Windows Driver for current application
/// Provides instance of Windows Driver for current application.
/// </summary>
new WindowsDriver<WindowsElement> Driver { get; }

/// <summary>
/// Provides instance of Windows Driver for desktop session
/// Provides instance of Windows Driver for desktop session.
/// </summary>
WindowsDriver<WindowsElement> RootSession { get; }

/// <summary>
/// Provides methods representing basic keyboard actions.
/// </summary>
IKeyboardActions KeyboardActions { get; }

/// <summary>
/// Provides methods representing basic mouse actions.
/// </summary>
IMouseActions MouseActions { get; }

/// <summary>
/// Launches an instance of the current application.
/// </summary>
/// <returns>Current application instance.</returns>
IWindowsApplication Launch();

/// <summary>
/// Closes current application and desktop sessions.
/// </summary>
void Quit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public LocalApplicationFactory(AppiumLocalService driverService) : base()
this.driverService = driverService;
}

public override Application Application
public override IWindowsApplication Application
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public RemoteApplicationFactory(Uri driverServerUri) : base()
this.driverServerUri = driverServerUri;
}

public override Application Application
public override IWindowsApplication Application
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public WindowHandleApplicationFactory(Uri driverServerUri, Func<WindowsDriver<Wi
isRemote = AqualityServices.Get<IApplicationProfile>().IsRemote;
}

public override Application Application
public override IWindowsApplication Application
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="4.1.1" />
<PackageReference Include="Aquality.Selenium.Core" Version="0.3.1" />
<PackageReference Include="Aquality.Selenium.Core" Version="0.3.4" />
</ItemGroup>

</Project>
Loading

0 comments on commit d6bf0c1

Please sign in to comment.