Introduction
This blog is for beginners. It's mainly to teach you how to automate a Windows Application using C#, Winapp driver (Appium), & Selenium. In this blog, we are going to automate the Calculator app.
Winapp driver (Appium)
Winapp is a Product of Microsoft, using this driver we can automate Windows applications, classic Windows applications, universal Windows applications, and mobile applications. We can use this driver on the top of a Selenium library.
It is the latest Windows automation driver. It has advantages over Winum Driver & autoT.
Set up required for this:
- Windows 10 OS
- Visual Studio 2013+
- Winapp driver.exe
- Inspect.exe for identifying your element value
- Calculator app for automate
- Your PC should be on Developer mode (ON)
Steps to follow,
- Download the Winapp driver from here,
Download the WindowsApplicationDriver.msi
- Open the Download folder and process WindowsApplicationDriver.msi up to install Windows application driver.
- Click it for installation.
- After installation is complete go to C>>Program Files (x86) >>Windows Application Driver.
- Double click on WinAppDriver.exe for run the Windows application Driver as below:
- Now, time to install windows Inspect.exe.
To download inspect tool click here,
Note
You can download any tool to inspect elements or find elements. After downloading, run inspect.exe and see the control id, name, class etc.
Now, we will move to the coding part,
- Open Visual Studio
- Click on File>>New>>Project
- Click on Test for creating a unit test project.
- Open NuGet Package Manager to install Appium Driver.
Installation steps
Click on Tools >>NuGetPackageManager>>Manage NuGet PackageFor Solution.
Open the UnitTest1.cs file and paste the below code.
- using System;
- using System.Threading;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using OpenQA.Selenium;
- using OpenQA.Selenium.Appium.Windows;
- using OpenQA.Selenium.Remote;
-
- namespace CalculatorAutomationWinappDriver
- {
- [TestClass]
- public class UnitTest1
- {
-
- private const string appiumDriverURI = "http://127.0.0.1:4723";
-
-
- private const string calApp = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App";
-
- protected static WindowsDriver<WindowsElement> calSession;
-
-
- [TestMethod]
- public void TestMethod1()
- {
- if (calSession == null)
- {
- DesiredCapabilities appCapabilities = new DesiredCapabilities();
- appCapabilities.SetCapability("app", calApp);
- appCapabilities.SetCapability("deviceName", "WindowsPC");
-
- calSession = new WindowsDriver<WindowsElement>(new Uri(appiumDriverURI), appCapabilities);
-
-
-
-
- calSession.FindElement(By.Name("Nine")).Click();
- calSession.FindElement(By.Name("One")).Click();
- calSession.FindElement(By.Name("Two")).Click();
- calSession.FindElement(By.Name("Three")).Click();
- calSession.FindElement(By.Name("Multiply by")).Click();
-
- calSession.FindElementByAccessibilityId("num9Button").Click();
- calSession.FindElementByAccessibilityId("equalButton").Click();
-
- string ExpectedValue = calSession.FindElementByAccessibilityId("CalculatorResults").Text;
- string ExpectedValue1 = ExpectedValue.Replace("Display is ","").Replace(",","");
-
-
- Assert.AreEqual(82107,Convert.ToInt64(ExpectedValue1));
- }
- }
- }
- }
Now, you can automate calculator.
Some basic steps to find elements using Inspect.exe:
Now, we can automate any Windows application using C# as shown above. A very important note: Don't worry if you are new in identifying Elements on Inspect.exe.
Note
In the upcoming blog, I will be automating a classic Windows application.