Skip to content

Commit

Permalink
add OpenEditLayoutDialog test case and add By type
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhaopeng Wang committed Mar 4, 2025
1 parent bb84eec commit bf5d6cb
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 32 deletions.
7 changes: 7 additions & 0 deletions src/common/UITestAutomation/Element/By.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public override string ToString()
/// <returns>A By object.</returns>
public static By Name(string name) => new By(OpenQA.Selenium.By.Name(name));

/// <summary>
/// Creates a By object using the className attribute.
/// </summary>
/// <param name="className">The className attribute to search for.</param>
/// <returns>A By object.</returns>
public static By ClassName(string className) => new By(OpenQA.Selenium.By.ClassName(className));

/// <summary>
/// Creates a By object using the ID attribute.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,27 @@
using FancyZonesEditorCommon.Data;
using Microsoft.FancyZonesEditor.UITests;
using Microsoft.FancyZonesEditor.UnitTests.Utils;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium.Windows;
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;

namespace UITests_FancyZonesEditor
{
[TestClass]
public class RunFancyZonesEditorTest
public class RunFancyZonesEditorTest : UITestBase
{
private static FancyZonesEditorSession? _session;
private static TestContext? _context;
public RunFancyZonesEditorTest()
: base(PowerToysModule.FancyZone)
{
}

[ClassInitialize]
public static void ClassInitialize(TestContext testContext)
{
_context = testContext;
FancyZonesEditorHelper.Files.Restore();

// prepare files to launch Editor without errors
// prepare test editor parameters with 2 monitors before launching the editor
EditorParameters editorParameters = new EditorParameters();
EditorParameters.ParamsWrapper parameters = new EditorParameters.ParamsWrapper
{
Expand All @@ -46,9 +51,25 @@ public static void ClassInitialize(TestContext testContext)
MonitorWidth = 1920,
IsSelected = true,
},
new EditorParameters.NativeMonitorDataWrapper
{
Monitor = "monitor-2",
MonitorInstanceId = "instance-id-2",
MonitorSerialNumber = "serial-number-2",
MonitorNumber = 2,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 1920,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = false,
},
},
};
FancyZonesEditorSession.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));

LayoutTemplates layoutTemplates = new LayoutTemplates();
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
Expand All @@ -57,122 +78,153 @@ public static void ClassInitialize(TestContext testContext)
{
new LayoutTemplates.TemplateLayoutWrapper
{
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Empty],
Type = LayoutType.Blank.TypeToString(),
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Focus],
Type = LayoutType.Focus.TypeToString(),
ZoneCount = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Rows],
Type = LayoutType.Rows.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 10,
SensitivityRadius = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Columns],
Type = LayoutType.Columns.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 20,
SensitivityRadius = 20,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Grid],
Type = LayoutType.Grid.TypeToString(),
ZoneCount = 4,
ShowSpacing = false,
Spacing = 10,
SensitivityRadius = 30,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.PriorityGrid],
Type = LayoutType.PriorityGrid.TypeToString(),
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
};
FancyZonesEditorSession.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));

CustomLayouts customLayouts = new CustomLayouts();
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper> { },
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper>
{
new CustomLayouts.CustomLayoutWrapper
{
Uuid = "{E7807D0D-6223-4883-B15B-1F3883944C09}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Custom layout",
Info = new CustomLayouts().ToJsonElement(new CustomLayouts.CanvasInfoWrapper
{
RefHeight = 952,
RefWidth = 1500,
SensitivityRadius = 10,
Zones = new List<CustomLayouts.CanvasInfoWrapper.CanvasZoneWrapper> { },
}),
},
},
};
FancyZonesEditorSession.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));

DefaultLayouts defaultLayouts = new DefaultLayouts();
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
};
FancyZonesEditorSession.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));

LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
{
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
};
FancyZonesEditorSession.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));

AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
};
FancyZonesEditorSession.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
}

[ClassCleanup]
public static void ClassCleanup()
{
FancyZonesEditorSession.Files.Restore();
_context = null;
FancyZonesEditorHelper.Files.Restore();
}

[TestInitialize]
public void TestInitialize()
{
_session = new FancyZonesEditorSession(_context!);
}

[TestCleanup]
public void TestCleanup()
{
_session?.Close(_context!);
this.TestClean();
}

[TestMethod]
public void OpenEditorWindow() // verify the session is initialized
public void OpenNewLayoutDialog() // verify the new layout dialog is opened
{
Assert.IsNotNull(_session?.Session);
Session.FindByAccessibilityId<Button>(AccessibilityId.NewLayoutButton).Click();
Assert.IsNotNull(Session.Find<Element>("Choose layout type")); // check the pane header
}

