From 16f724cc98463768f0f1f5ec1b87d328275dc50f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alaksiej=20Miale=C5=A1ka?= Date: Mon, 23 Sep 2019 15:12:09 +0300 Subject: [PATCH] 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 --- .../Applications/ApplicationManager.cs | 2 +- .../Aquality.WinAppDriver.csproj | 2 +- .../Aquality.WinAppDriver.xml | 37 ++++---- .../Aquality.WinAppDriver/Elements/Button.cs | 2 +- .../Elements/ElementFactory.cs | 10 ++ .../Elements/Interfaces/IElementFactory.cs | 14 ++- .../Extensions/ElementExtensions.cs | 2 +- .../Resources/Localization/be.json | 1 + .../Resources/Localization/en.json | 1 + .../Resources/Localization/ru.json | 1 + .../Aquality.WinAppDriver/Windows/Window.cs | 44 ++++----- .../Actions/KeyboardActionsTests.cs | 2 +- .../Actions/MouseActionsTests.cs | 2 +- .../Applications/ApplicationManagerTests.cs | 91 +++++++++++++++++++ .../Applications/CalculatorTest.cs | 34 ------- .../Elements/Actions/MouseActionsTests.cs | 2 +- .../Elements/ElementFactoryTests.cs | 2 +- .../Elements/ElementTests.cs | 2 +- .../Elements/TextBoxTests.cs | 2 +- .../Locators => Windows}/CalculatorWindow.cs | 4 +- .../CalculatorWindowWithRelativeElements.cs | 18 ++++ .../Windows/WindowTests.cs | 19 ++++ 22 files changed, 207 insertions(+), 87 deletions(-) create mode 100644 Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/ApplicationManagerTests.cs delete mode 100644 Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/CalculatorTest.cs rename Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/{Applications/Locators => Windows}/CalculatorWindow.cs (88%) create mode 100644 Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Windows/CalculatorWindowWithRelativeElements.cs create mode 100644 Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Windows/WindowTests.cs diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationManager.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationManager.cs index 3e818a6..679d659 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationManager.cs +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Applications/ApplicationManager.cs @@ -132,7 +132,7 @@ private static IServiceCollection RegisterServices(Func new LocalizationManager(serviceProvider.GetRequiredService(), serviceProvider.GetRequiredService(), Assembly.GetExecutingAssembly())); services.AddSingleton(serviceProvider => new KeyboardActions(serviceProvider.GetRequiredService(), () => Application.WindowsDriver)); services.AddSingleton(serviceProvider => new MouseActions(serviceProvider.GetRequiredService(), () => Application.WindowsDriver)); - services.AddSingleton(serviceProvider => ApplicationFactory); + services.AddTransient(serviceProvider => ApplicationFactory); return services; } diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.csproj b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.csproj index 4508ec3..0927e96 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/Aquality.WinAppDriver.xml b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.xml index b09b64a..806f373 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.xml +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Aquality.WinAppDriver.xml @@ -467,6 +467,17 @@ Element name Instance of element that implements ITextBox interface + + + Finds element relative to parent window. + + Type of the target element. + Parent window for the element. + Locator of the element relative to parent window. + Name of the element. + Delegate that defines constructor of element in case of custom element. + Instance of element. + Describes behavior of Label UI element. @@ -533,28 +544,22 @@ Unique locator of the window. Name of the window. - - - Locator of specified window. - - - - - Name of specified window. - - - - - Instance of logger - - Logger instance. - Element factory Element factory. + + + Finds element relative to current window. + + Type of the target element. + Locator of the element relative to current window. + Name of the element. + Delegate that defines constructor of element in case of custom element. + Instance of element. + Return window state for window locator diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Elements/Button.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Elements/Button.cs index 1c0d478..c7a7fa0 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Elements/Button.cs +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Elements/Button.cs @@ -8,7 +8,7 @@ namespace Aquality.WinAppDriver.Elements /// public class Button : Element, IButton { - public Button(By locator, string name) : base(locator, name) + protected internal Button(By locator, string name) : base(locator, name) { } diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Elements/ElementFactory.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Elements/ElementFactory.cs index 4effd2e..2281921 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Elements/ElementFactory.cs +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Elements/ElementFactory.cs @@ -6,8 +6,12 @@ using Aquality.Selenium.Core.Localization; using Aquality.Selenium.Core.Waitings; using Aquality.WinAppDriver.Elements.Interfaces; +using Aquality.WinAppDriver.Extensions; +using Aquality.WinAppDriver.Windows; using OpenQA.Selenium; +using OpenQA.Selenium.Support.PageObjects; using CoreFactory = Aquality.Selenium.Core.Elements.ElementFactory; +using IElement = Aquality.WinAppDriver.Elements.Interfaces.IElement; using IElementFactory = Aquality.WinAppDriver.Elements.Interfaces.IElementFactory; namespace Aquality.WinAppDriver.Elements @@ -36,6 +40,12 @@ public ITextBox GetTextBox(By locator, string name) return GetCustomElement(ResolveSupplier(null), locator, name); } + public T FindChildElement(Window parentWindow, By childLocator, string childName, ElementSupplier supplier = null) where T : IElement + { + var elementSupplier = ResolveSupplier(supplier); + return elementSupplier(new ByChained(parentWindow.Locator, childLocator), $"{childName}' - {parentWindow.GetElementType()} '{parentWindow.Name}", ElementState.Displayed); + } + protected override ElementSupplier ResolveSupplier(ElementSupplier supplier) { if (supplier != null) diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Elements/Interfaces/IElementFactory.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Elements/Interfaces/IElementFactory.cs index 57407dd..5010d0b 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Elements/Interfaces/IElementFactory.cs +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Elements/Interfaces/IElementFactory.cs @@ -1,4 +1,6 @@ -using OpenQA.Selenium; +using Aquality.Selenium.Core.Elements; +using Aquality.WinAppDriver.Windows; +using OpenQA.Selenium; using CoreElementFactory = Aquality.Selenium.Core.Elements.Interfaces.IElementFactory; namespace Aquality.WinAppDriver.Elements.Interfaces @@ -32,5 +34,15 @@ public interface IElementFactory : CoreElementFactory /// Instance of element that implements ITextBox interface ITextBox GetTextBox(By locator, string name); + /// + /// Finds element relative to parent window. + /// + /// Type of the target element. + /// Parent window for the element. + /// Locator of the element relative to parent window. + /// Name of the element. + /// Delegate that defines constructor of element in case of custom element. + /// Instance of element. + T FindChildElement(Window parentWindow, By childLocator, string childName, ElementSupplier supplier = null) where T : IElement; } } diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Extensions/ElementExtensions.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Extensions/ElementExtensions.cs index abe7a89..6366e77 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Extensions/ElementExtensions.cs +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Extensions/ElementExtensions.cs @@ -19,7 +19,7 @@ internal static class ElementExtensions internal static string GetElementType(this IElement element) { string elementType = null; - if (typeof(Element).IsAssignableFrom(element.GetType())) + if (element is Element) { elementType = element.GetType().GetProperty("ElementType", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(element).ToString(); } diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Resources/Localization/be.json b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Resources/Localization/be.json index a7b06d4..7a6fcfd 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Resources/Localization/be.json +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Resources/Localization/be.json @@ -15,6 +15,7 @@ "loc.application.driver.service.remote": "Працуем з сэрвісам драйвера па адрасе '{0}'", "loc.button": "Кнопка", "loc.label": "Надпіс", + "loc.window": "Акно", "loc.text.field": "Тэкставае поле", "loc.text.clearing": "Aчышчаем", "loc.text.typing": "Уводзім значэнне '{0}'", diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Resources/Localization/en.json b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Resources/Localization/en.json index 84bac09..ed63457 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Resources/Localization/en.json +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Resources/Localization/en.json @@ -15,6 +15,7 @@ "loc.application.driver.service.remote": "Using driver service running on '{0}'", "loc.button": "Button", "loc.label": "Label", + "loc.window": "Window", "loc.text.field": "Text Field", "loc.text.clearing": "Clearing", "loc.text.typing": "Typing '{0}'", diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Resources/Localization/ru.json b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Resources/Localization/ru.json index ec379db..9ddd3eb 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Resources/Localization/ru.json +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Resources/Localization/ru.json @@ -15,6 +15,7 @@ "loc.application.driver.service.remote": "Работаем с сервисом драйвера по адресу '{0}'", "loc.button": "Кнопка", "loc.label": "Надпись", + "loc.window": "Окно", "loc.text.field": "Текстовое поле", "loc.text.clearing": "Очищаем", "loc.text.typing": "Вводим значение '{0}'", diff --git a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Windows/Window.cs b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Windows/Window.cs index 4dc3748..aea7a80 100644 --- a/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Windows/Window.cs +++ b/Aquality.WinAppDriver/src/Aquality.WinAppDriver/Windows/Window.cs @@ -1,8 +1,9 @@ -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 @@ -10,53 +11,48 @@ namespace Aquality.WinAppDriver.Windows /// /// Defines base class for any application's window. /// - public abstract class Window + public abstract class Window : Element { /// /// Constructor with parameters. /// /// Unique locator of the window. /// Name of the window. - protected Window(By locator, string name) + protected Window(By locator, string name) : base(locator, name) { - Locator = locator; - Name = name; } - /// - /// Locator of specified window. - /// - public By Locator { get; } - - /// - /// Name of specified window. - /// - public string Name { get; } - - /// - /// Instance of logger - /// - /// Logger instance. - protected Logger Logger => ApplicationManager.GetRequiredService(); - /// /// Element factory /// /// Element factory. protected IElementFactory ElementFactory => ApplicationManager.GetRequiredService(); + /// + /// Finds element relative to current window. + /// + /// Type of the target element. + /// Locator of the element relative to current window. + /// Name of the element. + /// Delegate that defines constructor of element in case of custom element. + /// Instance of element. + public T FindChildElement(By childLocator, string childName, ElementSupplier supplier = null) where T : IElement + { + return ElementFactory.FindChildElement(this, childLocator, childName, supplier); + } + /// /// Return window state for window locator /// /// True - window is opened, /// False - window is not opened. - public bool IsDisplayed => WindowLabel.State.WaitForDisplayed(); + public bool IsDisplayed => State.WaitForDisplayed(); /// /// Gets size of window element defined by its locator. /// - 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"); } } diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/KeyboardActionsTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/KeyboardActionsTests.cs index e9184ad..891d08c 100644 --- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/KeyboardActionsTests.cs +++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/KeyboardActionsTests.cs @@ -1,7 +1,7 @@ using Aquality.WinAppDriver.Actions; using Aquality.WinAppDriver.Applications; using Aquality.WinAppDriver.Elements.Interfaces; -using Aquality.WinAppDriver.Tests.Applications.Locators; +using Aquality.WinAppDriver.Tests.Windows; using NUnit.Framework; using System; diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/MouseActionsTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/MouseActionsTests.cs index a948783..80177b3 100644 --- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/MouseActionsTests.cs +++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Actions/MouseActionsTests.cs @@ -1,7 +1,7 @@ using Aquality.WinAppDriver.Actions; using Aquality.WinAppDriver.Applications; using Aquality.WinAppDriver.Elements.Interfaces; -using Aquality.WinAppDriver.Tests.Applications.Locators; +using Aquality.WinAppDriver.Tests.Windows; using NUnit.Framework; namespace Aquality.WinAppDriver.Tests.Actions diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/ApplicationManagerTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/ApplicationManagerTests.cs new file mode 100644 index 0000000..40ad5e2 --- /dev/null +++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/ApplicationManagerTests.cs @@ -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().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/CalculatorTest.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/CalculatorTest.cs deleted file mode 100644 index 74f97d0..0000000 --- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/CalculatorTest.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Aquality.Selenium.Core.Elements.Interfaces; -using Aquality.WinAppDriver.Applications; -using Aquality.WinAppDriver.Tests.Applications.Locators; -using NUnit.Framework; - -namespace Aquality.WinAppDriver.Tests.Applications -{ - public class CalculatorTest : 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); - } - } -} diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/Actions/MouseActionsTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/Actions/MouseActionsTests.cs index 701d241..dfff884 100644 --- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/Actions/MouseActionsTests.cs +++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/Actions/MouseActionsTests.cs @@ -1,6 +1,6 @@ using Aquality.WinAppDriver.Actions; using Aquality.WinAppDriver.Elements.Interfaces; -using Aquality.WinAppDriver.Tests.Applications.Locators; +using Aquality.WinAppDriver.Tests.Windows; using NUnit.Framework; using OpenQA.Selenium.Interactions; diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementFactoryTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementFactoryTests.cs index dde9258..9958a8c 100644 --- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementFactoryTests.cs +++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementFactoryTests.cs @@ -1,7 +1,7 @@ using Aquality.WinAppDriver.Applications; using Aquality.WinAppDriver.Elements; using Aquality.WinAppDriver.Elements.Interfaces; -using Aquality.WinAppDriver.Tests.Applications.Locators; +using Aquality.WinAppDriver.Tests.Windows; using NUnit.Framework; using OpenQA.Selenium; using System; diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementTests.cs index a95207b..0ef4b04 100644 --- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementTests.cs +++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/ElementTests.cs @@ -1,7 +1,7 @@ using System; using Aquality.WinAppDriver.Applications; using Aquality.WinAppDriver.Elements.Interfaces; -using Aquality.WinAppDriver.Tests.Applications.Locators; +using Aquality.WinAppDriver.Tests.Windows; using NUnit.Framework; using OpenQA.Selenium; diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/TextBoxTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/TextBoxTests.cs index 5316d42..80aea8b 100644 --- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/TextBoxTests.cs +++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Elements/TextBoxTests.cs @@ -1,5 +1,5 @@ using Aquality.WinAppDriver.Elements.Interfaces; -using Aquality.WinAppDriver.Tests.Applications.Locators; +using Aquality.WinAppDriver.Tests.Windows; using NUnit.Framework; namespace Aquality.WinAppDriver.Tests.Elements diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/Locators/CalculatorWindow.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Windows/CalculatorWindow.cs similarity index 88% rename from Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/Locators/CalculatorWindow.cs rename to Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Windows/CalculatorWindow.cs index dbefe7e..d90e18a 100644 --- a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Applications/Locators/CalculatorWindow.cs +++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Windows/CalculatorWindow.cs @@ -3,7 +3,7 @@ using OpenQA.Selenium; using OpenQA.Selenium.Appium; -namespace Aquality.WinAppDriver.Tests.Applications.Locators +namespace Aquality.WinAppDriver.Tests.Windows { public class CalculatorWindow : Window { @@ -25,7 +25,7 @@ public class CalculatorWindow : Window public IElement NumberPad => ElementFactory.GetButton(WindowLocator, "Number pad"); - public CalculatorWindow() : base(WindowLocator, "Main Calculator Window") + public CalculatorWindow() : base(WindowLocator, "Calculator") { } } diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Windows/CalculatorWindowWithRelativeElements.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Windows/CalculatorWindowWithRelativeElements.cs new file mode 100644 index 0000000..a8be2db --- /dev/null +++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Windows/CalculatorWindowWithRelativeElements.cs @@ -0,0 +1,18 @@ +using Aquality.WinAppDriver.Elements.Interfaces; +using OpenQA.Selenium; + +namespace Aquality.WinAppDriver.Tests.Windows +{ + public class CalculatorWindowWithRelativeElements : CalculatorWindow + { + public new IButton OneButton => FindChildElement(base.OneButton.Locator, base.OneButton.Name); + + public new IButton TwoButton => FindChildElement(base.TwoButton.Locator, base.TwoButton.Name); + + public new IButton PlusButton => FindChildElement(base.PlusButton.Locator, base.PlusButton.Name); + + public new IButton EqualsButton => FindChildElement(base.EqualsButton.Locator, base.EqualsButton.Name); + + public new ILabel ResultsLabel => FindChildElement(By.XPath(".//*[@AutomationId='48']")); + } +} \ No newline at end of file diff --git a/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Windows/WindowTests.cs b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Windows/WindowTests.cs new file mode 100644 index 0000000..6ef740b --- /dev/null +++ b/Aquality.WinAppDriver/tests/Aquality.WinAppDriver.Tests/Windows/WindowTests.cs @@ -0,0 +1,19 @@ +using NUnit.Framework; + +namespace Aquality.WinAppDriver.Tests.Windows +{ + public class WindowTests : TestWithApplication + { + private static readonly CalculatorWindowWithRelativeElements calculatorWindow = new CalculatorWindowWithRelativeElements(); + + [Test] + public void Should_WorkWithCalculator_ViaRelativeElements() + { + calculatorWindow.OneButton.Click(); + calculatorWindow.PlusButton.Click(); + calculatorWindow.TwoButton.Click(); + calculatorWindow.EqualsButton.Click(); + StringAssert.Contains("3", calculatorWindow.ResultsLabel.Text); + } + } +}