-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature - Extend Window from Element (#17)
* Implemented relative search against window locator. * Fix codesmell issue at ElementExtensions * Extend ApplicationManager tests. Fix issue with ApplicationFactory registration in DI container +semver: feature
- Loading branch information
Showing
22 changed files
with
207 additions
and
87 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
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
37 changes: 21 additions & 16 deletions
37
Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
44 changes: 20 additions & 24 deletions
44
Aquality.WinAppDriver/src/Aquality.WinAppDriver/Windows/Window.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 |
---|---|---|
@@ -1,62 +1,58 @@ | ||
using Aquality.Selenium.Core.Logging; | ||
using Aquality.Selenium.Core.Elements; | ||
using Aquality.WinAppDriver.Applications; | ||
using Aquality.WinAppDriver.Elements.Interfaces; | ||
using OpenQA.Selenium; | ||
using System.Drawing; | ||
using Element = Aquality.WinAppDriver.Elements.Element; | ||
using IElementFactory = Aquality.WinAppDriver.Elements.Interfaces.IElementFactory; | ||
|
||
namespace Aquality.WinAppDriver.Windows | ||
{ | ||
/// <summary> | ||
/// Defines base class for any application's window. | ||
/// </summary> | ||
public abstract class Window | ||
public abstract class Window : Element | ||
{ | ||
/// <summary> | ||
/// Constructor with parameters. | ||
/// </summary> | ||
/// <param name="locator">Unique locator of the window.</param> | ||
/// <param name="name">Name of the window.</param> | ||
protected Window(By locator, string name) | ||
protected Window(By locator, string name) : base(locator, name) | ||
{ | ||
Locator = locator; | ||
Name = name; | ||
} | ||
|
||
/// <summary> | ||
/// Locator of specified window. | ||
/// </summary> | ||
public By Locator { get; } | ||
|
||
/// <summary> | ||
/// Name of specified window. | ||
/// </summary> | ||
public string Name { get; } | ||
|
||
/// <summary> | ||
/// Instance of logger <see cref="Selenium.Core.Logging.Logger"/> | ||
/// </summary> | ||
/// <value>Logger instance.</value> | ||
protected Logger Logger => ApplicationManager.GetRequiredService<Logger>(); | ||
|
||
/// <summary> | ||
/// Element factory <see cref="IElementFactory"/> | ||
/// </summary> | ||
/// <value>Element factory.</value> | ||
protected IElementFactory ElementFactory => ApplicationManager.GetRequiredService<IElementFactory>(); | ||
|
||
/// <summary> | ||
/// Finds element relative to current window. | ||
/// </summary> | ||
/// <typeparam name="T">Type of the target element.</typeparam> | ||
/// <param name="childLocator">Locator of the element relative to current window.</param> | ||
/// <param name="childName">Name of the element.</param> | ||
/// <param name="supplier">Delegate that defines constructor of element in case of custom element.</param> | ||
/// <returns>Instance of element.</returns> | ||
public T FindChildElement<T>(By childLocator, string childName, ElementSupplier<T> supplier = null) where T : IElement | ||
{ | ||
return ElementFactory.FindChildElement(this, childLocator, childName, supplier); | ||
} | ||
|
||
/// <summary> | ||
/// Return window state for window locator | ||
/// </summary> | ||
/// <value>True - window is opened, | ||
/// False - window is not opened.</value> | ||
public bool IsDisplayed => WindowLabel.State.WaitForDisplayed(); | ||
public bool IsDisplayed => State.WaitForDisplayed(); | ||
|
||
/// <summary> | ||
/// Gets size of window element defined by its locator. | ||
/// </summary> | ||
public Size Size => WindowLabel.GetElement().Size; | ||
public Size Size => GetElement().Size; | ||
|
||
private ILabel WindowLabel => ElementFactory.GetLabel(Locator, Name); | ||
protected override string ElementType => LocalizationManager.GetLocalizedMessage("loc.window"); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/KeyboardActionsTests.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
2 changes: 1 addition & 1 deletion
2
Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/MouseActionsTests.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
91 changes: 91 additions & 0 deletions
91
...ty.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/ApplicationManagerTests.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,91 @@ | ||
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<IElementFinder>().FindElement(calculatorWindow.OneButton.Locator).Click(); | ||
ApplicationManager.GetRequiredService<IElementFinder>().FindElement(calculatorWindow.PlusButton.Locator).Click(); | ||
ApplicationManager.GetRequiredService<IElementFinder>().FindElement(calculatorWindow.TwoButton.Locator).Click(); | ||
ApplicationManager.GetRequiredService<IElementFinder>().FindElement(calculatorWindow.EqualsButton.Locator).Click(); | ||
var result = ApplicationManager.GetRequiredService<IElementFinder>().FindElement(calculatorWindow.ResultsLabel.Locator).Text; | ||
StringAssert.Contains("3", result); | ||
} | ||
|
||
[Test] | ||
public void Should_GetCurrentApplicationFactory_AfterSetDefaultFactory() | ||
{ | ||
var firstFactory = ApplicationManager.GetRequiredService<IApplicationFactory>(); | ||
ApplicationManager.SetDefaultFactory(); | ||
var secondFactory = ApplicationManager.GetRequiredService<IApplicationFactory>(); | ||
Assert.AreNotSame(firstFactory, secondFactory); | ||
ApplicationManager.ApplicationFactory = firstFactory; | ||
Assert.AreSame(firstFactory, ApplicationManager.GetRequiredService<IApplicationFactory>()); | ||
Assert.AreNotSame(secondFactory, ApplicationManager.GetRequiredService<IApplicationFactory>()); | ||
} | ||
|
||
[Test] | ||
public void Should_GetCurrentApplication_AfterSetApplication() | ||
{ | ||
IApplication firstApplication; | ||
using(var scope = ApplicationManager.ServiceProvider.CreateScope()) | ||
{ | ||
firstApplication = scope.ServiceProvider.GetRequiredService<IApplication>(); | ||
} | ||
|
||
// Creating a second instance of Application | ||
ApplicationManager.Application = ApplicationManager.ApplicationFactory.Application; | ||
|
||
using (var scope = ApplicationManager.ServiceProvider.CreateScope()) | ||
{ | ||
var secondApplication = scope.ServiceProvider.GetRequiredService<IApplication>(); | ||
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<IApplication>()); | ||
} | ||
} | ||
|
||
[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<IApplication>(); | ||
Assert.AreNotSame(firstApplication, secondApplicationFromServiceProvider); | ||
Assert.AreSame(secondApplication, secondApplicationFromServiceProvider); | ||
} | ||
} | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/CalculatorTest.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.