calculator/src/CalculatorUITestFramework/WindowsElementExtensions.cs
Stephanie Anderl 2517854836 Added Calculator Standard Mode UI Tests (#501)
- Added the CalculatorUIFramework to handle the WinAppDriver logic.
- Added Standard Mode smoke tests and BVTs to the CalculatorUITests project.
- Removed old UI tests that did not use the CalculatorUIFramework
2019-06-21 14:54:36 -07:00

40 lines
1.3 KiB
C#

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting.Logging;
using OpenQA.Selenium.Appium.Windows;
using System;
using System.Diagnostics;
using System.Threading;
namespace CalculatorUITestFramework
{
public static class WindowsElementExtensions
{
/// <summary>
/// Waits for an element to be displayed until the timeout is reached.
/// </summary>
/// <param name="element">WindowsElement in the Calculator application.</param>
/// <param name="timeout">Timeout in ms.</param>
public static void WaitForDisplayed(this WindowsElement element, int timeout = 2000)
{
Stopwatch timer = new Stopwatch();
timer.Reset();
timer.Start();
while (timer.ElapsedMilliseconds < timeout)
{
if (element.Displayed)
{
timer.Stop();
return;
}
Logger.LogMessage("Waiting for 10ms in WaitForDisplayed");
Thread.Sleep(10);
}
timer.Stop();
Assert.Fail(String.Format("{0} was not displayed in {1} ms", element, timeout));
}
}
}