UI Automation using Appium and WinAppDriver

Introduction to Appium

Appium is an open source cross platform test automation framework for use with native, hybrid and mobile web apps. It drives iOS, Android, and Windows apps using the WebDriver protocol. Platforms supported are:

  •  iOS
  • Android
  • Windows
  • FirefoxOS

Step 1: Installing Appium in Windows machine

npm install -g appium  // get appium
npm install wd   // get appium client
appium &         //Start appium

Appium install

Note: Appium will install WindowsAppDriver automatically.

You can explicitly install WindowsAppDriver.exe from 

https://github.com/Microsoft/WinAppDriver/releases

Step 2: Writing your Test code( classic Windows app)

You can use any Selenium supported language and specify the full executable path for the app under test in the app capabilities entry. In my example I will be using C#.

Following is a sample code to create test session for Windows Notepad. If you are using Appium as mentioned in Step 1, do not forget to add /wd/hub in ur URL.

You can get the complete sample project at my Github site.

namespace NotepadExample
{
    [TestClass]
    public class NotepadBase
    {
        // Note: append /wd/hub to the URL if you're directing the test at Appium
        protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723/wd/hub";
        protected static WindowsDriver<WindowsElement> NotepadSession;

        [ClassInitialize]
        public static void NotepadBaseSetup(TestContext testcontext)
        {
            if (NotepadSession == null)
            {
               //launch the Notepad app
               DesiredCapabilities appCapabilities = new DesiredCapabilities();
               appCapabilities.SetCapability("deviceName", "WindowsPC");
               appCapabilities.SetCapability("app", @"C:\Windows\System32\notepad.exe");
               NotepadSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
            }
        }
        [TestMethod]
        public void TestMethod1()
        {
          NotepadSession.FindElementByClassName("Edit").SendKeys("This is an automated text......");
          Assert.IsNotNull(NotepadSession);
        }
        [ClassCleanup]
        public static void NotepadBaseTearDown()
        {
            if (NotepadSession != null)
            {
                NotepadSession.Dispose();
                NotepadSession = null;
            }
        }
    }
}

Using Appium you can write tests with any WebDriver compatible language such as Java, C#, Nodejs, PHP, Phython, Ruby or Perl With the Selenium WebDriver API. It removes limitation of Selenium by providing support to Windows based desktop applications.

Watch the video for easy reference.

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.