Skip to content

Commit

Permalink
Added WinUI InfoBar support and ability to maximise Windows application
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmcroft committed Feb 18, 2021
1 parent b39c6f5 commit decd6e9
Show file tree
Hide file tree
Showing 23 changed files with 178 additions and 37 deletions.
13 changes: 7 additions & 6 deletions docs/Windows/WindowsControlWrappers.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Windows control wrappers

The goal of the platform control wrappers is to provide an easy set of elements which surface up properties and actions of the actual controls within the UI to make it easier for you to write tests that interact with them.
The goal of the platform control wrappers is to provide an easy set of elements that surface up properties and actions of the actual controls within the UI to make it easier for you to write tests that interact with them.

These Windows control wrappers are designed to be used with applications built for the Windows platform.

## UWP Core Controls

These UWP control wrappers are designed to be used with applications built with Windows 10 SDK controls.
These Windows control wrappers are designed to be used with applications built with Windows 10 SDK controls.

**NOTE**, these control wrappers will also work with the WinUI alternatives.

Expand Down Expand Up @@ -43,8 +43,9 @@ These UWP control wrappers are designed to be used with applications built with

## WinUI Controls

These UWP control wrappers are designed to be used with controls from the [WinUI](https://github.com/microsoft/microsoft-ui-xaml) suite.
These Windows control wrappers are designed to be used with controls from the [WinUI](https://github.com/microsoft/microsoft-ui-xaml) suite.

- [InfoBar](../../src/Legerity.WinUI/InfoBar.cs)
- [MenuBar](../../src/Legerity.WinUI/MenuBar.cs)
- [MenuBarItem](../../src/Legerity.WinUI/MenuBarItem.cs)
- [NavigationView](../../src/Legerity.WinUI/NavigationView.cs)
Expand All @@ -54,7 +55,7 @@ These UWP control wrappers are designed to be used with controls from the [WinUI

## Windows Community Toolkit Controls

These UWP control wrappers are designed to be used with controls from the [Windows Community Toolkit](https://github.com/windows-toolkit/WindowsCommunityToolkit) suite.
These Windows control wrappers are designed to be used with controls from the [Windows Community Toolkit](https://github.com/windows-toolkit/WindowsCommunityToolkit) suite.

- [BladeView](../../src/Legerity.WCT/BladeView.cs)
- [BladeViewItem](../../src/Legerity.WCT/BladeViewItem.cs)
Expand All @@ -64,7 +65,7 @@ These UWP control wrappers are designed to be used with controls from the [Windo

## Telerik UWP Controls

These UWP control wrappers are designed to be used with controls from the [Telerik UI for UWP](https://github.com/telerik/UI-For-UWP) suite.
These Windows control wrappers are designed to be used with controls from the [Telerik UI for UWP](https://github.com/telerik/UI-For-UWP) suite.

- [RadAutoCompleteBox](../../src/Legerity.Telerik.Uwp/RadAutoCompleteBox.cs)
- [RadBulletGraph](../../src/Legerity.Telerik.Uwp/RadBulletGraph.cs)
Expand All @@ -73,7 +74,7 @@ These UWP control wrappers are designed to be used with controls from the [Teler

## MADE.NET Controls

These UWP control wrappers are designed to be used with controls from the [MADE.NET](https://github.com/MADE-Apps/MADE.NET) suite.
These Windows control wrappers are designed to be used with controls from the [MADE.NET](https://github.com/MADE-Apps/MADE.NET) suite.

- [DropDownList](../../src/Legerity.MADE/DropDownList.cs)
- [InputValidator](../../src/Legerity.MADE/InputValidator.cs)
3 changes: 2 additions & 1 deletion samples/XamlControlsGallery/BaseTestClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public virtual void Initialize()
new WindowsAppManagerOptions(StoreSampleApp)
{
DriverUri = "http://127.0.0.1:4723",
LaunchWinAppDriver = true
LaunchWinAppDriver = true,
Maximize = true
});
}

Expand Down
2 changes: 0 additions & 2 deletions samples/XamlControlsGallery/Pages/Collections/FlipViewPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ namespace XamlControlsGallery.Pages.Collections

using Legerity.Pages;
using Legerity.Windows.Elements.Core;
using Legerity.Windows.Extensions;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using OpenQA.Selenium;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace XamlControlsGallery.Pages.DateAndTime
using Microsoft.VisualStudio.TestTools.UnitTesting;

using OpenQA.Selenium;
using OpenQA.Selenium.Appium.Windows;

/// <summary>
/// Defines the CalendarDatePickerPage page of the XAML Controls Gallery application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace XamlControlsGallery.Pages.DateAndTime
using Microsoft.VisualStudio.TestTools.UnitTesting;

using OpenQA.Selenium;
using OpenQA.Selenium.Appium.Windows;

/// <summary>
/// Defines the CalendarView page of the XAML Controls Gallery application.
Expand Down
5 changes: 0 additions & 5 deletions samples/XamlControlsGallery/Pages/Media/InkToolbarPage.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
namespace XamlControlsGallery.Pages.Media
{
using System.Threading;

using Legerity.Pages;
using Legerity.Windows.Elements.Core;
using Legerity.Windows.Extensions;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using OpenQA.Selenium;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace XamlControlsGallery.Pages.MenusAndToolbars
{
using System.Linq;
using Legerity;
using Legerity.Pages;
using Legerity.Windows.Elements.Core;
using Legerity.Windows.Elements.WinUI;
Expand Down
3 changes: 0 additions & 3 deletions samples/XamlControlsGallery/Pages/Navigation/TabViewPage.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
namespace XamlControlsGallery.Pages.Navigation
{
using System.Linq;

using Legerity.Pages;
using Legerity.Windows.Elements.Core;
using Legerity.Windows.Elements.WinUI;
using Legerity.Windows.Extensions;

Expand Down
9 changes: 7 additions & 2 deletions samples/XamlControlsGallery/Pages/NavigationMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ namespace XamlControlsGallery.Pages
using Microsoft.VisualStudio.TestTools.UnitTesting;

using OpenQA.Selenium;
using OpenQA.Selenium.Appium.Windows;

using StatusAndInfo;
using XamlControlsGallery.Pages.BasicInput;
using XamlControlsGallery.Pages.Collections;
using XamlControlsGallery.Pages.DateAndTime;
Expand Down Expand Up @@ -127,6 +126,12 @@ public FlipViewPage GoToFlipViewPage()
return new FlipViewPage();
}

public InfoBarPage GoToInfoBarPage()
{
this.SearchForControl("InfoBar");
return new InfoBarPage();
}

/// <summary>
/// Navigates to the ink toolbar control page.
/// </summary>
Expand Down
27 changes: 27 additions & 0 deletions samples/XamlControlsGallery/Pages/StatusAndInfo/InfoBarPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace XamlControlsGallery.Pages.StatusAndInfo
{
using Legerity.Pages;
using Legerity.Windows.Elements.WinUI;
using Legerity.Windows.Extensions;
using OpenQA.Selenium;

/// <summary>
/// Defines the InfoBar page of the XAML Controls Gallery application.
/// </summary>
public class InfoBarPage : BasePage
{
private readonly By closableBarWithOptsQuery = ByExtensions.AutomationId("TestInfoBar1");

/// <summary>
/// Gets a given trait of the page to verify that the page is in view.
/// </summary>
protected override By Trait => By.XPath(".//*[@Name='InfoBar'][@AutomationId='TitleTextBlock']");

public InfoBarPage CloseClosableBarWithOptions()
{
InfoBar closeableBarWithOpts = this.WindowsApp.FindElement(this.closableBarWithOptsQuery);
closeableBarWithOpts.Close();
return this;
}
}
}
1 change: 0 additions & 1 deletion samples/XamlControlsGallery/Pages/Text/NumberBoxPage.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace XamlControlsGallery.Pages.Text
{
using Legerity.Pages;
using Legerity.Windows.Elements.Core;
using Legerity.Windows.Elements.WinUI;
using Legerity.Windows.Extensions;

Expand Down
3 changes: 0 additions & 3 deletions samples/XamlControlsGallery/Tests/Media/InkToolbarTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
namespace XamlControlsGallery.Tests.Media
{
using System;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using XamlControlsGallery.Pages;
using XamlControlsGallery.Pages.DateAndTime;
using XamlControlsGallery.Pages.Media;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ namespace XamlControlsGallery.Tests.BasicInput
using Microsoft.VisualStudio.TestTools.UnitTesting;

using XamlControlsGallery.Pages;
using XamlControlsGallery.Pages.BasicInput;
using XamlControlsGallery.Pages.MenusAndToolbars;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ namespace XamlControlsGallery.Tests.BasicInput
using Microsoft.VisualStudio.TestTools.UnitTesting;

using XamlControlsGallery.Pages;
using XamlControlsGallery.Pages.BasicInput;
using XamlControlsGallery.Pages.MenusAndToolbars;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
namespace XamlControlsGallery.Tests.BasicInput
{
using System.Linq;
using Legerity;
using Legerity.Windows.Elements.WinUI;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using XamlControlsGallery.Pages;
using XamlControlsGallery.Pages.BasicInput;
using XamlControlsGallery.Pages.MenusAndToolbars;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ namespace XamlControlsGallery.Tests.Navigation
using Microsoft.VisualStudio.TestTools.UnitTesting;

using XamlControlsGallery.Pages;
using XamlControlsGallery.Pages.Collections;
using XamlControlsGallery.Pages.Navigation;

[TestClass]
Expand Down
25 changes: 25 additions & 0 deletions samples/XamlControlsGallery/Tests/StatusAndInfo/InfoBarTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace XamlControlsGallery.Tests.StatusAndInfo
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Pages;
using Pages.StatusAndInfo;

[TestClass]
public class InfoBarTests : BaseTestClass
{
private static InfoBarPage InfoBarPage { get; set; }

[TestInitialize]
public override void Initialize()
{
base.Initialize();
InfoBarPage = new NavigationMenu().GoToInfoBarPage();
}

[TestMethod]
public void CloseClosableBarWithOptions()
{
InfoBarPage.CloseClosableBarWithOptions();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ namespace XamlControlsGallery.Tests.Text
using Microsoft.VisualStudio.TestTools.UnitTesting;

using XamlControlsGallery.Pages;
using XamlControlsGallery.Pages.BasicInput;
using XamlControlsGallery.Pages.Text;

[TestClass]
Expand Down
1 change: 0 additions & 1 deletion samples/XamlControlsGallery/Tests/Text/NumberBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ namespace XamlControlsGallery.Tests.Text
using Microsoft.VisualStudio.TestTools.UnitTesting;

using XamlControlsGallery.Pages;
using XamlControlsGallery.Pages.BasicInput;
using XamlControlsGallery.Pages.Text;

[TestClass]
Expand Down
90 changes: 90 additions & 0 deletions src/Legerity.WinUI/InfoBar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
namespace Legerity.Windows.Elements.WinUI
{
using Core;
using Extensions;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;

/// <summary>
/// Defines a <see cref="WindowsElement"/> wrapper for the WinUI InfoBar control.
/// </summary>
public class InfoBar : WindowsElementWrapper
{
/// <summary>
/// Initializes a new instance of the <see cref="InfoBar"/> class.
/// </summary>
/// <param name="element">
/// The <see cref="WindowsElement"/> reference.
/// </param>
public InfoBar(WindowsElement element)
: base(element)
{
}

/// <summary>
/// Gets the title of the info bar.
/// </summary>
public string Title => this.TitleTextBlock.Text;

/// <summary>
/// Gets the message of the info bar.
/// </summary>
public string Message => this.MessageTextBlock.Text;

/// <summary>
/// Gets a value indicating whether the info bar is open.
/// </summary>
public bool IsOpen => !bool.Parse(this.Element.GetAttribute("IsOffscreen"));

/// <summary>
/// Gets the element associated with the title <see cref="TextBlock"/>.
/// </summary>
public TextBlock TitleTextBlock => this.FindElement(ByExtensions.AutomationId("Title"));

/// <summary>
/// Gets the element associated with the message <see cref="TextBlock"/>.
/// </summary>
public TextBlock MessageTextBlock => this.FindElement(ByExtensions.AutomationId("Message"));

/// <summary>
/// Gets the element associated with the close <see cref="Button"/>.
/// </summary>
public Button CloseButton => this.FindElement(ByExtensions.AutomationId("CloseButton"));

/// <summary>
/// Allows conversion of a <see cref="WindowsElement"/> to the <see cref="InfoBar"/> without direct casting.
/// </summary>
/// <param name="element">
/// The <see cref="WindowsElement"/>.
/// </param>
/// <returns>
/// The <see cref="InfoBar"/>.
/// </returns>
public static implicit operator InfoBar(WindowsElement element)
{
return new InfoBar(element);
}

/// <summary>
/// Allows conversion of a <see cref="AppiumWebElement"/> to the <see cref="InfoBar"/> without direct casting.
/// </summary>
/// <param name="element">
/// The <see cref="AppiumWebElement"/>.
/// </param>
/// <returns>
/// The <see cref="InfoBar"/>.
/// </returns>
public static implicit operator InfoBar(AppiumWebElement element)
{
return new InfoBar(element as WindowsElement);
}

/// <summary>
/// Closes the info bar.
/// </summary>
public void Close()
{
this.CloseButton.Click();
}
}
}
5 changes: 5 additions & 0 deletions src/Legerity/AppManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public static void StartApp(AppManagerOptions opts)
winOpts.AppiumOptions);

VerifyAppDriver(WindowsApp, winOpts);

if (winOpts.Maximize)
{
WebApp.Manage().Window.Maximize();
}
break;
}

Expand Down
10 changes: 10 additions & 0 deletions src/Legerity/ElementWrapper`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ protected ElementWrapper(TElement element)
/// </summary>
public bool IsVisible => this.Element.Displayed;

/// <summary>
/// Finds a child element by the specified query.
/// </summary>
/// <param name="by">The query to find a child element by.</param>
/// <returns>The <typeparamref name="TElement"/>.</returns>
public AppiumWebElement FindElement(By by)
{
return this.Element.FindElement(by);
}

/// <summary>
/// Determines whether the given element is shown.
/// </summary>
Expand Down
Loading

0 comments on commit decd6e9

Please sign in to comment.