diff --git a/src/Calculator.sln b/src/Calculator.sln index bf9290a4..43a46f9c 100644 --- a/src/Calculator.sln +++ b/src/Calculator.sln @@ -105,6 +105,38 @@ Global {D3BAED2C-4B07-4E1D-8807-9D6499450349}.Release|x86.ActiveCfg = Release|Win32 {D3BAED2C-4B07-4E1D-8807-9D6499450349}.Release|x86.Build.0 = Release|Win32 {D3BAED2C-4B07-4E1D-8807-9D6499450349}.Release|x86.Deploy.0 = Release|Win32 + {B2C5ADFF-D6B5-48C1-BB8C-571BFD583D7F}.Debug|ARM.ActiveCfg = Debug|Any CPU + {B2C5ADFF-D6B5-48C1-BB8C-571BFD583D7F}.Debug|ARM.Build.0 = Debug|Any CPU + {B2C5ADFF-D6B5-48C1-BB8C-571BFD583D7F}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {B2C5ADFF-D6B5-48C1-BB8C-571BFD583D7F}.Debug|ARM64.Build.0 = Debug|Any CPU + {B2C5ADFF-D6B5-48C1-BB8C-571BFD583D7F}.Debug|x64.ActiveCfg = Debug|Any CPU + {B2C5ADFF-D6B5-48C1-BB8C-571BFD583D7F}.Debug|x64.Build.0 = Debug|Any CPU + {B2C5ADFF-D6B5-48C1-BB8C-571BFD583D7F}.Debug|x86.ActiveCfg = Debug|Any CPU + {B2C5ADFF-D6B5-48C1-BB8C-571BFD583D7F}.Debug|x86.Build.0 = Debug|Any CPU + {B2C5ADFF-D6B5-48C1-BB8C-571BFD583D7F}.Release|ARM.ActiveCfg = Release|Any CPU + {B2C5ADFF-D6B5-48C1-BB8C-571BFD583D7F}.Release|ARM.Build.0 = Release|Any CPU + {B2C5ADFF-D6B5-48C1-BB8C-571BFD583D7F}.Release|ARM64.ActiveCfg = Release|Any CPU + {B2C5ADFF-D6B5-48C1-BB8C-571BFD583D7F}.Release|ARM64.Build.0 = Release|Any CPU + {B2C5ADFF-D6B5-48C1-BB8C-571BFD583D7F}.Release|x64.ActiveCfg = Release|Any CPU + {B2C5ADFF-D6B5-48C1-BB8C-571BFD583D7F}.Release|x64.Build.0 = Release|Any CPU + {B2C5ADFF-D6B5-48C1-BB8C-571BFD583D7F}.Release|x86.ActiveCfg = Release|Any CPU + {B2C5ADFF-D6B5-48C1-BB8C-571BFD583D7F}.Release|x86.Build.0 = Release|Any CPU + {96454213-94AF-457D-9DF9-B14F80E7770F}.Debug|ARM.ActiveCfg = Debug|Any CPU + {96454213-94AF-457D-9DF9-B14F80E7770F}.Debug|ARM.Build.0 = Debug|Any CPU + {96454213-94AF-457D-9DF9-B14F80E7770F}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {96454213-94AF-457D-9DF9-B14F80E7770F}.Debug|ARM64.Build.0 = Debug|Any CPU + {96454213-94AF-457D-9DF9-B14F80E7770F}.Debug|x64.ActiveCfg = Debug|Any CPU + {96454213-94AF-457D-9DF9-B14F80E7770F}.Debug|x64.Build.0 = Debug|Any CPU + {96454213-94AF-457D-9DF9-B14F80E7770F}.Debug|x86.ActiveCfg = Debug|Any CPU + {96454213-94AF-457D-9DF9-B14F80E7770F}.Debug|x86.Build.0 = Debug|Any CPU + {96454213-94AF-457D-9DF9-B14F80E7770F}.Release|ARM.ActiveCfg = Release|Any CPU + {96454213-94AF-457D-9DF9-B14F80E7770F}.Release|ARM.Build.0 = Release|Any CPU + {96454213-94AF-457D-9DF9-B14F80E7770F}.Release|ARM64.ActiveCfg = Release|Any CPU + {96454213-94AF-457D-9DF9-B14F80E7770F}.Release|ARM64.Build.0 = Release|Any CPU + {96454213-94AF-457D-9DF9-B14F80E7770F}.Release|x64.ActiveCfg = Release|Any CPU + {96454213-94AF-457D-9DF9-B14F80E7770F}.Release|x64.Build.0 = Release|Any CPU + {96454213-94AF-457D-9DF9-B14F80E7770F}.Release|x86.ActiveCfg = Release|Any CPU + {96454213-94AF-457D-9DF9-B14F80E7770F}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/CalculatorUITestFramework/HistoryPanel.cs b/src/CalculatorUITestFramework/HistoryPanel.cs index bb69037e..a7cf3ec1 100644 --- a/src/CalculatorUITestFramework/HistoryPanel.cs +++ b/src/CalculatorUITestFramework/HistoryPanel.cs @@ -1,32 +1,21 @@ + + using Microsoft.VisualStudio.TestTools.UnitTesting; -using Microsoft.VisualStudio.TestTools.UnitTesting.Logging; using OpenQA.Selenium; using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.Windows; -using System; -using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace CalculatorUITestFramework { public class HistoryPanel { private WindowsDriver session => WinAppDriver.Instance.CalculatorSession; - public WindowsElement HistoryLabel => session.TryFindElementByAccessibilityId("HistoryLabel"); - public WindowsElement HistoryListView => session.TryFindElementByAccessibilityId("HistoryListView"); - public WindowsElement ClearHistoryButton => session.TryFindElementByAccessibilityId("ClearHistory"); - public WindowsElement HistoryEmptyLabel => session.TryFindElementByAccessibilityId("HistoryEmpty"); + public WindowsElement HistoryLabel => this.session.TryFindElementByAccessibilityId("HistoryLabel"); + public WindowsElement HistoryListView => this.session.TryFindElementByAccessibilityId("HistoryListView"); + public WindowsElement ClearHistoryButton => this.session.TryFindElementByAccessibilityId("ClearHistory"); + public WindowsElement HistoryEmptyLabel => this.session.TryFindElementByAccessibilityId("HistoryEmpty"); - /// - /// Opens the History Pane by clicking the History pivot label. - /// - public void OpenHistoryPanel() - { - HistoryLabel.Click(); - } /// /// Gets all of the history items listed in the History Pane. @@ -34,9 +23,9 @@ namespace CalculatorUITestFramework /// A readonly collection of history items. public ReadOnlyCollection GetAllHistoryListViewItems() { - OpenHistoryPanel(); - HistoryListView.WaitForDisplayed(); - return HistoryListView.FindElementsByClassName("ListViewItem"); + this.HistoryLabel.Click(); + this.HistoryListView.WaitForDisplayed(); + return this.HistoryListView.FindElementsByClassName("ListViewItem"); } /// @@ -44,17 +33,17 @@ namespace CalculatorUITestFramework /// public void ClearHistory() { - OpenHistoryPanel(); + this.HistoryLabel.Click(); try { - ClearHistoryButton.Click(); + this.ClearHistoryButton.Click(); } catch(WebDriverException ex) { if (ex.Message.Contains("element could not be located")) { - Assert.IsNotNull(HistoryEmptyLabel); + Assert.IsNotNull(this.HistoryEmptyLabel); return; } diff --git a/src/CalculatorUITestFramework/MemoryPanel.cs b/src/CalculatorUITestFramework/MemoryPanel.cs index 1f71eacf..cb32396d 100644 --- a/src/CalculatorUITestFramework/MemoryPanel.cs +++ b/src/CalculatorUITestFramework/MemoryPanel.cs @@ -1,35 +1,32 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.Windows; -using System; -using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace CalculatorUITestFramework { public class MemoryPanel { private WindowsDriver session => WinAppDriver.Instance.CalculatorSession; - public WindowsElement MemoryClear => session.TryFindElementByAccessibilityId("ClearMemoryButton"); - public WindowsElement MemRecall => session.TryFindElementByAccessibilityId("MemRecall"); - public WindowsElement MemPlus => session.TryFindElementByAccessibilityId("MemPlus"); - public WindowsElement MemMinus => session.TryFindElementByAccessibilityId("MemMinus"); - public WindowsElement MemButton => session.TryFindElementByAccessibilityId("memButton"); - public WindowsElement MemoryPane => session.TryFindElementByAccessibilityId("MemoryPanel"); - public WindowsElement MemoryLabel => session.TryFindElementByAccessibilityId("MemoryLabel"); - public WindowsElement MemoryListView => session.TryFindElementByAccessibilityId("MemoryListView"); - public WindowsElement MemoryPaneEmptyLabel => session.TryFindElementByAccessibilityId("MemoryPaneEmpty"); + 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"); /// /// Opens the Memory Pane by clicking the Memory pivot label. /// public void OpenMemoryPanel() { - MemoryLabel.Click(); - MemoryPane.WaitForDisplayed(); + this.MemoryLabel.Click(); + this.MemoryPane.WaitForDisplayed(); } /// @@ -39,7 +36,7 @@ namespace CalculatorUITestFramework public ReadOnlyCollection GetAllMemoryListViewItems() { OpenMemoryPanel(); - return MemoryListView.FindElementsByClassName("ListViewItem"); + return this.MemoryListView.FindElementsByClassName("ListViewItem"); } } } diff --git a/src/CalculatorUITestFramework/NavigationMenu.cs b/src/CalculatorUITestFramework/NavigationMenu.cs index 4e5d99d7..a7cca7c9 100644 --- a/src/CalculatorUITestFramework/NavigationMenu.cs +++ b/src/CalculatorUITestFramework/NavigationMenu.cs @@ -1,8 +1,8 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + using OpenQA.Selenium.Appium.Windows; using System; -using System.Diagnostics; -using System.Threading; namespace CalculatorUITestFramework { @@ -30,8 +30,8 @@ namespace CalculatorUITestFramework { private WindowsDriver session => WinAppDriver.Instance.CalculatorSession; - public WindowsElement NavigationMenuButton => session.TryFindElementByAccessibilityId("TogglePaneButton"); - public WindowsElement NavigationMenuPane => session.TryFindElementByClassName("SplitViewPane"); + public WindowsElement NavigationMenuButton => this.session.TryFindElementByAccessibilityId("TogglePaneButton"); + public WindowsElement NavigationMenuPane => this.session.TryFindElementByClassName("SplitViewPane"); /// /// Changes the mode using the navigation menu in the UI @@ -94,14 +94,12 @@ namespace CalculatorUITestFramework modeAccessibilityId = "Angle"; break; default: - modeAccessibilityId = string.Empty; - break; + throw (new ArgumentException("The mode is not valid")); } - var source = session.PageSource; - NavigationMenuButton.Click(); - NavigationMenuPane.WaitForDisplayed(); - session.TryFindElementByAccessibilityId(modeAccessibilityId).Click(); + this.NavigationMenuButton.Click(); + this.NavigationMenuPane.WaitForDisplayed(); + this.session.TryFindElementByAccessibilityId(modeAccessibilityId).Click(); } } } diff --git a/src/CalculatorUITestFramework/NumerPad.cs b/src/CalculatorUITestFramework/NumerPad.cs index 7fd47f65..51ea60d7 100644 --- a/src/CalculatorUITestFramework/NumerPad.cs +++ b/src/CalculatorUITestFramework/NumerPad.cs @@ -1,76 +1,80 @@ -using System; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + using OpenQA.Selenium.Appium.Windows; +using System; namespace CalculatorUITestFramework { public class NumerPad { private WindowsDriver session => WinAppDriver.Instance.CalculatorSession; - public WindowsElement Num0Button => session.TryFindElementByAccessibilityId("num0Button"); - public WindowsElement Num1Button => session.TryFindElementByAccessibilityId("num1Button"); - public WindowsElement Num2Button => session.TryFindElementByAccessibilityId("num2Button"); - public WindowsElement Num3Button => session.TryFindElementByAccessibilityId("num3Button"); - public WindowsElement Num4Button => session.TryFindElementByAccessibilityId("num4Button"); - public WindowsElement Num5Button => session.TryFindElementByAccessibilityId("num5Button"); - public WindowsElement Num6Button => session.TryFindElementByAccessibilityId("num6Button"); - public WindowsElement Num7Button => session.TryFindElementByAccessibilityId("num7Button"); - public WindowsElement Num8Button => session.TryFindElementByAccessibilityId("num8Button"); - public WindowsElement Num9Button => session.TryFindElementByAccessibilityId("num9Button"); - public WindowsElement DecimalButton => session.TryFindElementByAccessibilityId("decimalSeparatorButton"); - public WindowsElement NegateButton => session.TryFindElementByAccessibilityId("negateButton"); + public WindowsElement Num0Button => this.session.TryFindElementByAccessibilityId("num0Button"); + public WindowsElement Num1Button => this.session.TryFindElementByAccessibilityId("num1Button"); + public WindowsElement Num2Button => this.session.TryFindElementByAccessibilityId("num2Button"); + public WindowsElement Num3Button => this.session.TryFindElementByAccessibilityId("num3Button"); + public WindowsElement Num4Button => this.session.TryFindElementByAccessibilityId("num4Button"); + public WindowsElement Num5Button => this.session.TryFindElementByAccessibilityId("num5Button"); + public WindowsElement Num6Button => this.session.TryFindElementByAccessibilityId("num6Button"); + public WindowsElement Num7Button => this.session.TryFindElementByAccessibilityId("num7Button"); + public WindowsElement Num8Button => this.session.TryFindElementByAccessibilityId("num8Button"); + public WindowsElement Num9Button => this.session.TryFindElementByAccessibilityId("num9Button"); + public WindowsElement DecimalButton => this.session.TryFindElementByAccessibilityId("decimalSeparatorButton"); + public WindowsElement NegateButton => this.session.TryFindElementByAccessibilityId("negateButton"); /// /// Translates a number into the Calculator button clicks. /// /// Number to be entered into the calculator. - public void TranslateNumberToButtonClicks(double number) + public void Input(double number) { string numberStr = number.ToString(); if (numberStr.StartsWith("-")) { - numberStr = numberStr.Remove(0, 1); - numberStr += '-'; + numberStr = numberStr.Substring(1) + "-"; } foreach (char digit in numberStr) { switch (digit) { case '0': - Num0Button.Click(); + this.Num0Button.Click(); break; case '1': - Num1Button.Click(); + this.Num1Button.Click(); break; case '2': - Num2Button.Click(); + this.Num2Button.Click(); break; case '3': - Num3Button.Click(); + this.Num3Button.Click(); break; case '4': - Num4Button.Click(); + this.Num4Button.Click(); break; case '5': - Num5Button.Click(); + this.Num5Button.Click(); break; case '6': - Num6Button.Click(); + this.Num6Button.Click(); break; case '7': - Num7Button.Click(); + this.Num7Button.Click(); break; case '8': - Num8Button.Click(); + this.Num8Button.Click(); break; case '9': - Num9Button.Click(); + this.Num9Button.Click(); break; case '.': - DecimalButton.Click(); + this.DecimalButton.Click(); break; case '-': - NegateButton.Click(); + this.NegateButton.Click(); break; + default: + throw (new ArgumentException(String.Format("{0} is not valid", digit))); } } } diff --git a/src/CalculatorUITestFramework/StandardCalculatorPage.cs b/src/CalculatorUITestFramework/StandardCalculatorPage.cs index 508b3b44..39b7b623 100644 --- a/src/CalculatorUITestFramework/StandardCalculatorPage.cs +++ b/src/CalculatorUITestFramework/StandardCalculatorPage.cs @@ -1,11 +1,8 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace CalculatorUITestFramework { @@ -25,15 +22,15 @@ namespace CalculatorUITestFramework { try { - return session.TryFindElementByAccessibilityId("Header"); + return this.session.TryFindElementByAccessibilityId("Header"); } catch { - return session.TryFindElementByAccessibilityId("ContentPresenter"); + return this.session.TryFindElementByAccessibilityId("ContentPresenter"); } } } - public WindowsElement CalculatorResult => session.TryFindElementByAccessibilityId("CalculatorResults"); + public WindowsElement CalculatorResult => this.session.TryFindElementByAccessibilityId("CalculatorResults"); public void StandardCalculatorSetup(TestContext context) { @@ -41,7 +38,7 @@ namespace CalculatorUITestFramework WinAppDriver.Instance.SetupCalculatorSession(context); // Ensure that calculator is in standard mode - NavigationMenu.ChangeCalculatorMode(CalculatorMode.StandardCalculator); + this.NavigationMenu.ChangeCalculatorMode(CalculatorMode.StandardCalculator); Assert.IsNotNull(CalculatorResult); } @@ -57,9 +54,9 @@ namespace CalculatorUITestFramework /// Bool specifying if the History Panel should be cleared; true by default. public void ClearAll() { - StandardOperators.ClearButton.Click(); - MemoryPanel.MemoryClear.Click(); - HistoryPanel.ClearHistory(); + this.StandardOperators.ClearButton.Click(); + this.MemoryPanel.MemoryClear.Click(); + this.HistoryPanel.ClearHistory(); } /// @@ -68,7 +65,7 @@ namespace CalculatorUITestFramework /// The string shown in the UI. public string GetCalculatorResultText() { - return CalculatorResult.Text.Replace("Display is", string.Empty).Trim(); + return this.CalculatorResult.Text.Replace("Display is", string.Empty).Trim(); } } } diff --git a/src/CalculatorUITestFramework/StandardOperatorsPanel.cs b/src/CalculatorUITestFramework/StandardOperatorsPanel.cs index bc61bed2..9ff338c2 100644 --- a/src/CalculatorUITestFramework/StandardOperatorsPanel.cs +++ b/src/CalculatorUITestFramework/StandardOperatorsPanel.cs @@ -1,9 +1,8 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + using OpenQA.Selenium.Appium.Windows; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace CalculatorUITestFramework { @@ -15,142 +14,18 @@ namespace CalculatorUITestFramework private WindowsDriver session => WinAppDriver.Instance.CalculatorSession; public NumerPad NumberPad = new NumerPad(); - public WindowsElement PercentButton => session.TryFindElementByAccessibilityId("percentButton"); - public WindowsElement SquareRootButton => session.TryFindElementByAccessibilityId("squareRootButton"); - public WindowsElement XPower2Button => session.TryFindElementByAccessibilityId("xpower2Button"); - public WindowsElement XPower3Button => session.TryFindElementByAccessibilityId("xpower3Button"); - public WindowsElement InvertButton => session.TryFindElementByAccessibilityId("invertButton"); - public WindowsElement DivideButton => session.TryFindElementByAccessibilityId("divideButton"); - public WindowsElement MultiplyButton => session.TryFindElementByAccessibilityId("multiplyButton"); - public WindowsElement MinusButton => session.TryFindElementByAccessibilityId("minusButton"); - public WindowsElement PlusButton => session.TryFindElementByAccessibilityId("plusButton"); - public WindowsElement EqualButton => session.TryFindElementByAccessibilityId("equalButton"); - public WindowsElement ClearEntryButton => session.TryFindElementByAccessibilityId("clearEntryButton"); - public WindowsElement ClearButton => session.TryFindElementByAccessibilityId("clearButton"); - public WindowsElement BackSpaceButton => session.TryFindElementByAccessibilityId("backSpaceButton"); - - /// - /// Uses the Calculator UI to add a list of numbers. - /// - /// List of numbers to be added. - public void Add(List numbers) - { - for (int i = 0; i < numbers.Count; i++) - { - NumberPad.TranslateNumberToButtonClicks(numbers[i]); - - if (i != numbers.Count - 1) - { - PlusButton.Click(); - } - else - { - EqualButton.Click(); - } - } - } - - /// - /// Uses the Calculator UI to subtract a list of numbers. - /// - /// List of numbers to be subtracted. - public void Subtract(List numbers) - { - for (int i = 0; i < numbers.Count; i++) - { - NumberPad.TranslateNumberToButtonClicks(numbers[i]); - - if (i != numbers.Count - 1) - { - MinusButton.Click(); - } - else - { - EqualButton.Click(); - } - } - } - - /// - /// Uses the Calculator UI to multiply a list of numbers. - /// - /// List of numbers to be multiplied. - public void Multiply(List numbers) - { - for (int i = 0; i < numbers.Count; i++) - { - NumberPad.TranslateNumberToButtonClicks(numbers[i]); - - if (i != numbers.Count - 1) - { - MultiplyButton.Click(); - } - else - { - EqualButton.Click(); - } - } - } - - /// - /// Uses the Calculator UI to divide a list of numbers. - /// - /// List of numbers to be divided. - public void Divide(List numbers) - { - for (int i = 0; i < numbers.Count; i++) - { - NumberPad.TranslateNumberToButtonClicks(numbers[i]); - - if (i != numbers.Count - 1) - { - DivideButton.Click(); - } - else - { - EqualButton.Click(); - } - } - } - - /// - /// Uses the Calculator UI to take the reciprocal of a number. - /// - /// Number to take the reciprocal of. - public void Reciprocal(double number) - { - NumberPad.TranslateNumberToButtonClicks(number); - InvertButton.Click(); - } - - /// - /// Uses the Calculator UI to square a number. - /// - /// The number to be squared. - public void Square(double number) - { - NumberPad.TranslateNumberToButtonClicks(number); - XPower2Button.Click(); - } - - /// - /// Uses the Calculator UI to cube a number. - /// - /// The number to be cubed. - public void Cube(double number) - { - NumberPad.TranslateNumberToButtonClicks(number); - XPower3Button.Click(); - } - - /// - /// Uses the Calculator UI to take the square root of a number. - /// - /// Number to take the square root of. - public void SquareRoot(double number) - { - NumberPad.TranslateNumberToButtonClicks(number); - SquareRootButton.Click(); - } + public WindowsElement PercentButton => this.session.TryFindElementByAccessibilityId("percentButton"); + public WindowsElement SquareRootButton => this.session.TryFindElementByAccessibilityId("squareRootButton"); + public WindowsElement XPower2Button => this.session.TryFindElementByAccessibilityId("xpower2Button"); + public WindowsElement XPower3Button => this.session.TryFindElementByAccessibilityId("xpower3Button"); + public WindowsElement InvertButton => this.session.TryFindElementByAccessibilityId("invertButton"); + public WindowsElement DivideButton => this.session.TryFindElementByAccessibilityId("divideButton"); + public WindowsElement MultiplyButton => this.session.TryFindElementByAccessibilityId("multiplyButton"); + public WindowsElement MinusButton => this.session.TryFindElementByAccessibilityId("minusButton"); + public WindowsElement PlusButton => this.session.TryFindElementByAccessibilityId("plusButton"); + public WindowsElement EqualButton => this.session.TryFindElementByAccessibilityId("equalButton"); + public WindowsElement ClearEntryButton => this.session.TryFindElementByAccessibilityId("clearEntryButton"); + public WindowsElement ClearButton => this.session.TryFindElementByAccessibilityId("clearButton"); + public WindowsElement BackSpaceButton => this.session.TryFindElementByAccessibilityId("backSpaceButton"); } } diff --git a/src/CalculatorUITestFramework/WinAppDriver.cs b/src/CalculatorUITestFramework/WinAppDriver.cs index 01e49aa6..46b9b860 100644 --- a/src/CalculatorUITestFramework/WinAppDriver.cs +++ b/src/CalculatorUITestFramework/WinAppDriver.cs @@ -1,11 +1,11 @@ +// 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 System; -using System.Collections.Generic; using System.Diagnostics; -using System.Text; namespace CalculatorUITestFramework { @@ -36,9 +36,9 @@ namespace CalculatorUITestFramework public void SetupCalculatorSession(TestContext context) { - windowsDriverService = new WindowsDriverServiceBuilder().Build(); + this.windowsDriverService = new WindowsDriverServiceBuilder().Build(); - windowsDriverService.OutputDataReceived += new DataReceivedEventHandler((sender, e) => + this.windowsDriverService.OutputDataReceived += new DataReceivedEventHandler((sender, e) => { if (!String.IsNullOrEmpty(e.Data)) { @@ -46,35 +46,35 @@ namespace CalculatorUITestFramework } }); - windowsDriverService.Start(); + this.windowsDriverService.Start(); // Launch Calculator application if it is not yet launched - if (CalculatorSession == null) + if (this.CalculatorSession == null) { // Create a new WinAppDriver session to bring up an instance of the Calculator application // Note: Multiple calculator windows (instances) share the same process Id var options = new AppiumOptions(); options.AddAdditionalCapability("app", calculatorAppId); options.AddAdditionalCapability("deviceName", "WindowsPC"); - CalculatorSession = new WindowsDriver(windowsDriverService.ServiceUrl, options); - CalculatorSession.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); - Assert.IsNotNull(CalculatorSession); + this.CalculatorSession = new WindowsDriver(this.windowsDriverService.ServiceUrl, options); + this.CalculatorSession.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); + Assert.IsNotNull(this.CalculatorSession); } } public void TearDownCalculatorSession() { // Close the application and delete the session - if (CalculatorSession != null) + if (this.CalculatorSession != null) { - CalculatorSession.Quit(); - CalculatorSession = null; + this.CalculatorSession.Quit(); + this.CalculatorSession = null; } - if (windowsDriverService != null) + if (this.windowsDriverService != null) { - windowsDriverService.Dispose(); - windowsDriverService = null; + this.windowsDriverService.Dispose(); + this.windowsDriverService = null; } } diff --git a/src/CalculatorUITestFramework/WindowsDriverExtensions.cs b/src/CalculatorUITestFramework/WindowsDriverExtensions.cs index 77056d91..2326483a 100644 --- a/src/CalculatorUITestFramework/WindowsDriverExtensions.cs +++ b/src/CalculatorUITestFramework/WindowsDriverExtensions.cs @@ -1,8 +1,8 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + using OpenQA.Selenium; using OpenQA.Selenium.Appium.Windows; -using System; -using System.Collections.Generic; -using System.Text; namespace CalculatorUITestFramework { diff --git a/src/CalculatorUITestFramework/WindowsDriverLocalService.cs b/src/CalculatorUITestFramework/WindowsDriverLocalService.cs index 8fec7a9a..fbaf7630 100644 --- a/src/CalculatorUITestFramework/WindowsDriverLocalService.cs +++ b/src/CalculatorUITestFramework/WindowsDriverLocalService.cs @@ -1,11 +1,24 @@ -using OpenQA.Selenium.Appium.Service; +//Licensed under the Apache License, Version 2.0 (the "License"); +//you may not use this file except in compliance with the License. +//See the NOTICE file distributed with this work for additional +//information regarding copyright ownership. +//You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +//Unless required by applicable law or agreed to in writing, software +//distributed under the License is distributed on an "AS IS" BASIS, +//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +//See the License for the specific language governing permissions and +//limitations under the License. + +//Portions Copyright (c) Microsoft Corporation + using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Net; using System.Runtime.CompilerServices; -using System.Text; namespace CalculatorUITestFramework { @@ -27,33 +40,33 @@ namespace CalculatorUITestFramework int port, TimeSpan initializationTimeout) { - FileName = fileName; - Arguments = arguments; - IP = ip; - Port = port; - InitializationTimeout = initializationTimeout; + this.FileName = fileName; + this.Arguments = arguments; + this.IP = ip; + this.Port = port; + this.InitializationTimeout = initializationTimeout; } [MethodImpl(MethodImplOptions.Synchronized)] public void Start() { - if (IsRunning) + if (this.IsRunning) { return; } - Service = new Process(); - Service.StartInfo.FileName = FileName.FullName; - Service.StartInfo.Arguments = Arguments; - Service.StartInfo.UseShellExecute = false; - Service.StartInfo.CreateNoWindow = true; + this.Service = new Process(); + this.Service.StartInfo.FileName = FileName.FullName; + this.Service.StartInfo.Arguments = Arguments; + this.Service.StartInfo.UseShellExecute = false; + this.Service.StartInfo.CreateNoWindow = true; - Service.StartInfo.RedirectStandardOutput = true; - Service.OutputDataReceived += (sender, e) => OutputDataReceived?.Invoke(this, e); + this.Service.StartInfo.RedirectStandardOutput = true; + this.Service.OutputDataReceived += (sender, e) => OutputDataReceived?.Invoke(this, e); bool isLaunched = false; string msgTxt = - $"The local WinAppDriver server has not been started: {FileName.FullName} Arguments: {Arguments}. " + + $"The local WinAppDriver server has not been started: {this.FileName.FullName} Arguments: {this.Arguments}. " + "\n"; try @@ -82,14 +95,14 @@ namespace CalculatorUITestFramework { get { - if (Service == null) + if (this.Service == null) { return false; } try { - var pid = Service.Id; + var pid = this.Service.Id; } catch (Exception) { @@ -109,26 +122,26 @@ namespace CalculatorUITestFramework public Uri ServiceUrl { // Note: append /wd/hub to the URL if you're directing the test at Appium - get { return new Uri($"http://{IP.ToString()}:{Convert.ToString(Port)}"); } + get { return new Uri($"http://{this.IP.ToString()}:{Convert.ToString(this.Port)}"); } } private void DestroyProcess() { - if (Service == null) + if (this.Service == null) { return; } try { - Service.Kill(); + this.Service.Kill(); } catch (Exception) { } finally { - Service.Close(); + this.Service.Close(); } } @@ -138,10 +151,10 @@ namespace CalculatorUITestFramework Uri status; - Uri service = ServiceUrl; + Uri service = this.ServiceUrl; if (service.IsLoopback) { - status = new Uri("http://localhost:" + Convert.ToString(Port) + "/status"); + status = new Uri("http://localhost:" + Convert.ToString(this.Port) + "/status"); } else { diff --git a/src/CalculatorUITestFramework/WindowsDriverServiceBuilder.cs b/src/CalculatorUITestFramework/WindowsDriverServiceBuilder.cs index 1dacdd85..57610f79 100644 --- a/src/CalculatorUITestFramework/WindowsDriverServiceBuilder.cs +++ b/src/CalculatorUITestFramework/WindowsDriverServiceBuilder.cs @@ -1,13 +1,23 @@ -using OpenQA.Selenium; -using OpenQA.Selenium.Appium.Service; -using OpenQA.Selenium.Appium.Service.Options; +//Licensed under the Apache License, Version 2.0 (the "License"); +//you may not use this file except in compliance with the License. +//See the NOTICE file distributed with this work for additional +//information regarding copyright ownership. +//You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +//Unless required by applicable law or agreed to in writing, software +//distributed under the License is distributed on an "AS IS" BASIS, +//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +//See the License for the specific language governing permissions and +//limitations under the License. + +//Portions Copyright(c) Microsoft Corporation + using System; -using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Net; using System.Net.Sockets; -using System.Text; namespace CalculatorUITestFramework { @@ -20,11 +30,11 @@ namespace CalculatorUITestFramework public WindowsDriverLocalService Build() { - if (FileInfo == null) + if (this.FileInfo == null) { - FileInfo = new FileInfo(@"c:\Program Files (x86)\Windows Application Driver\winappdriver.exe"); + this.FileInfo = new FileInfo(@"c:\Program Files (x86)\Windows Application Driver\winappdriver.exe"); } - return new WindowsDriverLocalService(FileInfo, string.Empty, IPAddress.Parse(this.IpAddress), this.Port, StartUpTimeout); + return new WindowsDriverLocalService(this.FileInfo, string.Empty, IPAddress.Parse(this.IpAddress), this.Port, this.StartUpTimeout); } public WindowsDriverServiceBuilder WithFileInfo(FileInfo fileInfo) @@ -33,7 +43,7 @@ namespace CalculatorUITestFramework { throw new ArgumentNullException("FileInfo should not be NULL"); } - FileInfo = fileInfo; + this.FileInfo = fileInfo; return this; } @@ -43,13 +53,13 @@ namespace CalculatorUITestFramework { throw new ArgumentNullException("A startup timeout should not be NULL"); } - StartUpTimeout = startUpTimeout; + this.StartUpTimeout = startUpTimeout; return this; } public WindowsDriverServiceBuilder WithIPAddress(string ipAddress) { - IpAddress = ipAddress; + this.IpAddress = ipAddress; return this; } @@ -65,7 +75,7 @@ namespace CalculatorUITestFramework return UsingAnyFreePort(); } - Port = port; + this.Port = port; return this; } @@ -78,7 +88,7 @@ namespace CalculatorUITestFramework sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); sock.Bind(new IPEndPoint(IPAddress.Any, 0)); - Port = ((IPEndPoint)sock.LocalEndPoint).Port; + this.Port = ((IPEndPoint)sock.LocalEndPoint).Port; return this; } finally diff --git a/src/CalculatorUITestFramework/WindowsElementExtensions.cs b/src/CalculatorUITestFramework/WindowsElementExtensions.cs index e49c9f6d..741c9559 100644 --- a/src/CalculatorUITestFramework/WindowsElementExtensions.cs +++ b/src/CalculatorUITestFramework/WindowsElementExtensions.cs @@ -1,11 +1,11 @@ +// 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; using OpenQA.Selenium.Appium.Windows; using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Text; using System.Threading; namespace CalculatorUITestFramework diff --git a/src/CalculatorUITests/StandardModeFunctionalTests.cs b/src/CalculatorUITests/StandardModeFunctionalTests.cs index c2b2fc01..7ba9bfa9 100644 --- a/src/CalculatorUITests/StandardModeFunctionalTests.cs +++ b/src/CalculatorUITests/StandardModeFunctionalTests.cs @@ -1,14 +1,12 @@ using CalculatorUITestFramework; using Microsoft.VisualStudio.TestTools.UnitTesting; -using OpenQA.Selenium; -using OpenQA.Selenium.Remote; using System; using System.Collections.Generic; -using System.Text; -using System.Threading; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. namespace CalculatorUITests -{ +{ [TestClass] public class StandardModeFunctionalTests { @@ -56,8 +54,10 @@ namespace CalculatorUITests [TestMethod] public void SmokeTest_Add() { - // Find the buttons by their names and click them in sequence to peform 1 + 7 = 8 - page.StandardOperators.Add(new List() { 3.5, 0.25 }); + page.StandardOperators.NumberPad.Input(3.5); + page.StandardOperators.PlusButton.Click(); + page.StandardOperators.NumberPad.Input(0.25); + page.StandardOperators.EqualButton.Click(); Assert.AreEqual("3.75", page.GetCalculatorResultText()); } @@ -71,17 +71,31 @@ namespace CalculatorUITests [TestMethod] public void SmokeTest_Subtract() { - // Find the buttons by their names and click them in sequence to peform 1 + 7 = 8 - page.StandardOperators.Subtract(new List() { 4.3, 2.6 }); + page.StandardOperators.NumberPad.Input(4.3); + page.StandardOperators.MinusButton.Click(); + page.StandardOperators.NumberPad.Input(2.6); + page.StandardOperators.EqualButton.Click(); Assert.AreEqual("1.7", page.GetCalculatorResultText()); } [TestMethod] public void SmokeTest_History() { - page.StandardOperators.Add(new List() { -3, -2.6 }); - page.StandardOperators.Subtract(new List() { 2, 3 }); - page.StandardOperators.Multiply(new List() { 1, 3 }); + page.StandardOperators.NumberPad.Input(-3); + page.StandardOperators.PlusButton.Click(); + page.StandardOperators.NumberPad.Input(-2.6); + page.StandardOperators.EqualButton.Click(); + + page.StandardOperators.NumberPad.Input(2); + page.StandardOperators.MinusButton.Click(); + page.StandardOperators.NumberPad.Input(3); + page.StandardOperators.EqualButton.Click(); + + page.StandardOperators.NumberPad.Input(1); + page.StandardOperators.MultiplyButton.Click(); + page.StandardOperators.NumberPad.Input(3); + page.StandardOperators.EqualButton.Click(); + var historyItems = page.HistoryPanel.GetAllHistoryListViewItems(); Assert.IsTrue(historyItems[0].Text.Equals("1 × 3 = 3", StringComparison.InvariantCultureIgnoreCase)); Assert.IsTrue(historyItems[1].Text.Equals("2 Minus ( 3 = Minus (1", StringComparison.InvariantCultureIgnoreCase)); @@ -92,12 +106,24 @@ namespace CalculatorUITests [TestMethod] public void SmokeTest_Memory() { - page.StandardOperators.Add(new List() { 3, 0 }); + page.StandardOperators.NumberPad.Input(3); + page.StandardOperators.PlusButton.Click(); + page.StandardOperators.NumberPad.Input(0); + page.StandardOperators.EqualButton.Click(); page.MemoryPanel.MemButton.Click(); - page.StandardOperators.Divide(new List() { 2, 3 }); + + page.StandardOperators.NumberPad.Input(2); + page.StandardOperators.DivideButton.Click(); + page.StandardOperators.NumberPad.Input(3); + page.StandardOperators.EqualButton.Click(); page.MemoryPanel.MemButton.Click(); - page.StandardOperators.Multiply(new List() { 7, 9 }); + + page.StandardOperators.NumberPad.Input(7); + page.StandardOperators.MultiplyButton.Click(); + page.StandardOperators.NumberPad.Input(9); + page.StandardOperators.EqualButton.Click(); page.MemoryPanel.MemButton.Click(); + var memoryItems = page.MemoryPanel.GetAllMemoryListViewItems(); Assert.IsTrue(memoryItems[0].Text.Equals("63", StringComparison.InvariantCultureIgnoreCase)); @@ -113,37 +139,41 @@ namespace CalculatorUITests [TestMethod] public void Operator_Reciprocal() { - page.StandardOperators.Reciprocal(4); + page.StandardOperators.NumberPad.Input(4); + page.StandardOperators.InvertButton.Click(); Assert.AreEqual("0.25", page.GetCalculatorResultText()); } [TestMethod] public void Operator_Squared() { - page.StandardOperators.Square(-15.5); + page.StandardOperators.NumberPad.Input(-15.5); + page.StandardOperators.XPower2Button.Click(); Assert.AreEqual("240.25", page.GetCalculatorResultText()); } [TestMethod] public void Operator_SquareRoot() { - page.StandardOperators.SquareRoot(144); + page.StandardOperators.NumberPad.Input(144); + page.StandardOperators.SquareRootButton.Click(); Assert.AreEqual("12", page.GetCalculatorResultText()); } [TestMethod] public void Operator_Cubed() { - page.StandardOperators.Cube(-3); + page.StandardOperators.NumberPad.Input(-3); + page.StandardOperators.XPower3Button.Click(); Assert.AreEqual("-27", page.GetCalculatorResultText()); } [TestMethod] public void Operator_Percent() { - page.StandardOperators.NumberPad.TranslateNumberToButtonClicks(600); + page.StandardOperators.NumberPad.Input(600); page.StandardOperators.MultiplyButton.Click(); - page.StandardOperators.NumberPad.TranslateNumberToButtonClicks(15); + page.StandardOperators.NumberPad.Input(15); page.StandardOperators.PercentButton.Click(); page.StandardOperators.EqualButton.Click(); Assert.AreEqual("90", page.GetCalculatorResultText()); @@ -152,7 +182,7 @@ namespace CalculatorUITests [TestMethod] public void Operator_Delete() { - page.StandardOperators.NumberPad.TranslateNumberToButtonClicks(-12345); + page.StandardOperators.NumberPad.Input(-12345); page.StandardOperators.BackSpaceButton.Click(); Assert.AreEqual("-1,234", page.GetCalculatorResultText()); } @@ -160,7 +190,9 @@ namespace CalculatorUITests [TestMethod] public void Operator_ClearAll() { - page.StandardOperators.Add(new List() { 12345, 6789 }); + page.StandardOperators.NumberPad.Input(12345); + page.StandardOperators.PlusButton.Click(); + page.StandardOperators.NumberPad.Input(6789); page.StandardOperators.ClearButton.Click(); Assert.AreEqual("0", page.GetCalculatorResultText()); } @@ -168,9 +200,9 @@ namespace CalculatorUITests [TestMethod] public void Operator_ClearEntry() { - page.StandardOperators.NumberPad.TranslateNumberToButtonClicks(-12345); + page.StandardOperators.NumberPad.Input(-12345); page.StandardOperators.MinusButton.Click(); - page.StandardOperators.NumberPad.TranslateNumberToButtonClicks(5678); + page.StandardOperators.NumberPad.Input(5678); page.StandardOperators.ClearEntryButton.Click(); Assert.AreEqual("0", page.GetCalculatorResultText()); } @@ -239,9 +271,13 @@ namespace CalculatorUITests [TestMethod] public void Memory_AddTest() { - page.StandardOperators.Divide(new List() { 12, 3 }); + page.StandardOperators.NumberPad.Input(12); + page.StandardOperators.DivideButton.Click(); + page.StandardOperators.NumberPad.Input(3); + page.StandardOperators.EqualButton.Click(); + page.MemoryPanel.MemButton.Click(); - page.StandardOperators.NumberPad.TranslateNumberToButtonClicks(15); + page.StandardOperators.NumberPad.Input(15); page.MemoryPanel.MemPlus.Click(); var memoryItems = page.MemoryPanel.GetAllMemoryListViewItems(); Assert.IsTrue(memoryItems[0].Text.Equals("19", StringComparison.InvariantCultureIgnoreCase)); @@ -250,9 +286,13 @@ namespace CalculatorUITests [TestMethod] public void Memory_SubtractTest() { - page.StandardOperators.Divide(new List() { 12, 3 }); + page.StandardOperators.NumberPad.Input(12); + page.StandardOperators.DivideButton.Click(); + page.StandardOperators.NumberPad.Input(3); + page.StandardOperators.EqualButton.Click(); + page.MemoryPanel.MemButton.Click(); - page.StandardOperators.NumberPad.TranslateNumberToButtonClicks(3.3); + page.StandardOperators.NumberPad.Input(3.3); page.MemoryPanel.MemMinus.Click(); var memoryItems = page.MemoryPanel.GetAllMemoryListViewItems(); Assert.IsTrue(memoryItems[0].Text.Equals("0.7", StringComparison.InvariantCultureIgnoreCase)); @@ -261,9 +301,13 @@ namespace CalculatorUITests [TestMethod] public void Memory_RecallTest() { - page.StandardOperators.Divide(new List() { 12, 3 }); + page.StandardOperators.NumberPad.Input(12); + page.StandardOperators.DivideButton.Click(); + page.StandardOperators.NumberPad.Input(3); + page.StandardOperators.EqualButton.Click(); + page.MemoryPanel.MemButton.Click(); - page.StandardOperators.NumberPad.TranslateNumberToButtonClicks(3.3); + page.StandardOperators.NumberPad.Input(3.3); page.MemoryPanel.MemRecall.Click(); var memoryItems = page.MemoryPanel.GetAllMemoryListViewItems(); Assert.IsTrue(memoryItems[0].Text.Equals("4", StringComparison.InvariantCultureIgnoreCase)); @@ -272,9 +316,13 @@ namespace CalculatorUITests [TestMethod] public void Memory_ClearTest() { - page.StandardOperators.Divide(new List() { 12, 3 }); + page.StandardOperators.NumberPad.Input(12); + page.StandardOperators.DivideButton.Click(); + page.StandardOperators.NumberPad.Input(3); + page.StandardOperators.EqualButton.Click(); + page.MemoryPanel.MemButton.Click(); - page.StandardOperators.NumberPad.TranslateNumberToButtonClicks(3.3); + page.StandardOperators.NumberPad.Input(3.3); page.MemoryPanel.MemoryClear.Click(); page.MemoryPanel.OpenMemoryPanel(); Assert.IsNotNull(page.MemoryPanel.MemoryPaneEmptyLabel);