Best WinAppDriver code snippet using CalculatorTest.CalculatorSession
BasicScenarios.cs
Source:BasicScenarios.cs
...23 [TestClass]24 public class BasicScenarios25 {26 protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723/wd/hub";27 protected static RemoteWebDriver CalculatorSession;28 protected static RemoteWebElement CalculatorResult;29 protected static string OriginalCalculatorMode;30 [ClassInitialize]31 public static void Setup(TestContext context)32 {33 // Launch the calculator app34 DesiredCapabilities appCapabilities = new DesiredCapabilities();35 appCapabilities.SetCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");36 appCapabilities.SetCapability("platformName", "Windows");37 appCapabilities.SetCapability("deviceName", "WindowsPC");38 CalculatorSession = new RemoteWebDriver(new Uri(WindowsApplicationDriverUrl), appCapabilities);39 Assert.IsNotNull(CalculatorSession);40 CalculatorSession.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2));41 // Make sure we're in standard mode42 CalculatorSession.FindElementByXPath("//Button[starts-with(@Name, \"Menu\")]").Click();43 OriginalCalculatorMode = CalculatorSession.FindElementByXPath("//List[@AutomationId=\"FlyoutNav\"]//ListItem[@IsSelected=\"True\"]").Text;44 CalculatorSession.FindElementByXPath("//ListItem[@Name=\"Standard Calculator\"]").Click();45 // Use series of operation to locate the calculator result text element as a workaround46 // We currently cannot query element by automationId without using modified appium dot net driver47 // TODO: Use a proper appium/webdriver nuget package that allow us to query based on automationId48 CalculatorSession.FindElementByXPath("//Button[@Name=\"Clear\"]").Click();49 CalculatorSession.FindElementByXPath("//Button[@Name=\"Seven\"]").Click();50 CalculatorResult = CalculatorSession.FindElementByName("Display is 7 ") as RemoteWebElement;51 Assert.IsNotNull(CalculatorResult);52 }53 [ClassCleanup]54 public static void TearDown()55 {56 // Restore original mode before closing down57 CalculatorSession.FindElementByXPath("//Button[starts-with(@Name, \"Menu\")]").Click();58 CalculatorSession.FindElementByXPath("//ListItem[@Name=\"" + OriginalCalculatorMode + "\"]").Click();59 CalculatorResult = null;60 CalculatorSession.Dispose();61 CalculatorSession = null;62 }63 [TestInitialize]64 public void Clear()65 {66 CalculatorSession.FindElementByName("Clear").Click();67 Assert.AreEqual("Display is 0 ", CalculatorResult.Text);68 }69 [TestMethod]70 public void Addition()71 {72 CalculatorSession.FindElementByName("One").Click();73 CalculatorSession.FindElementByName("Plus").Click();74 CalculatorSession.FindElementByName("Seven").Click();75 CalculatorSession.FindElementByName("Equals").Click();76 Assert.AreEqual("Display is 8 ", CalculatorResult.Text);77 }78 [TestMethod]79 public void Combination()80 {81 CalculatorSession.FindElementByXPath("//Button[@Name=\"Seven\"]").Click();82 CalculatorSession.FindElementByXPath("//Button[@Name=\"Multiply by\"]").Click();83 CalculatorSession.FindElementByXPath("//Button[@Name=\"Nine\"]").Click();84 CalculatorSession.FindElementByXPath("//Button[@Name=\"Plus\"]").Click();85 CalculatorSession.FindElementByXPath("//Button[@Name=\"One\"]").Click();86 CalculatorSession.FindElementByXPath("//Button[@Name=\"Equals\"]").Click();87 CalculatorSession.FindElementByXPath("//Button[@Name=\"Divide by\"]").Click();88 CalculatorSession.FindElementByXPath("//Button[@Name=\"Eight\"]").Click();89 CalculatorSession.FindElementByXPath("//Button[@Name=\"Equals\"]").Click();90 Assert.AreEqual("Display is 8 ", CalculatorResult.Text);91 }92 [TestMethod]93 public void Division()94 {95 CalculatorSession.FindElementByName("Eight").Click();96 CalculatorSession.FindElementByName("Eight").Click();97 CalculatorSession.FindElementByName("Divide by").Click();98 CalculatorSession.FindElementByName("One").Click();99 CalculatorSession.FindElementByName("One").Click();100 CalculatorSession.FindElementByName("Equals").Click();101 Assert.AreEqual("Display is 8 ", CalculatorResult.Text);102 }103 [TestMethod]104 public void Multiplication()105 {106 CalculatorSession.FindElementByName("Nine").Click();107 CalculatorSession.FindElementByName("Multiply by").Click();108 CalculatorSession.FindElementByName("Nine").Click();109 CalculatorSession.FindElementByName("Equals").Click();110 Assert.AreEqual("Display is 81 ", CalculatorResult.Text);111 }112 [TestMethod]113 public void Subtraction()114 {115 CalculatorSession.FindElementByName("Nine").Click();116 CalculatorSession.FindElementByName("Minus").Click();117 CalculatorSession.FindElementByName("One").Click();118 CalculatorSession.FindElementByName("Equals").Click();119 Assert.AreEqual("Display is 8 ", CalculatorResult.Text);120 }121 }122}...
CalculatorSession
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using CalculatorTest;7{8 {9 static void Main(string[] args)10 {11 CalculatorSession cs = new CalculatorSession();12 Console.WriteLine("Addition of 10 and 20 is " + cs.Add(10, 20));13 Console.WriteLine("Subtraction of 10 and 20 is " + cs.Subtract(10, 20));14 Console.WriteLine("Multiplication of 10 and 20 is " + cs.Multiply(10, 20));15 Console.WriteLine("Division of 10 and 20 is " + cs.Divide(10, 20));16 Console.ReadLine();17 }18 }19}
CalculatorSession
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using CalculatorTest;7{8 {9 static void Main(string[] args)10 {11 CalculatorSession calc = new CalculatorSession();12 Console.WriteLine("Enter first number");13 int num1 = int.Parse(Console.ReadLine());14 Console.WriteLine("Enter second number");15 int num2 = int.Parse(Console.ReadLine());16 Console.WriteLine("Addition of two numbers is {0}", calc.Add(num1, num2));17 Console.WriteLine("Subtraction of two numbers is {0}", calc.Subtract(num1, num2));18 Console.WriteLine("Multiplication of two numbers is {0}", calc.Multiply(num1, num2));19 Console.WriteLine("Division of two numbers is {0}", calc.Divide(num1, num2));20 Console.ReadLine();21 }22 }23}
CalculatorSession
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using CalculatorTest;7{8 {9 static void Main(string[] args)10 {11 Calculator obj = new Calculator();12 Console.WriteLine("Enter two numbers");13 int a = int.Parse(Console.ReadLine());14 int b = int.Parse(Console.ReadLine());15 obj.Add(a, b);16 obj.Subtract(a, b);17 obj.Multiply(a, b);18 obj.Divide(a, b);19 Console.ReadLine();20 }21 }22}
CalculatorSession
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using CalculatorTest;7{8 {9 static void Main(string[] args)10 {11 Calculator calc = new Calculator();12 int result = calc.Add(10, 20);13 Console.WriteLine("Addition of 10 and 20 is {0}", result);14 result = calc.Subtract(40, 20);15 Console.WriteLine("Subtraction of 40 and 20 is {0}", result);16 result = calc.Multiply(10, 20);17 Console.WriteLine("Multiplication of 10 and 20 is {0}", result);18 result = calc.Divide(40, 20);19 Console.WriteLine("Division of 40 and 20 is {0}", result);20 Console.ReadLine();21 }22 }23}
CalculatorSession
Using AI Code Generation
1using System;2using CalculatorTest;3using System.Runtime.Remoting;4using System.Runtime.Remoting.Channels;5using System.Runtime.Remoting.Channels.Tcp;6using System.Runtime.Remoting.Channels.Http;7using System.Runtime.Remoting.Channels.Ipc;8{9 static void Main(string[] args)10 {11 TcpChannel channel = new TcpChannel(8000);12 ChannelServices.RegisterChannel(channel);13 CalculatorSession cs = new CalculatorSession();14 RemotingServices.Marshal(cs, "Calculator");15 Console.WriteLine("Press Enter to exit");16 Console.ReadLine();17 }18}19using System;20using CalculatorTest;21using System.Runtime.Remoting;22using System.Runtime.Remoting.Channels;23using System.Runtime.Remoting.Channels.Tcp;24using System.Runtime.Remoting.Channels.Http;25using System.Runtime.Remoting.Channels.Ipc;26{27 static void Main(string[] args)28 {29 HttpChannel channel = new HttpChannel(8000);30 ChannelServices.RegisterChannel(channel);31 CalculatorSession cs = new CalculatorSession();32 RemotingServices.Marshal(cs, "Calculator");33 Console.WriteLine("Press Enter to exit");34 Console.ReadLine();35 }36}37using System;38using CalculatorTest;39using System.Runtime.Remoting;40using System.Runtime.Remoting.Channels;41using System.Runtime.Remoting.Channels.Tcp;42using System.Runtime.Remoting.Channels.Http;43using System.Runtime.Remoting.Channels.Ipc;44{45 static void Main(string[] args)46 {47 IpcChannel channel = new IpcChannel("MyChannel");48 ChannelServices.RegisterChannel(channel);49 CalculatorSession cs = new CalculatorSession();50 RemotingServices.Marshal(cs, "Calculator");51 Console.WriteLine("Press Enter to exit");52 Console.ReadLine();53 }54}55using System;56using CalculatorTest;
CalculatorSession
Using AI Code Generation
1using System;2using System.Collections;3using System.ComponentModel;4using System.Data;5using System.Drawing;6using System.Text;7using System.Windows.Forms;8using CalculatorTest;9{10 {11 public Form1()12 {13 InitializeComponent();14 }15 private void button1_Click(object sender, EventArgs e)16 {17 CalculatorSession obj = new CalculatorSession();18 obj.Add(2, 3);19 obj.Add(4, 5);20 obj.Add(6, 7);21 obj.Add(8, 9);22 int result = obj.Result;23 MessageBox.Show(result.ToString());24 }25 }26}27System.Net.WebClient client = new System.Net.WebClient();28MessageBox.Show(result.ToString());29System.Net.WebClient client = new System.Net.WebClient();
CalculatorSession
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using CalculatorTest;7{8 {9 public int Add(int a, int b)10 {11 return a + b;12 }13 public int Subtract(int a, int b)14 {15 return a - b;16 }17 public int Multiply(int a, int b)18 {19 return a * b;20 }21 public int Divide(int a, int b)22 {23 return a / b;24 }25 }26}27using System;28using System.Collections.Generic;29using System.Linq;30using System.Text;31using System.Threading.Tasks;32using CalculatorTest;33{34 {35 public int Add(int a, int b)36 {37 return a + b;38 }39 public int Subtract(int a, int b)40 {41 return a - b;42 }43 public int Multiply(int a, int b)44 {45 return a * b;46 }47 public int Divide(int a, int b)48 {49 return a / b;50 }51 }52}53using System;54using System.Collections.Generic;55using System.Linq;56using System.Text;57using System.Threading.Tasks;58using CalculatorTest;59{60 {61 public int Add(int a, int b)62 {63 return a + b;64 }65 public int Subtract(int a, int b)66 {67 return a - b;68 }69 public int Multiply(int a, int b)70 {71 return a * b;72 }73 public int Divide(int a, int b)74 {75 return a / b;76 }77 }78}79using System;80using System.Collections.Generic;81using System.Linq;82using System.Text;83using System.Threading.Tasks;84using CalculatorTest;85{86 {87 public int Add(int a, int b)88 {89 return a + b;90 }91 public int Subtract(int a, int b)92 {93 return a - b;94 }
CalculatorSession
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Text;4using CalculatorTest;5{6{7static void Main(string[] args)8{9CalculatorSession calc = new CalculatorSession();10Console.WriteLine("Addition of 2 and 3 is: " + calc.Add(2, 3));11Console.WriteLine("Subtraction of 2 and 3 is: " + calc.Subtract(2, 3));12Console.WriteLine("Multiplication of 2 and 3 is: " + calc.Multiply(2, 3));13Console.WriteLine("Division of 2 and 3 is: " + calc.Divide(2, 3));14Console.ReadLine();15}16}17}
CalculatorSession
Using AI Code Generation
1using System;2using CalculatorTest;3{4 {5 public int result;6 public void Add(int x, int y)7 {8 result = x + y;9 }10 public void Sub(int x, int y)11 {12 result = x - y;13 }14 public void Mul(int x, int y)15 {16 result = x * y;17 }18 public void Div(int x, int y)19 {20 result = x / y;21 }22 }23}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!