How to use LegacyCalc class of FlaUI.Core.UITests package

Best FlaUI code snippet using FlaUI.Core.UITests.LegacyCalc

CalculatorTests.cs

Source:CalculatorTests.cs Github

copy

Full Screen

...18 [Test]19 public void CalculatorTest()20 {21 var window = App.GetMainWindow(Automation);22 var calc = OperatingSystem.IsWindows10() ? (ICalculator)new Win10Calc(window) : new LegacyCalc(window);23 // Switch to default mode24 System.Threading.Thread.Sleep(1000);25 Keyboard.TypeSimultaneously(VirtualKeyShort.ALT, VirtualKeyShort.KEY_1);26 Wait.UntilInputIsProcessed();27 App.WaitWhileBusy();28 System.Threading.Thread.Sleep(1000);29 // Simple addition30 calc.Button1.Click();31 calc.Button2.Click();32 calc.Button3.Click();33 calc.Button4.Click();34 calc.ButtonAdd.Click();35 calc.Button5.Click();36 calc.Button6.Click();37 calc.Button7.Click();38 calc.Button8.Click();39 calc.ButtonEquals.Click();40 App.WaitWhileBusy();41 var result = calc.Result;42 Assert.That(result, Is.EqualTo("6912"));43 // Date comparison44 using (Keyboard.Pressing(VirtualKeyShort.CONTROL))45 {46 Keyboard.Type(VirtualKeyShort.KEY_E);47 }48 }49 protected override Application StartApplication()50 {51 if (OperatingSystem.IsWindows10())52 {53 // Use the store application on those systems54 return Application.LaunchStoreApp("Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");55 }56 if (OperatingSystem.IsWindowsServer2016())57 {58 // The calc.exe on this system is just a stub which launches win32calc.exe59 return Application.Launch("win32calc.exe");60 }61 return Application.Launch("calc.exe");62 }63 }64 public interface ICalculator65 {66 Button Button1 { get; }67 Button Button2 { get; }68 Button Button3 { get; }69 Button Button4 { get; }70 Button Button5 { get; }71 Button Button6 { get; }72 Button Button7 { get; }73 Button Button8 { get; }74 Button ButtonAdd { get; }75 Button ButtonEquals { get; }76 string Result { get; }77 }78 public class LegacyCalc : ICalculator79 {80 private readonly AutomationElement _mainWindow;81 public Button Button1 => FindElement("1").AsButton();82 public Button Button2 => FindElement("2").AsButton();83 public Button Button3 => FindElement("3").AsButton();84 public Button Button4 => FindElement("4").AsButton();85 public Button Button5 => FindElement("5").AsButton();86 public Button Button6 => FindElement("6").AsButton();87 public Button Button7 => FindElement("7").AsButton();88 public Button Button8 => FindElement("8").AsButton();89 public Button ButtonAdd => FindElement("Add").AsButton();90 public Button ButtonEquals => FindElement("Equals").AsButton();91 public string Result92 {93 get94 {95 var resultElement = _mainWindow.FindFirstDescendant(cf => cf.ByAutomationId("158"));96 var value = resultElement.Properties.Name;97 return Regex.Replace(value, "[^0-9]", String.Empty);98 }99 }100 public LegacyCalc(AutomationElement mainWindow)101 {102 _mainWindow = mainWindow;103 }104 private AutomationElement FindElement(string text)105 {106 var element = _mainWindow.FindFirstDescendant(cf => cf.ByText(text));107 return element;108 }109 }110 public class Win10Calc : ICalculator111 {112 private readonly AutomationElement _mainWindow;113 public Button Button1 => FindElement("num1Button").AsButton();114 public Button Button2 => FindElement("num2Button").AsButton();...

Full Screen

Full Screen

LegacyCalc

Using AI Code Generation

copy

Full Screen

1using FlaUI.Core.UITests;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 static void Main(string[] args)10 {11 LegacyCalc calc = new LegacyCalc();12 calc.Launch();13 calc.Add(2, 3);14 Console.WriteLine(calc.Result);15 calc.Close();16 }17 }18}19using FlaUI.Core;20using FlaUI.Core.AutomationElements;21using FlaUI.Core.AutomationElements.Infrastructure;22using FlaUI.Core.Definitions;23using FlaUI.Core.Tools;24using System;25using System.Collections.Generic;26using System.Linq;27using System.Text;28using System.Threading.Tasks;29{30 {31 private Application _app;32 private Window _window;33 public void Launch()34 {35 _app = Application.Launch("calc.exe");36 _window = _app.GetMainWindow();37 }38 public void Close()39 {40 _app.Close();41 }42 public void Add(int a, int b)43 {44 var num1 = _window.FindFirstDescendant(cf => cf.ByAutomationId("num1Button")).AsButton();45 var num2 = _window.FindFirstDescendant(cf => cf.ByAutomationId("num2Button")).AsButton();46 var num3 = _window.FindFirstDescendant(cf => cf.ByAutomationId("num3Button")).AsButton();

Full Screen

Full Screen

LegacyCalc

Using AI Code Generation

copy

Full Screen

1using FlaUI.Core.UITests;2{3 {4 public int Add(int a, int b)5 {6 return a + b;7 }8 }9}10using FlaUI.Core.UITests;11{12 {13 public int Add(int a, int b)14 {15 return a + b;16 }17 }18}19using FlaUI.Core.UITests;20{21 {22 public int Add(int a, int b)23 {24 return a + b;25 }26 }27}28using FlaUI.Core.UITests;29{30 {31 public int Add(int a, int b)32 {33 return a + b;34 }35 }36}37using FlaUI.Core.UITests;38{39 {40 public int Add(int a, int b)41 {42 return a + b;43 }44 }45}46using FlaUI.Core.UITests;47{48 {49 public int Add(int a, int b)50 {51 return a + b;52 }53 }54}55using FlaUI.Core.UITests;56{57 {58 public int Add(int a, int b)59 {60 return a + b;61 }62 }63}

Full Screen

Full Screen

LegacyCalc

Using AI Code Generation

copy

Full Screen

1using FlaUI.Core.UITests;2using FlaUI.Core;3using FlaUI.Core.AutomationElements;4using FlaUI.Core.Conditions;5using FlaUI.Core.Definitions;6using FlaUI.Core.Tools;7using FlaUI.Core.WindowsAPI;8using FlaUI.UIA3;9using System;10{11 {12 public static void Main(string[] args)13 {14 var application = Application.Launch(@"C:\Windows\System32\calc.exe");15 var automation = new UIA3Automation();16 var mainWindow = application.GetMainWindow(automation);17 mainWindow.FindFirstDescendant(cf => cf.ByText("1")).Click();18 mainWindow.FindFirstDescendant(cf => cf.ByText("2")).Click();19 mainWindow.FindFirstDescendant(cf => cf.ByText("3")).Click();20 mainWindow.FindFirstDescendant(cf => cf.ByText("4")).Click();21 mainWindow.FindFirstDescendant(cf => cf.ByText("5")).Click();22 mainWindow.FindFirstDescendant(cf => cf.ByText("6")).Click();23 mainWindow.FindFirstDescendant(cf => cf.ByText("7")).Click();24 mainWindow.FindFirstDescendant(cf => cf.ByText("8")).Click();25 mainWindow.FindFirstDescendant(cf => cf.ByText("9")).Click();26 mainWindow.FindFirstDescendant(cf => cf.ByText("0")).Click();27 mainWindow.FindFirstDescendant(cf => cf.ByText("5")).Click();28 mainWindow.FindFirstDescendant(cf => cf.ByText("+")).Click();29 mainWindow.FindFirstDescendant(cf => cf.ByText("6")).Click();30 mainWindow.FindFirstDescendant(cf => cf.ByText("=")).Click();31 mainWindow.FindFirstDescendant(cf => cf.ByText("C")).Click();32 mainWindow.FindFirstDescendant(cf => cf.ByText("1")).Click();33 mainWindow.FindFirstDescendant(cf => cf.ByText("2")).Click();34 mainWindow.FindFirstDescendant(cf => cf.ByText("3")).Click();35 mainWindow.FindFirstDescendant(cf => cf.ByText("4")).Click();36 mainWindow.FindFirstDescendant(cf => cf.ByText("5")).Click();37 mainWindow.FindFirstDescendant(cf => cf.ByText("6")).Click();38 mainWindow.FindFirstDescendant(cf => cf.ByText("7")).Click();39 mainWindow.FindFirstDescendant(cf => cf.ByText("8")).Click();40 mainWindow.FindFirstDescendant(cf => cf

Full Screen

Full Screen

LegacyCalc

Using AI Code Generation

copy

Full Screen

1using FlaUI.Core.UITests;2using FlaUI.Core.UITests.Calculator;3using FlaUI.Core.UITests.Calculator.Calculator;4using FlaUI.Core.UITests.Calculator.Calculator.Calculator;5using FlaUI.Core.UITests.Calculator.Calculator.Calculator.Calculator;6using FlaUI.Core.UITests.Calculator.Calculator.Calculator.Calculator.Calculator;7using FlaUI.Core.UITests.Calculator.Calculator.Calculator.Calculator.Calculator.Calculator;8using FlaUI.Core.UITests.Calculator.Calculator.Calculator.Calculator.Calculator.Calculator.Calculator;9using FlaUI.Core.UITests.Calculator.Calculator.Calculator.Calculator.Calculator.Calculator.Calculator.Calculator;10using FlaUI.Core.UITests.Calculator.Calculator.Calculator.Calculator.Calculator.Calculator.Calculator.Calculator.Calculator;11using FlaUI.Core.UITests.Calculator.Calculator.Calculator.Calculator.Calculator.Calculator.Calculator.Calculator.Calculator.Calculator;

Full Screen

Full Screen

LegacyCalc

Using AI Code Generation

copy

Full Screen

1using FlaUI.Core.UITests;2using FlaUI.Core.UITests.Calculator;3using FlaUI.Core;4using FlaUI.Core.Conditions;5using FlaUI.Core.AutomationElements;6using FlaUI.Core.AutomationElements.Infrastructure;7using FlaUI.Core.Tools;8using System;9using System.Linq;10{11 {12 public LegacyCalc() : base("LegacyCalc")13 {14 }15 public override Window Initialize()16 {17 var window = Retry.WhileNull(() => Application.GetMainWindow(Automation), TimeSpan.FromSeconds(5));18 window.WaitUntilResponsive();19 return window;20 }21 public void EnterNumber(int number)22 {23 foreach (var digit in number.ToString())24 {25 var button = Window.FindFirstDescendant(cf => cf.ByAutomationId("num" + digit + "Button"));26 button.Click();27 }28 }29 public void Add()30 {31 Window.FindFirstDescendant(cf => cf.ByAutomationId("plusButton")).Click();32 }33 public void Equal()34 {35 Window.FindFirstDescendant(cf => cf.ByAutomationId("equalButton")).Click();36 }37 public string GetResultText()38 {39 return Window.FindFirstDescendant(cf => cf.ByAutomationId("CalculatorResults")).AsLabel().Text;40 }41 }42}43using FlaUI.Core.UITests;44using FlaUI.Core.UITests.Calculator;45using FlaUI.Core;46using FlaUI.Core.Conditions;47using FlaUI.Core.AutomationElements;48using FlaUI.Core.AutomationElements.Infrastructure;49using FlaUI.Core.Tools;50using System;51using System.Linq;52{53 {54 public LegacyCalc() : base("LegacyCalc")55 {56 }57 public override Window Initialize()58 {59 var window = Retry.WhileNull(() => Application.GetMainWindow(Automation), TimeSpan.FromSeconds(5));60 window.WaitUntilResponsive();61 return window;62 }63 public void EnterNumber(int number)64 {65 foreach (var digit in number.ToString())66 {67 var button = Window.FindFirstDescendant(cf => cf.ByAutomationId("num" + digit + "Button"));68 button.Click();69 }70 }71 public void Add()

Full Screen

Full Screen

LegacyCalc

Using AI Code Generation

copy

Full Screen

1using FlaUI.Core.UITests;2using FlaUI.Core;3using FlaUI.Core.AutomationElements;4using FlaUI.Core.Conditions;5using FlaUI.Core.Input;6using FlaUI.Core.WindowsAPI;7using FlaUI.Core.EventHandlers;8using FlaUI.Core.WindowsAPI;9using FlaUI.Core.EventHandlers;10using FlaUI.Core.AutomationElements.Infrastructure;

Full Screen

Full Screen

LegacyCalc

Using AI Code Generation

copy

Full Screen

1using FlaUI.Core;2using FlaUI.Core.Definitions;3using FlaUI.Core.Elements;4using FlaUI.Core.Elements.Infrastructure;5using FlaUI.Core.EventHandlers;6using FlaUI.Core.Identifiers;7using FlaUI.Core.Input;8using FlaUI.Core.Tools;9using FlaUI.UIA2;10using FlaUI.UIA2.Identifiers;11using System;12using System.Collections.Generic;13using System.Drawing;14using System.Linq;15using System.Text;16using System.Threading.Tasks;17using System.Windows.Automation;18using System.Windows.Automation.Text;19using System.Windows.Forms;20{21 {22 private readonly Application _application;23 private readonly Window _window;24 public LegacyCalc()25 {26 _application = Application.Launch(@"C:\Windows\System32\calc.exe");27 _window = Retry.WhileNull(() => _application.GetMainWindow(AutomationType.UIA2), TimeSpan.FromSeconds(2));28 }29 public void Close()30 {31 _application.Close();32 }33 public void ClickDigit(int digit)34 {35 var digitButton = _window.FindFirstDescendant(cf => cf.ByAutomationId($"num{digit}Button"));36 digitButton.AsButton().Invoke();37 }38 public void ClickAdd()39 {40 var addButton = _window.FindFirstDescendant(cf => cf.ByAutomationId("plusButton"));41 addButton.AsButton().Invoke();42 }43 public void ClickEquals()44 {45 var addButton = _window.FindFirstDescendant(cf => cf.ByAutomationId("equalButton"));46 addButton.AsButton().Invoke();47 }48 public string GetResultText()49 {50 var resultTextBlock = _window.FindFirstDescendant(cf => cf.ByAutomationId("CalculatorResults"));51 return resultTextBlock.AsText().Text;52 }53 }54}55using FlaUI.Core;56using FlaUI.Core.Definitions;57using FlaUI.Core.Elements;58using FlaUI.Core.Elements.Infrastructure;59using FlaUI.Core.EventHandlers;60using FlaUI.Core.Identifiers;61using FlaUI.Core.Input;62using FlaUI.Core.Tools;63using FlaUI.UIA2;64using FlaUI.UIA2.Identifiers;

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run FlaUI automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in LegacyCalc

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful