msft-calculator/src/CalculatorUITestFramework/ScientificOperatorsPanel.cs
Daniel-Parker 2cafb0dc88
Scientific and Programmer tests (#779)
* Maximize window during setup, and added divide by zero error test

* Added Error_CubedNegativeNumber test and AOT buttons

* Made Added AoT Tests and test are faster

* Hotkey and Mouse Input BVT Test added, Memory Test started

* Started Aligning BVTs with manual tests.  Added TC23466694, TC17416429, and TC17416884, and a test to switching mode test

* Basic Scientific Mode Functional Test Tests

* Added history panel test, and history flyout test for Standard calculator, and added the supporting framework

* Added some functional tests for Scientific mode.

* Basic Scientific Mode functional tests, added solution to set Angle Operator button correctly.

* Created functions to resize the app to display history panel, to display history button, display memory panel, and memory button.  Then I applied them to reduce areas with rewritten code, and to help with over all test stability and speed.

* I added the trigonometry functional tests

* Pull from latetest master, and retargeted solution

* Added a GetCalculatorWindowPostion function, when resizing window to show history/memory label, set window position to (0,0), and the same when resizing KOT calculator.  This will make tests more stable by keeping calculator on screen. It will also help with any testing that may require tracking the apps postion. To fix a test failure, changed function from ResizeToDiplayHistoryButton to ResizeToNotDisplayHistoryLabel.

* Sorted Using Statements, modified .gitignore to ignore **src/out, etc...

* Merged CalcMemoryFlyout into MemoryPanel, and deleted CalcMemoryFlyout. Merged CalcHistoryFlyout in HistoryPanel, and deleted CalcMemory.  Created GlobalCalculatorUI.cs.  Updated tests to work with these changes.

* hold on to changes

* Changed all KOT to Aot,
Removed equal button click in Test Cleanup/History method uses page source,
Removed extra line in Calculator.vcxproj.filters, Removed Try/Catch in the ClearHistory method

* Removed unused elses
Added CalculatorResults class
Added StandardAoTCalculatorPage
Removed manual test case info in the comments

* - In test framework, where it worked,
made some elements private
- Created EnsureCalculatorHasFocus() in GlobalCalculatorUI.cs
- Due to new classes, moved some methods to more correct classes
- Moved "page.MemoryPanel.ResizeWindowToDiplayMemoryLabel();" from
SetupCalculatorSession() to ClassInitialize()

* Sorted Using

* Updating fork from latest master

* Don't stand so

* Minor edits, fixing things from PR comments

* Merging scientific and standard mode tests, minor merge conflict fixes

* Method work
- Created ResizeAoTWindowToDiplayInvertButton()
    - Applied to test method AoT_ErrorMessage()
- Added page.ScientificOperators.ResetFEButton(fEButtonState.Normal);
to TestIniT in ScientificModeFunctionalTests
- Fixed if statement in public void ResetFEButton(fEButtonState value)

* Added StandardOperatorsPanel and removed duplicated code

* Created tests for Programmer mode, fixed a typo that appeared in multiple locations

* Fixed clear entry not working in Scientific test

* This time I really fixed the problem with clear memory not being found every time

* Revert shared changes

* Rebased onto master and resolved conflicts

* Fixed the 15 second delay on every scientific mode test

* Greatly shortened bitflipkeypad test

Co-authored-by: Crystal Edwards (Insight Global Inc) <v-credwa@microsoft.com>
Co-authored-by: Crystal Edwards <45952655+v-credwa@users.noreply.github.com>
2020-04-28 10:54:55 -07:00

167 lines
9.2 KiB
C#

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using OpenQA.Selenium;
using OpenQA.Selenium.Appium.Windows;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices.ComTypes;
using System;
using System.Diagnostics;
namespace CalculatorUITestFramework
{
public enum AngleOperatorState
{
Degrees,
Radians,
Gradians
}
public enum fEButtonState
{
Normal,
Exponential
}
/// <summary>
/// UI elements unique to Scientific mode
/// </summary>
public class ScientificOperatorsPanel
{
private WindowsDriver<WindowsElement> session => WinAppDriver.Instance.CalculatorSession;
public WindowsElement XPower3Button => this.session.TryFindElementByAccessibilityId("xpower3Button");
public WindowsElement XPowerYButton => this.session.TryFindElementByAccessibilityId("powerButton");
public WindowsElement PowerOf10Button => this.session.TryFindElementByAccessibilityId("powerOf10Button");
public WindowsElement LogButton => this.session.TryFindElementByAccessibilityId("logBase10Button");
public WindowsElement LnButton => this.session.TryFindElementByAccessibilityId("logBaseEButton");
public WindowsElement PiButton => this.session.TryFindElementByAccessibilityId("piButton");
public WindowsElement EulerButton => this.session.TryFindElementByAccessibilityId("eulerButton");
public WindowsElement AbsButton => this.session.TryFindElementByAccessibilityId("absButton");
public WindowsElement ExpButton => this.session.TryFindElementByAccessibilityId("expButton");
public WindowsElement ModButton => this.session.TryFindElementByAccessibilityId("modButton");
public WindowsElement ParenthesisLeftButton => this.session.TryFindElementByAccessibilityId("openParenthesisButton");
public WindowsElement ParenthesisRightButton => this.session.TryFindElementByAccessibilityId("closeParenthesisButton");
public WindowsElement FactorialButton => this.session.TryFindElementByAccessibilityId("factorialButton");
public WindowsElement BackSpaceButton => this.session.TryFindElementByAccessibilityId("backSpaceButton");
public WindowsElement DegButton => this.session.TryFindElementByAccessibilityId("degButton");
public WindowsElement RadButton => this.session.TryFindElementByAccessibilityId("radButton");
public WindowsElement GradButton => this.session.TryFindElementByAccessibilityId("gradButton");
public WindowsElement AngleOperator => this.session.TryFindElementByAccessibilityId("ScientificAngleOperators");
public WindowsElement TrigButton => this.session.TryFindElementByAccessibilityId("trigButton");
public WindowsElement FuncButton => this.session.TryFindElementByAccessibilityId("funcButton");
public WindowsElement SinButton => this.session.TryFindElementByAccessibilityId("sinButton");
public WindowsElement CosButton => this.session.TryFindElementByAccessibilityId("cosButton");
public WindowsElement TanButton => this.session.TryFindElementByAccessibilityId("tanButton");
public WindowsElement CscButton => this.session.TryFindElementByAccessibilityId("cscButton");
public WindowsElement SecButton => this.session.TryFindElementByAccessibilityId("secButton");
public WindowsElement CotButton => this.session.TryFindElementByAccessibilityId("cotButton");
public WindowsElement TrigShiftButton => this.session.TryFindElementByAccessibilityId("trigShiftButton");
public WindowsElement HypShiftButton => this.session.TryFindElementByAccessibilityId("hypShiftButton");
public WindowsElement InvSinButton => this.session.TryFindElementByAccessibilityId("invsinButton");
public WindowsElement InvCosButton => this.session.TryFindElementByAccessibilityId("invcosButton");
public WindowsElement InvTanButton => this.session.TryFindElementByAccessibilityId("invtanButton");
public WindowsElement InvCscButton => this.session.TryFindElementByAccessibilityId("invcscButton");
public WindowsElement InvSecButton => this.session.TryFindElementByAccessibilityId("invsecButton");
public WindowsElement InvCotButton => this.session.TryFindElementByAccessibilityId("invcotButton");
public WindowsElement SinhButton => this.session.TryFindElementByAccessibilityId("sinhButton");
public WindowsElement CoshButton => this.session.TryFindElementByAccessibilityId("coshButton");
public WindowsElement TanhButton => this.session.TryFindElementByAccessibilityId("tanhButton");
public WindowsElement CschButton => this.session.TryFindElementByAccessibilityId("cschButton");
public WindowsElement SechButton => this.session.TryFindElementByAccessibilityId("sechButton");
public WindowsElement CothButton => this.session.TryFindElementByAccessibilityId("cothButton");
public WindowsElement InvSinhButton => this.session.TryFindElementByAccessibilityId("invsinhButton");
public WindowsElement InvCoshButton => this.session.TryFindElementByAccessibilityId("invcoshButton");
public WindowsElement InvTanhButton => this.session.TryFindElementByAccessibilityId("invtanhButton");
public WindowsElement InvCschButton => this.session.TryFindElementByAccessibilityId("invcschButton");
public WindowsElement InvSechButton => this.session.TryFindElementByAccessibilityId("invsechButton");
public WindowsElement InvCothButton => this.session.TryFindElementByAccessibilityId("invcothButton");
public WindowsElement FloorButton => this.session.TryFindElementByAccessibilityId("floorButton");
public WindowsElement CeilButton => this.session.TryFindElementByAccessibilityId("ceilButton");
public WindowsElement RandButton => this.session.TryFindElementByAccessibilityId("randButton");
public WindowsElement DmsButton => this.session.TryFindElementByAccessibilityId("dmsButton");
public WindowsElement DegreesButton => this.session.TryFindElementByAccessibilityId("degreesButton");
public WindowsElement FixedToExponentialButton => this.session.TryFindElementByAccessibilityId("ftoeButton");
public WindowsElement NegateButton => this.session.TryFindElementByAccessibilityId("negateButton");
public WindowsElement TrigFlyout => this.session.TryFindElementByAccessibilityId("Trigflyout");
public WindowsElement LightDismiss => this.session.TryFindElementByAccessibilityId("Light Dismiss");
private WindowsElement DegRadGradButton => GetAngleOperatorButton();
private WindowsElement GetAngleOperatorButton()
{
string source = this.session.PageSource;
if (source.Contains("degButton"))
{
return DegButton;
}
else if (source.Contains("gradButton"))
{
return GradButton;
}
else if (source.Contains("radButton"))
{
return RadButton;
}
throw new NotFoundException("Could not find deg, rad or grad button in page source");
}
/// <summary>
/// Set the state of the degrees, radians and gradians buttons.
/// </summary>
public void SetAngleOperator(AngleOperatorState value)
{
//set the desired string value for the button
string desiredId;
switch (value)
{
case AngleOperatorState.Degrees:
desiredId = "degButton";
break;
case AngleOperatorState.Gradians:
desiredId = "gradButton";
break;
case AngleOperatorState.Radians:
desiredId = "radButton";
break;
default:
throw new NotImplementedException();
}
while (this.DegRadGradButton.GetAttribute("AutomationId") != desiredId)
{
this.DegRadGradButton.Click();
}
}
public void ResetFEButton(fEButtonState value)
{
if (this.FixedToExponentialButton.GetAttribute("Toggle.ToggleState") != "0")
{
FixedToExponentialButton.Click();
}
}
public WindowsElement ResetTrigDropdownToggles()
{
TrigButton.Click();
string source = this.session.PageSource;
if (source.Contains("sinButton"))
{
LightDismiss.Click();
}
else if (source.Contains("invsinButton"))
{
TrigShiftButton.Click();
}
else if (source.Contains("sinhButton"))
{
HypShiftButton.Click();
}
else if (source.Contains("invsinhButton"))
{
TrigShiftButton.Click();
HypShiftButton.Click();
}
throw new NotFoundException("Could not find trig drop-down buttons in page source");
}
}
}