Skip to content

Commit

Permalink
add cleanup test function and change file init
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhaopeng Wang committed Mar 4, 2025
1 parent 3fa0a74 commit e2651fe
Showing 5 changed files with 64 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/common/UITestAutomation/SessionHelper.cs
Original file line number Diff line number Diff line change
@@ -71,6 +71,7 @@ public SessionHelper Init()
/// </summary>
public void Cleanup()
{
ExitScopeExe();
try
{
appDriver?.Kill();
19 changes: 11 additions & 8 deletions src/common/UITestAutomation/UITestBase.cs
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Xml.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
@@ -31,12 +32,6 @@ public UITestBase(PowerToysModule scope = PowerToysModule.PowerToysSettings)
this.Session = new Session(this.sessionHelper.GetRoot(), this.sessionHelper.GetDriver());
}

~UITestBase()
{
this.ExitScopeExe();
this.sessionHelper.Cleanup();
}

/// <summary>
/// Initializes the test.
/// </summary>
@@ -54,6 +49,14 @@ public void TestInit()
}
}

/// <summary>
/// UnInitializes the test.
/// </summary>
public void TestClean()
{
this.sessionHelper.Cleanup();
}

/// <summary>
/// Finds an element by selector.
/// Shortcut for this.Session.Find<T>(by, timeoutMS)
@@ -160,7 +163,7 @@ protected ReadOnlyCollection<Element> FindAll(string name, int timeoutMS = 3000)
/// </summary>
public void RestartScopeExe()
{
sessionHelper.RestartScopeExe();
this.sessionHelper.RestartScopeExe();
this.Session = new Session(this.sessionHelper.GetRoot(), this.sessionHelper.GetDriver());
return;
}
@@ -170,7 +173,7 @@ public void RestartScopeExe()
/// </summary>
public void ExitScopeExe()
{
sessionHelper.ExitScopeExe();
this.sessionHelper.ExitScopeExe();
return;
}
}
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Windows.UI;
using static FancyZonesEditorCommon.Data.EditorParameters;
using static Microsoft.ApplicationInsights.MetricDimensionNames.TelemetryContext;

namespace UITests_FancyZonesEditor
@@ -20,7 +21,55 @@ public class DefaultLayoutsTest : UITestBase
public DefaultLayoutsTest()
: base(PowerToysModule.FancyZone)
{
// FancyZonesEditorHelper.InitFancyZonesLayout();
FancyZonesEditorHelper.Files.ParamsIOHelper.RestoreData();
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
new 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,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
}

[TestCleanup]
public void TestCleanup()
{
this.TestClean();
}

[TestMethod]
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ public void TestInitialize()
[TestCleanup]
public void TestCleanup()
{
this.TestClean();
}

[TestMethod]
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ public void TestInitialize()
[TestCleanup]
public void TestCleanup()
{
this.ExitScopeExe();
this.TestClean();
}

[TestMethod]

1 comment on commit e2651fe

@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 (1)

Initializaion

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 git@github.com: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/13651619171/attempts/1'
Errors (1)

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

❌ Errors Count
❌ check-file-path 1

See ❌ Event descriptions for more information.

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.