Update Standard Mode Calculator UI Tests (#788)
Additional Standard mode UI Tests added.
This commit is contained in:
70
src/CalculatorUITestFramework/CalculatorApp.cs
Normal file
70
src/CalculatorUITestFramework/CalculatorApp.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Appium.Windows;
|
||||
using System.Drawing;
|
||||
|
||||
namespace CalculatorUITestFramework
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains the UI automation objects and helper methods available when the Calculator is in any mode.
|
||||
/// </summary>
|
||||
public static class CalculatorApp
|
||||
{
|
||||
public static WindowsElement Window => session.FindElementByClassName("Windows.UI.Core.CoreWindow");
|
||||
|
||||
internal static WindowsElement Header => session.TryFindElementByAccessibilityId("Header");
|
||||
|
||||
private static WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
|
||||
private static WindowsElement AppName => session.TryFindElementByAccessibilityId("AppName");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the text from the Header
|
||||
/// </summary>
|
||||
/// <returns>The string shown in the UI.</returns>
|
||||
public static string GetCalculatorHeaderText()
|
||||
{
|
||||
return Header.Text;
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Clicks the AppName element on Windows Calculator to ensure that the app has focus
|
||||
///// </summary>
|
||||
public static void EnsureCalculatorHasFocus()
|
||||
{
|
||||
AppName.Click();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the the Dock Panel for the History and Memory lists is not displayed, resize the window
|
||||
/// Two attempts are made, the the lable is not found a "not found" exception is thrown
|
||||
/// </summary>
|
||||
public static void ResizeWindowToDisplayMemoryHistoryDockPanel()
|
||||
{
|
||||
// Put the calculator in the upper left region of the screen
|
||||
WinAppDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
|
||||
GrowWindowToShowDock(WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Width);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Increases the size of the window until Dock Panel for the History/Memory panel is visible
|
||||
/// </summary>
|
||||
private static void GrowWindowToShowDock(int width)
|
||||
{
|
||||
if (width > 2100)
|
||||
{
|
||||
throw new NotFoundException("Could not the Dock Panel for the History and Memory lists");
|
||||
}
|
||||
|
||||
if (!session.PageSource.Contains("DockPanel"))
|
||||
{
|
||||
var height = WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Height;
|
||||
WinAppDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
|
||||
//give window time to render new size
|
||||
System.Threading.Thread.Sleep(10);
|
||||
GrowWindowToShowDock(width + 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
65
src/CalculatorUITestFramework/CalculatorResults.cs
Normal file
65
src/CalculatorUITestFramework/CalculatorResults.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenQA.Selenium.Appium.Windows;
|
||||
using System;
|
||||
|
||||
namespace CalculatorUITestFramework
|
||||
{
|
||||
public class CalculatorResults
|
||||
{
|
||||
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
|
||||
private WindowsElement CalculatorAlwaysOnTopResults => this.session.TryFindElementByAccessibilityId("CalculatorAlwaysOnTopResults");
|
||||
private WindowsElement CalculatorResult => this.session.TryFindElementByAccessibilityId("CalculatorResults");
|
||||
private WindowsElement CalculatorExpression => this.session.TryFindElementByAccessibilityId("CalculatorExpression");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the text from the display control in AoT mode and removes the narrator text that is not displayed in the UI.
|
||||
/// </summary>
|
||||
/// <returns>The string shown in the UI.</returns>
|
||||
public string GetAoTCalculatorResultText()
|
||||
{
|
||||
return this.CalculatorAlwaysOnTopResults.Text.Replace("Display is", string.Empty).Trim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the text from the display control and removes the narrator text that is not displayed in the UI.
|
||||
/// </summary>
|
||||
/// <returns>The string shown in the UI.</returns>
|
||||
public string GetCalculatorResultText()
|
||||
{
|
||||
return this.CalculatorResult.Text.Replace("Display is", string.Empty).Trim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the text from the Calculator Expression control and removes narrator text that is not displayed in the UI.
|
||||
/// </summary>
|
||||
/// <returns>The string shown in the UI.</returns>
|
||||
public string GetCalculatorExpressionText()
|
||||
{
|
||||
return this.CalculatorExpression.Text.Replace("Expression is", string.Empty).Trim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that CalculatorResult is not null
|
||||
/// </summary>
|
||||
/// <returns>The string shown in the UI.</returns>
|
||||
public void IsResultsDisplayPresent()
|
||||
{
|
||||
Assert.IsNotNull(this.CalculatorResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that Calculator Expression is clear
|
||||
/// </summary>
|
||||
/// <returns>The string shown in the UI.</returns>
|
||||
public void IsResultsExpressionClear()
|
||||
{
|
||||
string source = WinAppDriver.Instance.CalculatorSession.PageSource;
|
||||
if (source.Contains("CalculatorExpression"))
|
||||
{
|
||||
throw new Exception("The Calculator Expression is not clear");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,22 +1,34 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Appium.Windows;
|
||||
using OpenQA.Selenium.Interactions;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
|
||||
namespace CalculatorUITestFramework
|
||||
{
|
||||
public class HistoryPanel
|
||||
{
|
||||
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
|
||||
public WindowsElement HistoryLabel => this.session.TryFindElementByAccessibilityId("HistoryLabel");
|
||||
public WindowsElement HistoryListView => this.session.TryFindElementByAccessibilityId("HistoryListView");
|
||||
public WindowsElement HistoryButton => this.session.TryFindElementByAccessibilityId("HistoryButton");
|
||||
public WindowsElement ListViewItem => this.session.FindElementByClassName("ListViewItem");
|
||||
public WindowsElement ClearHistoryButton => this.session.TryFindElementByAccessibilityId("ClearHistory");
|
||||
public WindowsElement HistoryEmptyLabel => this.session.TryFindElementByAccessibilityId("HistoryEmpty");
|
||||
|
||||
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
|
||||
private WindowsElement HistoryLabel => this.session.TryFindElementByAccessibilityId("HistoryLabel");
|
||||
private WindowsElement HistoryListView => this.session.TryFindElementByAccessibilityId("HistoryListView");
|
||||
private WindowsElement HistoryFlyout => this.session.TryFindElementByAccessibilityId("HistoryFlyout");
|
||||
|
||||
/// <summary>
|
||||
/// Opens the History Pane by clicking the History pivot label.
|
||||
/// </summary>
|
||||
public void OpenHistoryPanel()
|
||||
{
|
||||
this.ResizeWindowToDisplayHistoryLabel();
|
||||
this.HistoryLabel.Click();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all of the history items listed in the History Pane.
|
||||
@@ -24,8 +36,7 @@ namespace CalculatorUITestFramework
|
||||
/// <returns>A readonly collection of history items.</returns>
|
||||
public ReadOnlyCollection<AppiumWebElement> GetAllHistoryListViewItems()
|
||||
{
|
||||
this.HistoryLabel.Click();
|
||||
this.HistoryListView.WaitForDisplayed();
|
||||
OpenHistoryPanel();
|
||||
return this.HistoryListView.FindElementsByClassName("ListViewItem");
|
||||
}
|
||||
|
||||
@@ -34,21 +45,96 @@ namespace CalculatorUITestFramework
|
||||
/// </summary>
|
||||
public void ClearHistory()
|
||||
{
|
||||
this.HistoryLabel.Click();
|
||||
|
||||
try
|
||||
this.HistoryLabel.Click();
|
||||
string source = this.session.PageSource;
|
||||
if (source.Contains("ClearHistory"))
|
||||
{
|
||||
this.ClearHistoryButton.Click();
|
||||
}
|
||||
catch(WebDriverException ex)
|
||||
{
|
||||
if (ex.Message.Contains("element could not be located"))
|
||||
{
|
||||
Assert.IsNotNull(this.HistoryEmptyLabel);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw;
|
||||
/// <summary>
|
||||
/// If the History label is not displayed, resize the window
|
||||
/// Two attempts are made; the label is not found a "not found" exception is thrown
|
||||
/// </summary>
|
||||
public void ResizeWindowToDisplayHistoryLabel()
|
||||
{
|
||||
// Put the calculator in the upper left region of the screen
|
||||
WinAppDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
|
||||
GrowWindowToShowHistoryLabel(WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Width);
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// If the History button is not displayed, resize the window
|
||||
///// </summary>
|
||||
public void ResizeWindowToDisplayHistoryButton()
|
||||
{
|
||||
// Put the calculator in the upper left region of the screen
|
||||
WinAppDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
|
||||
ShrinkWindowToShowHistoryButton(WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Width);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the History Flyout.
|
||||
/// </summary>
|
||||
public void OpenHistoryFlyout()
|
||||
{
|
||||
this.ResizeWindowToDisplayHistoryButton();
|
||||
CalculatorApp.EnsureCalculatorHasFocus();
|
||||
CalculatorApp.Window.SendKeys(Keys.Control + "h" + Keys.Control);
|
||||
Actions moveToHistoryFlyout = new Actions(WinAppDriver.Instance.CalculatorSession);
|
||||
moveToHistoryFlyout.MoveToElement(HistoryFlyout);
|
||||
moveToHistoryFlyout.Perform();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all of the History items listed in the History Flyout.
|
||||
/// </summary>
|
||||
/// <returns> A read only collection of History items.</returns>
|
||||
public ReadOnlyCollection<AppiumWebElement> GetAllHistoryFlyoutListViewItems()
|
||||
{
|
||||
OpenHistoryFlyout();
|
||||
return this.HistoryListView.FindElementsByClassName("ListViewItem");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Increases the size of the window until History label for the History panel is visible
|
||||
/// </summary>
|
||||
private void GrowWindowToShowHistoryLabel(int width)
|
||||
{
|
||||
if (width > 2100)
|
||||
{
|
||||
throw new NotFoundException("Could not the History Label");
|
||||
}
|
||||
|
||||
if (!this.session.PageSource.Contains("HistoryLabel"))
|
||||
{
|
||||
var height = WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Height;
|
||||
WinAppDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
|
||||
//give window time to render new size
|
||||
System.Threading.Thread.Sleep(10);
|
||||
GrowWindowToShowHistoryLabel(width + 100);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decreases the size of the window until History button is visible
|
||||
/// </summary>
|
||||
private void ShrinkWindowToShowHistoryButton(int width)
|
||||
{
|
||||
if (width < 200)
|
||||
{
|
||||
throw new NotFoundException("Could not find the History Button");
|
||||
}
|
||||
|
||||
if (!this.session.PageSource.Contains("HistoryButton"))
|
||||
{
|
||||
var height = WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Height;
|
||||
WinAppDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
|
||||
//give window time to render new size
|
||||
System.Threading.Thread.Sleep(10);
|
||||
ShrinkWindowToShowHistoryButton(width - 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,30 +1,40 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Appium.Windows;
|
||||
using OpenQA.Selenium.Interactions;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
|
||||
namespace CalculatorUITestFramework
|
||||
{
|
||||
public class MemoryPanel
|
||||
{
|
||||
public WindowsElement NumberpadMCButton => this.session.TryFindElementByAccessibilityId("ClearMemoryButton");
|
||||
public WindowsElement NumberpadMRButton => this.session.TryFindElementByAccessibilityId("MemRecall");
|
||||
public WindowsElement NumberpadMPlusButton => this.session.TryFindElementByAccessibilityId("MemPlus");
|
||||
public WindowsElement NumberpadMMinusButton => this.session.TryFindElementByAccessibilityId("MemMinus");
|
||||
public WindowsElement NumberpadMSButton => this.session.TryFindElementByAccessibilityId("memButton");
|
||||
public WindowsElement MemoryFlyoutButton => this.session.TryFindElementByAccessibilityId("MemoryButton");
|
||||
public WindowsElement PanelClearMemoryButton => this.session.TryFindElementByAccessibilityId("ClearMemory");
|
||||
public WindowsElement ListViewItem => this.session.FindElementByClassName("ListViewItem");
|
||||
|
||||
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
|
||||
public WindowsElement MemoryClear => this.session.TryFindElementByAccessibilityId("ClearMemoryButton");
|
||||
public WindowsElement MemRecall => this.session.TryFindElementByAccessibilityId("MemRecall");
|
||||
public WindowsElement MemPlus => this.session.TryFindElementByAccessibilityId("MemPlus");
|
||||
public WindowsElement MemMinus => this.session.TryFindElementByAccessibilityId("MemMinus");
|
||||
public WindowsElement MemButton => this.session.TryFindElementByAccessibilityId("memButton");
|
||||
public WindowsElement MemoryPane => this.session.TryFindElementByAccessibilityId("MemoryPanel");
|
||||
public WindowsElement MemoryLabel => this.session.TryFindElementByAccessibilityId("MemoryLabel");
|
||||
public WindowsElement MemoryListView => this.session.TryFindElementByAccessibilityId("MemoryListView");
|
||||
public WindowsElement MemoryPaneEmptyLabel => this.session.TryFindElementByAccessibilityId("MemoryPaneEmpty");
|
||||
private WindowsElement MemoryPane => this.session.TryFindElementByAccessibilityId("MemoryPanel");
|
||||
private WindowsElement MemoryLabel => this.session.TryFindElementByAccessibilityId("MemoryLabel");
|
||||
private WindowsElement MemoryListView => this.session.TryFindElementByAccessibilityId("MemoryListView");
|
||||
private WindowsElement MemoryPaneEmptyLabel => this.session.TryFindElementByAccessibilityId("MemoryPaneEmpty");
|
||||
private WindowsElement MemoryFlyout => this.session.TryFindElementByAccessibilityId("MemoryFlyout");
|
||||
|
||||
/// <summary>
|
||||
/// Opens the Memory Pane by clicking the Memory pivot label.
|
||||
/// </summary>
|
||||
public void OpenMemoryPanel()
|
||||
{
|
||||
this.ResizeWindowToDisplayMemoryLabel();
|
||||
this.MemoryLabel.Click();
|
||||
this.MemoryPane.WaitForDisplayed();
|
||||
}
|
||||
@@ -38,5 +48,119 @@ namespace CalculatorUITestFramework
|
||||
OpenMemoryPanel();
|
||||
return this.MemoryListView.FindElementsByClassName("ListViewItem");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the Memory Panel and clicks the delete button if it is visible
|
||||
/// </summary>
|
||||
public void ClearMemoryPanel()
|
||||
{
|
||||
this.MemoryLabel.Click();
|
||||
|
||||
try
|
||||
{
|
||||
if (this.session.PageSource.Contains("ClearMemoryButton"))
|
||||
{
|
||||
this.PanelClearMemoryButton.Click();
|
||||
}
|
||||
}
|
||||
catch (WebDriverException ex)
|
||||
{
|
||||
if (ex.Message.Contains("element could not be located"))
|
||||
{
|
||||
Assert.IsNotNull(this.MemoryPaneEmptyLabel);
|
||||
return;
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the Memory label is not displayed, resize the window
|
||||
/// Two attempts are made, the the lable is not found a "not found" exception is thrown
|
||||
/// </summary>
|
||||
public void ResizeWindowToDisplayMemoryLabel()
|
||||
{
|
||||
// Put the calculator in the upper left region of the screen
|
||||
WinAppDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
|
||||
GrowWindowToShowMemoryLabel(WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Width);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the Memory button is not displayed, resize the window
|
||||
/// </summary>
|
||||
public void ResizeWindowToDisplayMemoryButton()
|
||||
{
|
||||
// Put the calculator in the upper left region of the screen
|
||||
WinAppDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
|
||||
ShrinkWindowToShowMemoryButton(WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Width);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the Memory Flyout.
|
||||
/// </summary>
|
||||
public void OpenMemoryFlyout()
|
||||
{
|
||||
this.ResizeWindowToDisplayMemoryButton();
|
||||
CalculatorApp.EnsureCalculatorHasFocus();
|
||||
Actions moveToMemoryButton = new Actions(WinAppDriver.Instance.CalculatorSession);
|
||||
moveToMemoryButton.MoveToElement(MemoryFlyoutButton);
|
||||
moveToMemoryButton.Perform();
|
||||
CalculatorApp.Window.SendKeys(Keys.Alt + "m" + Keys.Alt);
|
||||
Actions moveToMemoryFlyout = new Actions(WinAppDriver.Instance.CalculatorSession);
|
||||
moveToMemoryFlyout.MoveToElement(MemoryFlyout);
|
||||
moveToMemoryFlyout.Perform();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all of the memory items listed in the Memory Flyout.
|
||||
/// </summary>
|
||||
/// <returns> A read only collection of memory items.</returns>
|
||||
public ReadOnlyCollection<AppiumWebElement> GetAllMemoryFlyoutListViewItems()
|
||||
{
|
||||
OpenMemoryFlyout();
|
||||
return this.MemoryListView.FindElementsByClassName("ListViewItem");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Increases the size of the window until Memory label for the Memory panel is visible
|
||||
/// </summary>
|
||||
private void GrowWindowToShowMemoryLabel(int width)
|
||||
{
|
||||
if (width > 2100)
|
||||
{
|
||||
throw new NotFoundException("Could not the Memory Label");
|
||||
}
|
||||
|
||||
if (!this.session.PageSource.Contains("MemoryLabel"))
|
||||
{
|
||||
var height = WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Height;
|
||||
WinAppDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
|
||||
//give window time to render new size
|
||||
System.Threading.Thread.Sleep(10);
|
||||
GrowWindowToShowMemoryLabel(width + 100);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decreases the size of the window until Memory button is visible
|
||||
/// </summary>
|
||||
private void ShrinkWindowToShowMemoryButton(int width)
|
||||
{
|
||||
if (width < 200)
|
||||
{
|
||||
throw new NotFoundException("Could not find the Memory Button");
|
||||
}
|
||||
|
||||
//Page source contains differnt memory button types, using hotkey info is for this specific memory button
|
||||
if (!this.session.PageSource.Contains("Alt, M"))
|
||||
{
|
||||
var height = WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Height;
|
||||
WinAppDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
|
||||
//give window time to render new size
|
||||
System.Threading.Thread.Sleep(10);
|
||||
ShrinkWindowToShowMemoryButton(width - 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,13 +26,14 @@ namespace CalculatorUITestFramework
|
||||
Pressure,
|
||||
Angle
|
||||
}
|
||||
|
||||
public class NavigationMenu
|
||||
{
|
||||
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
|
||||
|
||||
public WindowsElement NavigationMenuButton => this.session.TryFindElementByAccessibilityId("TogglePaneButton");
|
||||
public WindowsElement NavigationMenuPane => this.session.TryFindElementByClassName("SplitViewPane");
|
||||
|
||||
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
|
||||
|
||||
/// <summary>
|
||||
/// Changes the mode using the navigation menu in the UI
|
||||
/// </summary>
|
||||
|
@@ -8,7 +8,6 @@ namespace CalculatorUITestFramework
|
||||
{
|
||||
public class NumberPad
|
||||
{
|
||||
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
|
||||
public WindowsElement Num0Button => this.session.TryFindElementByAccessibilityId("num0Button");
|
||||
public WindowsElement Num1Button => this.session.TryFindElementByAccessibilityId("num1Button");
|
||||
public WindowsElement Num2Button => this.session.TryFindElementByAccessibilityId("num2Button");
|
||||
@@ -22,6 +21,8 @@ namespace CalculatorUITestFramework
|
||||
public WindowsElement DecimalButton => this.session.TryFindElementByAccessibilityId("decimalSeparatorButton");
|
||||
public WindowsElement NegateButton => this.session.TryFindElementByAccessibilityId("negateButton");
|
||||
|
||||
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
|
||||
|
||||
/// <summary>
|
||||
/// Translates a number into the Calculator button clicks.
|
||||
/// </summary>
|
||||
|
164
src/CalculatorUITestFramework/StandardAoTCalculatorPage.cs
Normal file
164
src/CalculatorUITestFramework/StandardAoTCalculatorPage.cs
Normal file
@@ -0,0 +1,164 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Appium.Windows;
|
||||
using OpenQA.Selenium.Interactions;
|
||||
using System.Drawing;
|
||||
|
||||
namespace CalculatorUITestFramework
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains the UI automation objects and helper methods available when the Calculator is in Standard / AoT Mode.
|
||||
/// </summary>
|
||||
public class StandardAoTCalculatorPage
|
||||
{
|
||||
public StandardOperatorsPanel StandardOperators = new StandardOperatorsPanel();
|
||||
public NavigationMenu NavigationMenu = new NavigationMenu();
|
||||
public WindowsElement EnterAlwaysOnTopButton => this.session.TryFindElementByAccessibilityId("NormalAlwaysOnTopButton");
|
||||
public WindowsElement ExitAlwaysOnTopButton => this.session.TryFindElementByAccessibilityId("ExitAlwaysOnTopButton");
|
||||
public AppiumWebElement ToolTip => WinAppDriver.Instance.CalculatorSession.FindElementByClassName("ToolTip").FindElementByClassName("TextBlock");
|
||||
|
||||
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
|
||||
|
||||
///// <summary>
|
||||
///// Navigates from AoT(Keep on top) to Standard
|
||||
///// </summary>
|
||||
public void NavigateToStandardMode()
|
||||
{
|
||||
string source = this.session.PageSource;
|
||||
if (source.Contains("ExitAlwaysOnTopButton"))
|
||||
{
|
||||
this.ExitAlwaysOnTopButton.Click();
|
||||
Assert.AreEqual("Standard", CalculatorApp.GetCalculatorHeaderText());
|
||||
}
|
||||
else
|
||||
{
|
||||
source = this.session.PageSource;
|
||||
if (source.Contains("NormalAlwaysOnTopButton"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotFoundException("Could not find the 'Keep on top' button");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Ensures the calculator is in AoT(Keep on top) mode, and verifies that the AoT mode through the absence of the header
|
||||
///// </summary>
|
||||
public void NavigateToStandardAoTMode()
|
||||
{
|
||||
string source = this.session.PageSource;
|
||||
if (source.Contains("NormalAlwaysOnTopButton"))
|
||||
{
|
||||
this.EnterAlwaysOnTopButton.Click();
|
||||
this.ExitAlwaysOnTopButton.WaitForDisplayed();
|
||||
source = WinAppDriver.Instance.CalculatorSession.PageSource;
|
||||
if (source.Contains("Header"))
|
||||
{
|
||||
throw new NotFoundException("Failed to enter 'Keep on top' mode; In AoT mode, Calculator does not have header");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Gets the AoT ToolTip text
|
||||
///// </summary>
|
||||
public string GetAoTToolTipText()
|
||||
{
|
||||
string source = this.session.PageSource;
|
||||
if ((source.Contains("Keep on top")) || (source.Contains("Back to full view")))
|
||||
{
|
||||
if (source.Contains("Keep on top"))
|
||||
{
|
||||
Actions moveToAoTButton = new Actions(WinAppDriver.Instance.CalculatorSession);
|
||||
moveToAoTButton.MoveToElement(EnterAlwaysOnTopButton);
|
||||
moveToAoTButton.Perform();
|
||||
}
|
||||
else
|
||||
{
|
||||
Actions moveToBackToFullViewVButton = new Actions(WinAppDriver.Instance.CalculatorSession);
|
||||
moveToBackToFullViewVButton.MoveToElement(ExitAlwaysOnTopButton);
|
||||
moveToBackToFullViewVButton.Perform();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotFoundException("Could not find 'Keep on top' button or 'Back to full view' button");
|
||||
}
|
||||
var ToolTipText = ToolTip.Text.ToString();
|
||||
return ToolTipText;
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Checks in AoT (Keep on top) button is present
|
||||
///// </summary>
|
||||
public string GetAoTPresence()
|
||||
{
|
||||
bool AoTPresent;
|
||||
string source = this.session.PageSource;
|
||||
if (source.Contains("Keep on top"))
|
||||
{
|
||||
AoTPresent = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
AoTPresent = false;
|
||||
}
|
||||
return AoTPresent.ToString();
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Checks Standard calculator to see if it's in AoT (Keep on top)
|
||||
///// </summary>
|
||||
public string AoTModeCheck()
|
||||
{
|
||||
bool InAoTMode;
|
||||
string source = this.session.PageSource;
|
||||
if ((source.Contains("Keep on top")) && (source.Contains("Header")))
|
||||
{
|
||||
InAoTMode = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
InAoTMode = true;
|
||||
}
|
||||
return InAoTMode.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the Invert button is not displayed, resize the window
|
||||
/// Two attempts are made, the the button is not found a "not found" exception is thrown
|
||||
/// </summary>
|
||||
public void ResizeAoTWindowToDisplayInvertButton()
|
||||
{
|
||||
// Put the calculator in the upper left region of the screen
|
||||
WinAppDriver.Instance.CalculatorSession.Manage().Window.Position = new Point(8, 8);
|
||||
GrowWindowToShowInvertButton(WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Increases the size of the window until History label for the History panel is visible
|
||||
/// </summary>
|
||||
private void GrowWindowToShowInvertButton(int height)
|
||||
{
|
||||
if (height > 1000)
|
||||
{
|
||||
throw new NotFoundException("Could not find the Invert Button");
|
||||
}
|
||||
|
||||
if (!this.session.PageSource.Contains("invertButton"))
|
||||
{
|
||||
var width = WinAppDriver.Instance.CalculatorSession.Manage().Window.Size.Width;
|
||||
WinAppDriver.Instance.CalculatorSession.Manage().Window.Size = new Size(width, height);
|
||||
//give window time to render new size
|
||||
System.Threading.Thread.Sleep(10);
|
||||
GrowWindowToShowInvertButton(width + 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenQA.Selenium.Appium.Windows;
|
||||
|
||||
namespace CalculatorUITestFramework
|
||||
@@ -11,20 +10,23 @@ namespace CalculatorUITestFramework
|
||||
/// </summary>
|
||||
public class StandardCalculatorPage
|
||||
{
|
||||
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
|
||||
public StandardOperatorsPanel StandardOperators = new StandardOperatorsPanel();
|
||||
public MemoryPanel MemoryPanel = new MemoryPanel();
|
||||
public HistoryPanel HistoryPanel = new HistoryPanel();
|
||||
public NavigationMenu NavigationMenu = new NavigationMenu();
|
||||
public WindowsElement Header => this.session.TryFindElementByAccessibilityId("Header");
|
||||
public StandardAoTCalculatorPage StandardAoTCalculatorPage = new StandardAoTCalculatorPage();
|
||||
public CalculatorResults CalculatorResults = new CalculatorResults();
|
||||
|
||||
public WindowsElement CalculatorResult => this.session.TryFindElementByAccessibilityId("CalculatorResults");
|
||||
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
|
||||
|
||||
/// <summary>
|
||||
/// Navigates the caclulator to Standard mode and ensures that it is in standard mode
|
||||
/// </summary>
|
||||
public void NavigateToStandardCalculator()
|
||||
{
|
||||
// Ensure that calculator is in standard mode
|
||||
this.NavigationMenu.ChangeCalculatorMode(CalculatorMode.StandardCalculator);
|
||||
Assert.IsNotNull(CalculatorResult);
|
||||
this.CalculatorResults.IsResultsDisplayPresent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -32,18 +34,47 @@ namespace CalculatorUITestFramework
|
||||
/// </summary>
|
||||
public void ClearAll()
|
||||
{
|
||||
this.StandardAoTCalculatorPage.NavigateToStandardMode();
|
||||
this.MemoryPanel.ResizeWindowToDisplayMemoryLabel();
|
||||
this.StandardOperators.ClearButton.Click();
|
||||
this.MemoryPanel.MemoryClear.Click();
|
||||
this.MemoryPanel.NumberpadMCButton.Click();
|
||||
this.HistoryPanel.ClearHistory();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the text from the display control and removes the narrator text that is not displayed in the UI.
|
||||
/// </summary>
|
||||
/// <returns>The string shown in the UI.</returns>
|
||||
public string GetCalculatorResultText()
|
||||
///// <summary>
|
||||
///// Ensures that the calculator result text is zero; if not, clears all
|
||||
///// </summary>
|
||||
public void EnsureCalculatorResultTextIsZero()
|
||||
{
|
||||
return this.CalculatorResult.Text.Replace("Display is", string.Empty).Trim();
|
||||
if ("0" != this.CalculatorResults.GetCalculatorResultText())
|
||||
{
|
||||
this.ClearAll();
|
||||
}
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Ensures that the calculator is in Standard Mode
|
||||
///// </summary>
|
||||
public void EnsureCalculatorIsInStandardMode()
|
||||
{
|
||||
string source = WinAppDriver.Instance.CalculatorSession.PageSource;
|
||||
if (source.Contains("Header"))
|
||||
{
|
||||
string header = CalculatorApp.Header.Text;
|
||||
if (header == "Standard")
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.NavigateToStandardCalculator();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.StandardAoTCalculatorPage.NavigateToStandardMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using OpenQA.Selenium.Appium.Windows;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CalculatorUITestFramework
|
||||
{
|
||||
@@ -27,5 +26,7 @@ namespace CalculatorUITestFramework
|
||||
public WindowsElement ClearEntryButton => this.session.TryFindElementByAccessibilityId("clearEntryButton");
|
||||
public WindowsElement ClearButton => this.session.TryFindElementByAccessibilityId("clearButton");
|
||||
public WindowsElement BackSpaceButton => this.session.TryFindElementByAccessibilityId("backSpaceButton");
|
||||
public WindowsElement NegateButton => this.session.TryFindElementByAccessibilityId("negateButton");
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,6 @@ namespace CalculatorUITestFramework
|
||||
|
||||
public WindowsDriver<WindowsElement> CalculatorSession { get; private set; }
|
||||
|
||||
|
||||
private WinAppDriver()
|
||||
{
|
||||
}
|
||||
@@ -88,6 +87,5 @@ namespace CalculatorUITestFramework
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user