mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
* Add UITestAutomation framework * add code comments * Optimized code format * Optimized code format * Update commons and add keyboard manager ui test project * Optimized code format * test scope and fix fancyzone exe path * Add readme * Optimize helper functions and UI test method * Fix spelling errors and restore module UI tests * Restore Indent * Update NOTICE.md * Update comments to Session and Elements * Update comments for Button and Window * delete unnecessary code * change FindElementByName to FindElmenet * Update comments for ModuleConfigData * Update readme and comments * Remove extra comments * change public property * Optimize code readability * add default Attach Function * change attach function name * Update comments to XML format * Hide by internal functions * Update readme * Refine the framework * Fix process start position and update readme * Remove Enum PowerToysModuleWindow * Update attach comments * Update ModuleConfigData comments --------- Co-authored-by: Zhaopeng Wang (from Dev Box) <zhaopengwang@microsoft.com> Co-authored-by: Xiaofeng Wang (from Dev Box) <xiaofengwang@microsoft.com> Co-authored-by: urnotdfs <709586527@qq.com>
61 lines
2.2 KiB
C#
61 lines
2.2 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;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using OpenQA.Selenium;
|
|
using OpenQA.Selenium.Appium;
|
|
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 FindElementHelper
|
|
{
|
|
public static T Find<T, TW>(Func<TW> findElementFunc, WindowsDriver<WindowsElement>? driver, int timeoutMS)
|
|
where T : Element, new()
|
|
{
|
|
var item = findElementFunc() as WindowsElement;
|
|
return NewElement<T>(item, driver, timeoutMS);
|
|
}
|
|
|
|
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);
|
|
}).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();
|
|
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(timeoutMS);
|
|
newElement.SetSession(driver);
|
|
newElement.SetWindowsElement(element);
|
|
return newElement;
|
|
}
|
|
}
|
|
}
|