mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
* Add more UI-Test, refactor UITestAutomation * Convert manual test-case to automation UI-Tests: Validating Empty-view is shown if no entries in the list. Validating Empty-view is NOT shown if 1 or more entries in the list. Validating Add-an-entry HyperlinkButton in Empty-view works correctly. Validating Adding-entry Button works correctly. Validating the Add button should be Disabled if more than 9 hosts in one entry. Validating the Add button should be Enabled if less or equal 9 hosts in one entry. Validating error message should be shown if not run as admin. Validating Warning-Dialog will be shown if 'Show a warning at startup' toggle is On. Validating Warning-Dialog will NOT be shown if 'Show a warning at startup' toggle is Off. Validating click 'Quit' button in Warning-Dialog, the Hosts File Editor window would be closed. Validating click 'Accept' button in Warning-Dialog, the Hosts File Editor window would NOT be closed. --------- Co-authored-by: Jerry Xu <nxu@microsoft.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
52 lines
1.9 KiB
C#
52 lines
1.9 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System.Collections.ObjectModel;
|
|
using System.Runtime.CompilerServices;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using OpenQA.Selenium.Appium.Windows;
|
|
|
|
[assembly: InternalsVisibleTo("Element")]
|
|
[assembly: InternalsVisibleTo("Session")]
|
|
|
|
namespace Microsoft.PowerToys.UITest
|
|
{
|
|
/// <summary>
|
|
/// Helper class for finding elements.
|
|
/// </summary>
|
|
internal static class FindHelper
|
|
{
|
|
public static ReadOnlyCollection<T>? FindAll<T, TW>(Func<ReadOnlyCollection<TW>> findElementsFunc, WindowsDriver<WindowsElement>? driver, int timeoutMS)
|
|
where T : Element, new()
|
|
{
|
|
var items = findElementsFunc();
|
|
var res = items.Select(item =>
|
|
{
|
|
var element = item as WindowsElement;
|
|
return NewElement<T>(element, driver, timeoutMS);
|
|
}).Where(item => item.IsMatchingTarget()).ToList();
|
|
|
|
return new ReadOnlyCollection<T>(res);
|
|
}
|
|
|
|
public static T NewElement<T>(WindowsElement? element, WindowsDriver<WindowsElement>? driver, int timeoutMS)
|
|
where T : Element, new()
|
|
{
|
|
Assert.IsNotNull(driver, $"New Element {typeof(T).Name} error: driver is null.");
|
|
Assert.IsNotNull(element, $"New Element {typeof(T).Name} error: element is null.");
|
|
|
|
T newElement = new T();
|
|
if (timeoutMS > 0)
|
|
{
|
|
// Only set timeout if it is positive value
|
|
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(timeoutMS);
|
|
}
|
|
|
|
newElement.SetSession(driver);
|
|
newElement.SetWindowsElement(element);
|
|
return newElement;
|
|
}
|
|
}
|
|
}
|