2023-10-26 14:36:10 +02: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.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
|
using OpenQA.Selenium;
|
|
|
|
|
|
using OpenQA.Selenium.Appium;
|
|
|
|
|
|
using OpenQA.Selenium.Appium.Windows;
|
|
|
|
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-27 15:43:52 +02:00
|
|
|
|
Assert.IsNotNull(Session, "Session not initialized");
|
2023-10-26 14:36:10 +02:00
|
|
|
|
|
|
|
|
|
|
// Set implicit timeout to 1.5 seconds to make element search to retry every 500 ms for at most three times
|
|
|
|
|
|
Session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);
|
|
|
|
|
|
|
|
|
|
|
|
// Find main editor window
|
|
|
|
|
|
MainEditorWindow = Session.FindElementByAccessibilityId("MainWindow1");
|
2023-10-27 15:43:52 +02:00
|
|
|
|
Assert.IsNotNull(MainEditorWindow, "Main editor window not found");
|
2023-10-26 14:36:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Close(TestContext testContext)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Close the session
|
|
|
|
|
|
if (Session != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2023-10-27 15:55:20 +02:00
|
|
|
|
// FZEditor applcation can be closed by explicitly closing main editor window
|
2023-10-26 14:36:10 +02:00
|
|
|
|
MainEditorWindow?.SendKeys(Keys.Alt + Keys.F4);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
testContext.WriteLine(ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Session.Quit();
|
|
|
|
|
|
Session.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|