[TestMethod]
public void OpenNewLayoutDialog() // verify the new layout dialog is opened
public void OpenEditLayoutDialog() // verify the edit layout dialog is opened
{
_session?.Click_CreateNewLayout();
Assert.IsNotNull(_session?.Session?.FindElementsByName("Choose layout type")); // check the pane header
Session.Find<Button>(TestConstants.TemplateLayoutNames[LayoutType.Grid]).Click();
Assert.IsNotNull(Session.FindByAccessibilityId<Element>(FancyZonesEditorHelper.AccessibilityId.DialogTitle)); // check the pane header
Assert.IsNotNull(Session.Find<Element>($"Edit '{TestConstants.TemplateLayoutNames[LayoutType.Grid]}'")); // verify it's opened for the correct layout
}

[TestMethod]
public void OpenEditLayoutDialog() // verify the edit layout dialog is opened
public void OpenEditLayoutDialog_ByContextMenu_TemplateLayout() // verify the edit layout dialog is opened
{
_session?.Click_EditLayout(TestConstants.TemplateLayoutNames[LayoutType.Grid]);
Assert.IsNotNull(_session?.Session?.FindElementByAccessibilityId("EditLayoutDialogTitle")); // check the pane header
Assert.IsNotNull(_session?.Session?.FindElementsByName("Edit 'Grid'")); // verify it's opened for the correct layout
Session.Find<Button>(TestConstants.TemplateLayoutNames[LayoutType.Grid]).Click(true);
var menu = Session.Find<Element>(By.ClassName(ClassName.ContextMenu));
menu.Find<Element>(FancyZonesEditorHelper.ElementName.Edit).Click();

Assert.IsNotNull(Session.FindByAccessibilityId<Element>(FancyZonesEditorHelper.AccessibilityId.DialogTitle)); // check the pane header
Assert.IsNotNull(Session.Find<Element>($"Edit '{TestConstants.TemplateLayoutNames[LayoutType.Grid]}'")); // verify it's opened for the correct layout
}

[TestMethod]
public void OpenEditLayoutDialog_ByContextMenu_CustomLayout() // verify the edit layout dialog is opened
{
string layoutName = "Custom layout";
Session.Find<Button>(layoutName).Click(true);
var menu = Session.Find<Element>(By.ClassName(ClassName.ContextMenu));
menu.Find<Element>(FancyZonesEditorHelper.ElementName.Edit).Click();

Assert.IsNotNull(Session.FindByAccessibilityId<Element>(FancyZonesEditorHelper.AccessibilityId.DialogTitle)); // check the pane header
Assert.IsNotNull(Session.Find<Element>($"Edit '{layoutName}'")); // verify it's opened for the correct layout
}

[TestMethod]
public void OpenContextMenu() // verify the context menu is opened
{
Assert.IsNotNull(_session?.OpenContextMenu(TestConstants.TemplateLayoutNames[LayoutType.Columns]));
Session.Find<Button>(TestConstants.TemplateLayoutNames[LayoutType.Columns]).Click(true);
Assert.IsNotNull(Session.Find<Element>(By.ClassName(ClassName.ContextMenu)));
}
}
}

1 comment on commit bf5d6cb

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log or 📝 job summary for details.

Unrecognized words (2)

Initializet
Tes

These words are not needed and should be removed ahk AMPROPERTY AMPROPSETID Breadcrumb CDEF comdef ddf devenum DEVMON DEVSOURCE DGR DIIRFLAG dshow DVH DVHD DVSD DVSL EData ERole fdw FILEINFOSIG Filtergraph Filterx HCERTSTORE IKs iljxck IYUV KSPROPERTY lcb ldx lld LONGLONG LTRB majortype makecab MEDIASUBTYPE mediatype mfplat mic mjpg Msimg msiquery ORAW outpin overlaywindow PAUDIO PINDIR Pnp ppmt previouscamera PROPBAG propvarutil reencoded REFGUID REGFILTER REGFILTERPINS REGPINTYPES regsvr shmem sizeread stl strsafe strutil subquery SYNCMFT TMPVAR vcdl vdi vid VIDCAP VIDEOINFOHEADER vih webcam wistd WVC

To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the [email protected]:microsoft/PowerToys.git repository
on the dev/zhaopengwang/test/37733-ui-test-fancyzones-editor branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.24/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/13661419434/attempts/1'
If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.