/ src / modules / Workspaces / WorkspacesEditorUITest / WorkspacesSnapshotTests.cs
WorkspacesSnapshotTests.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using Microsoft.PowerToys.UITest;
 6  using Microsoft.VisualStudio.TestTools.UnitTesting;
 7  using WorkspacesEditor.Utils;
 8  
 9  namespace WorkspacesEditorUITest;
10  
11  [TestClass]
12  public class WorkspacesSnapshotTests : WorkspacesUiAutomationBase
13  {
14      public WorkspacesSnapshotTests()
15          : base()
16      {
17      }
18  
19      [TestMethod("WorkspacesSnapshot.CancelCapture")]
20      [TestCategory("Workspaces Snapshot UI")]
21      public void TestCaptureCancel()
22      {
23          AttachWorkspacesEditor();
24  
25          var createButton = Find<Button>("Create Workspace");
26          createButton.Click();
27  
28          Task.Delay(1000).Wait();
29  
30          AttachSnapshotWindow();
31  
32          var cancelButton = Find<Button>("Cancel");
33  
34          Assert.IsNotNull(cancelButton, "Capture button should exist");
35  
36          cancelButton.Click();
37      }
38  
39      [TestMethod("WorkspacesSnapshot.CapturePackagedApps")]
40      [TestCategory("Workspaces Snapshot UI")]
41      public void TestCapturePackagedApplications()
42      {
43          OpenCalculator();
44  
45          // OpenWindowsSettings();
46          Task.Delay(2000).Wait();
47  
48          AttachWorkspacesEditor();
49          var createButton = Find<Button>("Create Workspace");
50          createButton.Click();
51          Task.Delay(1000).Wait();
52  
53          AttachSnapshotWindow();
54          var captureButton = Find<Button>("Capture");
55          captureButton.Click();
56          Task.Delay(3000).Wait();
57  
58          // Verify captured windows by reading the temporary workspaces file as the ground truth.
59          var editorIO = new WorkspacesEditorIO();
60          var workspace = editorIO.ParseTempProject();
61  
62          Assert.IsNotNull(workspace, "Workspace data should be deserialized.");
63          Assert.IsNotNull(workspace.Applications, "Workspace should contain a list of apps.");
64  
65          bool isCalculatorFound = workspace.Applications.Any(app => app.AppPath.Contains("Calculator", StringComparison.OrdinalIgnoreCase));
66  
67          // bool isSettingsFound = workspace.Applications.Any(app => app.AppPath.Contains("Settings", StringComparison.OrdinalIgnoreCase));
68          Assert.IsTrue(isCalculatorFound, "Calculator should be captured in the workspace data.");
69  
70          // Assert.IsTrue(isSettingsFound, "Settings should be captured in the workspace data.");
71  
72          // Cancel to clean up
73          AttachWorkspacesEditor();
74          Find<Button>("Cancel").Click();
75          Task.Delay(1000).Wait();
76  
77          // Close test applications
78          CloseCalculator();
79  
80          // CloseWindowsSettings();
81      }
82  }