fix UI tests in lab runs (#1375)
This commit is contained in:
@@ -13,8 +13,6 @@ namespace CalculatorUITestFramework
|
||||
private WindowsElement CalculatorAlwaysOnTopResults => this.session.TryFindElementByAccessibilityId("CalculatorAlwaysOnTopResults");
|
||||
private WindowsElement CalculatorResult => this.session.TryFindElementByAccessibilityId("CalculatorResults");
|
||||
private WindowsElement CalculatorExpression => this.session.TryFindElementByAccessibilityId("CalculatorExpression");
|
||||
private WindowsElement MenuItemCopy => this.session.WaitForElementByAccessibilityId("CopyMenuItem");
|
||||
private WindowsElement MenuItemPaste => this.session.WaitForElementByAccessibilityId("PasteMenuItem");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the text from the display control in AoT mode and removes the narrator text that is not displayed in the UI.
|
||||
@@ -64,33 +62,5 @@ namespace CalculatorUITestFramework
|
||||
throw new Exception("The Calculator Expression is not clear");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the context menu in order to be able to click its items
|
||||
/// </summary>
|
||||
private void OpenContextMenu()
|
||||
{
|
||||
Actions actions = new Actions(CalculatorResult.WrappedDriver);
|
||||
// It is important to move not to the centre in order to avoid click on the text
|
||||
actions.MoveToElement(CalculatorResult, 1,1).ContextClick().Perform();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the context menu and clicks the "Copy" item there
|
||||
/// </summary>
|
||||
public void ContextMenuItemCopyClick()
|
||||
{
|
||||
OpenContextMenu();
|
||||
MenuItemCopy.Click();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the context menu and clicks the "Paste" item there
|
||||
/// </summary>
|
||||
public void ContextMenuItemPasteClick()
|
||||
{
|
||||
OpenContextMenu();
|
||||
MenuItemPaste.Click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,8 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting.Logging;
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Appium.Windows;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
|
||||
namespace CalculatorUITestFramework
|
||||
{
|
||||
@@ -71,43 +68,5 @@ namespace CalculatorUITestFramework
|
||||
// process id (any entry of allWindowHandles)
|
||||
driver.SwitchTo().Window(allWindowHandles[0]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Waits for an element to be created.
|
||||
/// </summary>
|
||||
/// <param name="driver">this</param>
|
||||
/// <param name="id">the automation id</param>
|
||||
/// <param name="timeout">optional timeout in ms</param>
|
||||
/// <returns>the element with the matching automation id</returns>
|
||||
public static WindowsElement WaitForElementByAccessibilityId(this WindowsDriver<WindowsElement> driver, string id, int timeout = 1000)
|
||||
{
|
||||
Stopwatch timer = new Stopwatch();
|
||||
timer.Reset();
|
||||
timer.Start();
|
||||
while (timer.ElapsedMilliseconds < timeout)
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = driver.TryFindElementByAccessibilityId(id);
|
||||
return element;
|
||||
}
|
||||
catch(WebDriverException ex)
|
||||
{
|
||||
if (ex.Message.Contains("An element could not be located on the page using the given search parameters"))
|
||||
{
|
||||
Logger.LogMessage("Element not found. Waiting for 10ms in WaitForElementByAccessibilityId");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
timer.Stop();
|
||||
|
||||
// one last attempt. Throws the not found exception if this fails
|
||||
return driver.TryFindElementByAccessibilityId(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user