WinAppDriver tests fix (#2006)

* updated wait methods and launch
* canvas zone resize tests updated
* updated editor opening
This commit is contained in:
Seraphima Zykova
2020-04-10 18:52:16 +03:00
committed by GitHub
parent f589dd2f26
commit 14441ec144
9 changed files with 176 additions and 208 deletions

View File

@@ -13,6 +13,8 @@ namespace PowerToysTests
public class PowerToysSession
{
protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";
protected const string AppPath = "C:\\Program Files\\PowerToys\\PowerToys.exe";
protected static WindowsDriver<WindowsElement> session;
protected static bool isPowerToysLaunched = false;
protected static WindowsElement trayButton;
@@ -66,14 +68,27 @@ namespace PowerToysTests
{
Thread.Sleep(TimeSpan.FromSeconds(seconds));
}
public static void ShortWait()
{
Thread.Sleep(TimeSpan.FromSeconds(0.5));
//Trying to find element by XPath
protected static WindowsElement WaitElementByName(string name, double maxTime = 10)
{
WindowsElement result = null;
Stopwatch timer = new Stopwatch();
timer.Start();
while (timer.Elapsed < TimeSpan.FromSeconds(maxTime))
{
try
{
result = session.FindElementByName(name);
}
catch { }
return result;
}
return null;
}
//Trying to find element by XPath
protected WindowsElement WaitElementByXPath(string xPath, double maxTime = 10)
protected static WindowsElement WaitElementByXPath(string xPath, double maxTime = 10)
{
WindowsElement result = null;
Stopwatch timer = new Stopwatch();
@@ -85,17 +100,13 @@ namespace PowerToysTests
result = session.FindElementByXPath(xPath);
}
catch { }
if (result != null)
{
return result;
}
return result;
}
Assert.IsNotNull(result);
return null;
}
//Trying to find element by AccessibilityId
protected WindowsElement WaitElementByAccessibilityId(string accessibilityId, double maxTime = 10)
protected static WindowsElement WaitElementByAccessibilityId(string accessibilityId, double maxTime = 10)
{
WindowsElement result = null;
Stopwatch timer = new Stopwatch();
@@ -107,12 +118,8 @@ namespace PowerToysTests
result = session.FindElementByAccessibilityId(accessibilityId);
}
catch { }
if (result != null)
{
return result;
}
return result;
}
Assert.IsNotNull(result);
return null;
}
@@ -125,13 +132,11 @@ namespace PowerToysTests
public static void OpenFancyZonesSettings()
{
WindowsElement fzNavigationButton = session.FindElementByXPath("//Button[@Name=\"FancyZones\"]");
WindowsElement fzNavigationButton = WaitElementByXPath("//Button[@Name=\"FancyZones\"]");
Assert.IsNotNull(fzNavigationButton);
fzNavigationButton.Click();
fzNavigationButton.Click();
ShortWait();
}
public static void CloseSettings()
@@ -157,7 +162,7 @@ namespace PowerToysTests
try
{
WindowsElement pt = session.FindElementByXPath("//Button[@Name=\"PowerToys\"]");
WindowsElement pt = WaitElementByXPath("//Button[@Name=\"PowerToys\"]");
isLaunched = (pt != null);
}
catch(OpenQA.Selenium.WebDriverException)
@@ -174,11 +179,9 @@ namespace PowerToysTests
try
{
AppiumOptions opts = new AppiumOptions();
opts.PlatformName = "Windows";
opts.AddAdditionalCapability("platformVersion", "10");
opts.AddAdditionalCapability("deviceName", "WindowsPC");
opts.AddAdditionalCapability("app", "C:/Program Files/PowerToys/PowerToys.exe");
opts.PlatformName = "Windows";
opts.AddAdditionalCapability("app", AppPath);
WindowsDriver<WindowsElement> driver = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), opts);
Assert.IsNotNull(driver);
driver.LaunchApp();
@@ -195,13 +198,12 @@ namespace PowerToysTests
public static void ExitPowerToys()
{
trayButton.Click();
ShortWait();
WindowsElement pt = session.FindElementByXPath("//Button[@Name=\"PowerToys\"]");
WindowsElement pt = WaitElementByXPath("//Button[@Name=\"PowerToys\"]");
Assert.IsNotNull(pt, "Couldn't find \'PowerToys\' button");
new Actions(session).MoveToElement(pt).ContextClick().Perform();
ShortWait();
session.FindElementByXPath("//MenuItem[@Name=\"Exit\"]").Click();
WaitElementByXPath("//MenuItem[@Name=\"Exit\"]").Click();
trayButton.Click(); //close tray
isPowerToysLaunched = false;
}