mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-08 01:52:52 +08:00
Added zone count test and "WaitElementBy..." methods (#1645)
This commit is contained in:
parent
35054c1f59
commit
dee6dc1e6c
@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Appium.Windows;
|
||||
|
||||
namespace PowerToysTests
|
||||
{
|
||||
[TestClass]
|
||||
public class FancyZonesEditorSettingsTests : PowerToysSession
|
||||
{
|
||||
[TestMethod]
|
||||
public void ZoneCount()
|
||||
{
|
||||
ShortWait();
|
||||
OpenFancyZonesSettings();
|
||||
|
||||
WindowsElement editorButton = WaitElementByXPath("//Button[@Name=\"Edit zones\"]");
|
||||
editorButton.Click();
|
||||
|
||||
WindowsElement minusButton = WaitElementByAccessibilityId("decrementZones");
|
||||
WindowsElement zoneCount = WaitElementByAccessibilityId("zoneCount");
|
||||
WindowsElement applyButton;
|
||||
|
||||
int zoneCountQty;
|
||||
Assert.IsTrue(Int32.TryParse(zoneCount.Text, out zoneCountQty));
|
||||
|
||||
for (int i = zoneCountQty - 1, j = 0; i > -5; --i, ++j)
|
||||
{
|
||||
minusButton.Click();
|
||||
|
||||
Assert.IsTrue(Int32.TryParse(zoneCount.Text, out zoneCountQty));
|
||||
Assert.AreEqual(Math.Max(i, 1), zoneCountQty);
|
||||
|
||||
if (j == 0 || i == -4)
|
||||
{
|
||||
applyButton = WaitElementByAccessibilityId("ApplyTemplateButton");
|
||||
applyButton.Click();
|
||||
ShortWait();
|
||||
Assert.AreEqual(zoneCountQty, getSavedZoneCount());
|
||||
editorButton.Click();
|
||||
minusButton = WaitElementByAccessibilityId("decrementZones");
|
||||
zoneCount = WaitElementByAccessibilityId("zoneCount");
|
||||
}
|
||||
}
|
||||
|
||||
WindowsElement plusButton = WaitElementByAccessibilityId("incrementZones");
|
||||
|
||||
for (int i = 2; i < 45; ++i)
|
||||
{
|
||||
plusButton.Click();
|
||||
|
||||
Assert.IsTrue(Int32.TryParse(zoneCount.Text, out zoneCountQty));
|
||||
Assert.AreEqual(Math.Min(i, 40), zoneCountQty);
|
||||
}
|
||||
|
||||
applyButton = WaitElementByAccessibilityId("ApplyTemplateButton");
|
||||
applyButton.Click();
|
||||
ShortWait();
|
||||
Assert.AreEqual(zoneCountQty, getSavedZoneCount());
|
||||
}
|
||||
|
||||
private int getSavedZoneCount()
|
||||
{
|
||||
JObject zoneSettings = JObject.Parse(File.ReadAllText(_zoneSettingsPath));
|
||||
int editorZoneCount = (int)zoneSettings["devices"][0]["editor-zone-count"];
|
||||
return editorZoneCount;
|
||||
}
|
||||
|
||||
[ClassInitialize]
|
||||
public static void ClassInitialize(TestContext context)
|
||||
{
|
||||
Setup(context);
|
||||
OpenSettings();
|
||||
}
|
||||
|
||||
[ClassCleanup]
|
||||
public static void ClassCleanup()
|
||||
{
|
||||
CloseSettings();
|
||||
TearDown();
|
||||
}
|
||||
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
@ -87,7 +88,7 @@ namespace PowerToysTests
|
||||
}
|
||||
}
|
||||
|
||||
public static void WaitSeconds(int seconds)
|
||||
public static void WaitSeconds(double seconds)
|
||||
{
|
||||
Thread.Sleep(TimeSpan.FromSeconds(seconds));
|
||||
}
|
||||
@ -97,6 +98,50 @@ namespace PowerToysTests
|
||||
Thread.Sleep(TimeSpan.FromSeconds(0.5));
|
||||
}
|
||||
|
||||
//Trying to find element by XPath
|
||||
protected WindowsElement WaitElementByXPath(string xPath, double maxTime = 10)
|
||||
{
|
||||
WindowsElement result = null;
|
||||
Stopwatch timer = new Stopwatch();
|
||||
timer.Start();
|
||||
while (timer.Elapsed < TimeSpan.FromSeconds(maxTime))
|
||||
{
|
||||
try
|
||||
{
|
||||
result = session.FindElementByXPath(xPath);
|
||||
}
|
||||
catch { }
|
||||
if (result != null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Assert.IsNotNull(result);
|
||||
return null;
|
||||
}
|
||||
|
||||
//Trying to find element by AccessibilityId
|
||||
protected WindowsElement WaitElementByAccessibilityId(string accessibilityId, double maxTime = 10)
|
||||
{
|
||||
WindowsElement result = null;
|
||||
Stopwatch timer = new Stopwatch();
|
||||
timer.Start();
|
||||
while (timer.Elapsed < TimeSpan.FromSeconds(maxTime))
|
||||
{
|
||||
try
|
||||
{
|
||||
result = session.FindElementByAccessibilityId(accessibilityId);
|
||||
}
|
||||
catch { }
|
||||
if (result != null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Assert.IsNotNull(result);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void OpenSettings()
|
||||
{
|
||||
trayButton.Click();
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\..\..\packages\MSTest.TestAdapter.2.1.0\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\..\..\packages\MSTest.TestAdapter.2.1.0\build\net45\MSTest.TestAdapter.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
@ -84,6 +84,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="FancyZonesTests\EditorOpeningTests.cs" />
|
||||
<Compile Include="FancyZonesTests\EditorSettingsTests.cs" />
|
||||
<Compile Include="FancyZonesTests\FancyZonesSettingsTests.cs" />
|
||||
<Compile Include="PowerToysSession.cs" />
|
||||
<Compile Include="PowerToysTrayTests.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user