fix UI tests in lab runs (#1375)

This commit is contained in:
Eric Wong 2020-09-21 18:07:31 -07:00 committed by GitHub
parent 3f11e906bd
commit 41c182f45d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 133 deletions

View File

@ -13,8 +13,6 @@ public class CalculatorResults
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 @@ public void IsResultsExpressionClear()
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();
}
}
}

View File

@ -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 @@ public static void SwitchToCurrentWindowHandle(this WindowsDriver<WindowsElement
// 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);
}
}
}

View File

@ -899,10 +899,10 @@ public void Copy_And_Paste_Simple_Number()
{
page.ProgrammerOperators.BitFlip.Click();
page.ProgrammerOperators.Bit1.Click();
page.CalculatorResults.ContextMenuItemCopyClick();
CalculatorApp.Window.SendKeys(Keys.Control + "c" + Keys.Control);
page.ProgrammerOperators.FullKeypad.Click();
page.StandardOperators.ClearEntryButton.Click();
page.CalculatorResults.ContextMenuItemPasteClick();
CalculatorApp.Window.SendKeys(Keys.Control + "v" + Keys.Control);
Assert.AreEqual("2", page.CalculatorResults.GetCalculatorResultText());
}
@ -912,71 +912,13 @@ public void Copy_And_Paste_Invalid_Number()
{
page.ProgrammerOperators.BitFlip.Click();
page.ProgrammerOperators.Bit63.Click();
page.CalculatorResults.ContextMenuItemCopyClick();
CalculatorApp.Window.SendKeys(Keys.Control + "c" + Keys.Control);
page.ProgrammerOperators.FullKeypad.Click();
page.StandardOperators.ClearEntryButton.Click();
page.ProgrammerOperators.QWordButton.Click();
page.CalculatorResults.ContextMenuItemPasteClick();
CalculatorApp.Window.SendKeys(Keys.Control + "v" + Keys.Control);
Assert.AreEqual("Invalid input", page.CalculatorResults.GetCalculatorResultText());
}
[TestMethod]
[Priority(1)]
public void Copy_And_Paste_Big_QWord_Number()
{
page.ProgrammerOperators.BitFlip.Click();
page.ProgrammerOperators.Bit63.Click();
page.CalculatorResults.ContextMenuItemCopyClick();
page.ProgrammerOperators.FullKeypad.Click();
page.StandardOperators.ClearEntryButton.Click();
page.CalculatorResults.ContextMenuItemPasteClick();
Assert.AreEqual("-9,223,372,036,854,775,808", page.CalculatorResults.GetCalculatorResultText());
}
[TestMethod]
[Priority(1)]
public void Copy_And_Paste_Big_DWord_Number()
{
page.ProgrammerOperators.QWordButton.Click();
page.ProgrammerOperators.BitFlip.Click();
page.ProgrammerOperators.Bit31.Click();
page.CalculatorResults.ContextMenuItemCopyClick();
page.ProgrammerOperators.FullKeypad.Click();
page.StandardOperators.ClearEntryButton.Click();
page.CalculatorResults.ContextMenuItemPasteClick();
Assert.AreEqual("-2,147,483,648", page.CalculatorResults.GetCalculatorResultText());
}
[TestMethod]
[Priority(1)]
public void Copy_And_Paste_Big_Word_Number()
{
page.ProgrammerOperators.QWordButton.Click();
page.ProgrammerOperators.DWordButton.Click();
page.ProgrammerOperators.BitFlip.Click();
page.ProgrammerOperators.Bit15.Click();
page.CalculatorResults.ContextMenuItemCopyClick();
page.ProgrammerOperators.FullKeypad.Click();
page.StandardOperators.ClearEntryButton.Click();
page.CalculatorResults.ContextMenuItemPasteClick();
Assert.AreEqual("-32,768", page.CalculatorResults.GetCalculatorResultText());
}
[TestMethod]
[Priority(1)]
public void Copy_And_Paste_Big_Byte_Number()
{
page.ProgrammerOperators.QWordButton.Click();
page.ProgrammerOperators.DWordButton.Click();
page.ProgrammerOperators.WordButton.Click();
page.ProgrammerOperators.BitFlip.Click();
page.ProgrammerOperators.Bit7.Click();
page.CalculatorResults.ContextMenuItemCopyClick();
page.ProgrammerOperators.FullKeypad.Click();
page.StandardOperators.ClearEntryButton.Click();
page.CalculatorResults.ContextMenuItemPasteClick();
Assert.AreEqual("-128", page.CalculatorResults.GetCalculatorResultText());
}
#endregion
}
}