138 lines
4.5 KiB
C#
Raw Normal View History

[FancyZones]UI testing that works in CI (#29453) * added test project * run fz test * rename proj * editor test project * check if FZ is running * rename * added assert messages * spelling * dev docs * spelling * update to latest stable * exclude ui tests deps * update packages list in notice.md * added sample tests * added file for tests run * removed unrecognized * removed run * fix test configuration * rename job * change dependance * run test template * removed condition * tabulation fix * removed arg * removed dependance * removed log * removed parameters * test * test * added parameters * pool * pool * vs test * dependance * download artifact * publish artifact * artifact publish conditions * artifact name, default download path * set folders * prepare dotnet and vstest platform * copy all * target dotnet8 * test build agents * set vs test version * spellcheck * set test platform version * package feed selector * hardcoded vstest location * are other tests running? * location * vstest.console * upd command * script path * search vstest.console * vs path * tools dir * check files * try full path * try vstest task * try full path in vstest task * change path, remove unnecessary * test with full vsconsole path * winappdriver task * changed args and condition * default address * added start operation type * task name * remove resolution * Update run-ui-tests-ci.yml * Update run-ui-tests-ci.yml * Update run-ui-tests-ci.yml * Update run-ui-tests-ci.yml * AgentResolution should be a string * Update run-ui-tests-ci.yml testing against what WinUI gallery has for agent * Update run-ui-tests-ci.yml * Update run-ui-tests-ci.yml * added WinAppDriver.exe * spellcheck * remove task * checkout * path * src dir variable * added init to the second project * set longer timeout * try waiting * rerun * log session info * exclude WinAppDriver files from spell-check * split io class: editor params * remove unnecessary * move data to the common project * io test helper * write retry * Moved constants * file utils * prepare editor files before launch * remove unused file * spellcheck * create directory * fixed cleaning up * remove WinAppDriver from deps * start WinAppDriver from the default installation path * installation script * Revert "spellcheck" This reverts commit 4bdc3957305daa20a5901aae83de0622ec41a93d. * Revert "exclude WinAppDriver files from spell-check" This reverts commit 21ee6db3f5afb4cae9ea51d9468c07caa8dbc0f4. * install * installation argument * spellcheck * change winappdriver path in fz tests * delete iohelper * update docs * deleted obsolete winappdriver tests * net version * try without vstest location * spellcheck * Revert "try without vstest location" This reverts commit 7cd39f3ae6735f53f7deea8d91312a8046309459. * moved json tag constants to the common project
2024-03-22 13:10:10 +01:00
// 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.IO;
using System.Reflection;
using Microsoft.FancyZonesEditor.UITests.Utils;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
namespace Microsoft.FancyZonesEditor.UnitTests.Utils
{
public class FancyZonesEditorSession
{
protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";
private const string FancyZonesEditorPath = @"\..\..\..\PowerToys.FancyZonesEditor.exe";
private static FancyZonesEditorFiles? _files;
public static FancyZonesEditorFiles Files
{
get
{
if (_files == null)
{
_files = new FancyZonesEditorFiles();
}
return _files;
}
}
public WindowsDriver<WindowsElement>? Session { get; }
public WindowsElement? MainEditorWindow { get; }
public FancyZonesEditorSession(TestContext testContext)
{
try
{
// Launch FancyZonesEditor
string? path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
path += FancyZonesEditorPath;
AppiumOptions opts = new AppiumOptions();
opts.AddAdditionalCapability("app", path);
Session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), opts);
}
catch (Exception ex)
{
testContext.WriteLine(ex.Message);
}
Assert.IsNotNull(Session, "Session not initialized");
testContext.WriteLine("Session: " + Session.SessionId.ToString());
testContext.WriteLine("Title: " + Session.Title);
// Set implicit timeout to make element search to retry every 500 ms
Session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
// Find main editor window
try
{
MainEditorWindow = Session.FindElementByAccessibilityId("MainWindow1");
}
catch
{
Assert.IsNotNull(MainEditorWindow, "Main editor window not found");
}
}
public void Close(TestContext testContext)
{
// Close the session
if (Session != null)
{
try
{
// FZEditor application can be closed by explicitly closing main editor window
MainEditorWindow?.SendKeys(Keys.Alt + Keys.F4);
}
catch (Exception ex)
{
testContext.WriteLine(ex.Message);
}
Session.Quit();
Session.Dispose();
}
}
private WindowsElement? GetLayout(string layoutName)
{
var listItem = Session?.FindElementByName(layoutName);
Assert.IsNotNull(listItem, "Layout " + layoutName + " not found");
return listItem;
}
public WindowsElement? OpenContextMenu(string layoutName)
{
RightClick_Layout(layoutName);
var menu = Session?.FindElementByClassName("ContextMenu");
Assert.IsNotNull(menu, "Context menu not found");
return menu;
}
public void Click_CreateNewLayout()
{
var button = Session?.FindElementByAccessibilityId("NewLayoutButton");
Assert.IsNotNull(button, "Create new layout button not found");
button?.Click();
}
public void Click_EditLayout(string layoutName)
{
var layout = GetLayout(layoutName);
var editButton = layout?.FindElementByAccessibilityId("EditLayoutButton");
Assert.IsNotNull(editButton, "Edit button not found");
editButton.Click();
}
public void RightClick_Layout(string layoutName)
{
var layout = GetLayout(layoutName);
Actions actions = new Actions(Session);
actions.MoveToElement(layout);
actions.MoveByOffset(30, 30);
actions.ContextClick();
actions.Build().Perform();
}
}
}