// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium.Appium.Windows; using System; using OpenQA.Selenium.Interactions; namespace CalculatorUITestFramework { public class CalculatorResults { private WindowsDriver 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"); private WindowsElement MenuItemCopy => this.session.TryFindElementByAccessibilityId("CopyMenuItem"); private WindowsElement MenuItemPaste => this.session.TryFindElementByAccessibilityId("PasteMenuItem"); /// /// Gets the text from the display control in AoT mode and removes the narrator text that is not displayed in the UI. /// /// The string shown in the UI. public string GetAoTCalculatorResultText() { return this.CalculatorAlwaysOnTopResults.Text.Replace("Display is", string.Empty).Trim(); } /// /// Gets the text from the display control and removes the narrator text that is not displayed in the UI. /// /// The string shown in the UI. public string GetCalculatorResultText() { return this.CalculatorResult.Text.Replace("Display is", string.Empty).Trim(); } /// /// Gets the text from the Calculator Expression control and removes narrator text that is not displayed in the UI. /// /// The string shown in the UI. public string GetCalculatorExpressionText() { return this.CalculatorExpression.Text.Replace("Expression is", string.Empty).Trim(); } /// /// Verifies that CalculatorResult is not null /// /// The string shown in the UI. public void IsResultsDisplayPresent() { Assert.IsNotNull(this.CalculatorResult); } /// /// Verifies that Calculator Expression is clear /// /// The string shown in the UI. public void IsResultsExpressionClear() { string source = WinAppDriver.Instance.CalculatorSession.PageSource; if (source.Contains("CalculatorExpression")) { throw new Exception("The Calculator Expression is not clear"); } } /// /// Opens the context menu in order to be able to click its items /// 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(); } /// /// Opens the context menu and clicks the "Copy" item there /// public void ContextMenuItemCopyClick() { OpenContextMenu(); MenuItemCopy.Click(); } /// /// Opens the context menu and clicks the "Paste" item there /// public void ContextMenuItemPasteClick() { OpenContextMenu(); MenuItemPaste.Click(); } } }