Friday, May 15, 2020

Using Appium Client For Object Inspection With WinAppDriver in Windows 10 Test Automation


Download free e-book Windows Test Automation With Appium Windows Application Driver in C# .Net


Introduction to Appium Desktop Client




When I created my Udemy Course about WinAppDriverUI Automation Testing in 2019, I relied solely on the WinAppDriver UI Recorder for inspecting various elements of Windows applications. I showed how to automate. Not much information was available on the subject back then. I recently came across another tool that we can use to look into various application elements and find their attributes for UI test automation.

This article is going to show you just that because I believe it has the potential to make your life easier. I've also added the same videos to my Udemy course and YouTube channel. This tool is called the Appium Desktop.  

You can download it from the Appium.io website. 

Before we proceed, please remember there are two prerequisites for using Appium Desktop. 
  1. Enable Windows 10 Developer Mode on your PC
  2. You need to have WinAppDriver 1.1 or above installed on your PC. 



    Please note that you don't need to install Node.js to run an Appium desktop client. Let me google the search term Appium Desktop client quickly and show you. 

    We are going to click the link titled "Appium desktop for OSX, Windows, and Linux".

    appium WinAppDriver

    This will take us to the GitHub repository of the Appium Desktop project. You will need to download the Appium-windows.exe from here and use it to install an Appium desktop.

    Please see the screenshot below.


    appium desktop
    Once you've got Appium Desktop installed, you can proceed further. We are going to start using Appium Desktop for inspecting Windows Applications. Please note that you can use the same utility to check apps on other Appium supported platforms such as Android and iOS as well if you have proper tools installed.  Although that's beyond the scope of this blog.



    Running Appium Desktop Client and Connecting to a Windows Application


    Before we proceed with using the Appium Desktop Client to inspect the elements of a Windows Application, please start the WinAppDriver.exe. 


    WinAppDriver

    Now let's run the Appium Desktop Client, you'll be able to find it in your Windows applications. Click the "Start" button and type Appium. 



    Appium App WinAppDriver

    Now click the "Appium" icon to open the application. The Appium desktop client can take a few seconds to load. On the main Appium UI, go to the "File" menu and select "New Session Window." 

    Appium Session

    A new dialog box will open up. The tab "Custom Server" will be selected. I'll leave the remote host and remote port fields unchanged. In the Remote Path field, I'm going to put a forward slash. Then there's this table like Ui to specify Desired Capabilities. I am going to click on the first text box that contains the text "Name." type the word app in there. Please note, the word app will be small. In the value textbox, I'll paste the user mode ID of the Microsoft Windows 10 Calculator app which is:

    Microsoft.WindowsCalculator_8wekyb3d8bbwe!App


    I've shown how to find this value in my course. The final screenshot of the Appium custom server is shown below FYI: 

    WinAppDriver Ui Testing Appium Custom Server



    Now Appium Client is going to connect the instance of WinAppDriver, which is running on this PC and listening on port number 4723. Remember, we started it earlier. I'll press the button, "Start Session."

    Appium Port No


    The calculator app will start, and you'll get a preview inside the Appium UI inspector. You can hover the mouse on various controls of the application under test, and those controls will be highlighted in yellow. The mouse cursor is also changing into a hand in my case, but it was not captured in the screenshot.


    Appium UI inspector

    Let's end this section here, and we will learn more about the Appium UI Inspector
    in the section below. 


    Inspecting Elements Using Appium Desktop Client and WinAppDriver For Automated Testing


    Once we have created a session in Appium Client, we will be able to inspect various elements of the loaded application. The Appium Client object inspector UI is pretty simple. There's a row of the button on the top, "Select Elements" is clicked by default. 


    Appium Select Element
    1. We have the application preview loaded on the left side.
    2. “App Source” in the middle showing the hierarchy of application controls. 
    3. The rightmost panel is Selected Element”, it will populate when we’ll click an element. 


    Selected Element




    For Example, we will hover the mouse on the application preview shown in the Appium Desktop Client. 


    You will see that the element under the cursor will highlight yellow. Let's click on button two in the application preview. You see, its color will change. You'll see all attributes of this Windows Element will load in the right-hand side pane. I've highlighted some properties/attributes (Name, AutomationId), which we can use for automation in the screenshot below.


    appium properties

    The same thing will happen if we click on the calculation results textbox on the top. 

    This is how you can use the Appium desktop client to inspect Windows applications. Other options on this screen aren't much useful. Click on the given line to find out How to Download and Run WinAppDriver UI Recorder.

    Oxygen IDE Support: 


    Please note that you can record automated UI tests using Appium Desktop Inspector to run with Oxygen IDE. You'll need to have proper tools installed for that. This includes Android Studio, which is overhead, but so far, that's the way Oxygen IDE architecture is, and they don't have any plans to remove the dependency anytime soon. You can find more by visiting this link.

    You can now play with the inspector further to see more options. I am going to close it now. In the next video, I'll show you how to use the app arguments desired capability in Appium Desktop Client.

    appArguments Specifying Additional Desired Capabilities in
    Appium Desktop Client


    How to use appArguments AppiumOption/DesiredCapability in Appium? 

    We can specify more additional capabilities using the Appium Desktop Client. These capabilities can have various effects on our tests and are something not available in WinAppDriver UI Recorder. For Example, if we want to open Notepad with a file loaded into it already.

    Let us create a new session. In the app default capability, I'll put "Notepad." Then I'll click the plus sign and add app arguments in the desired skills. In the value field, I'll put the path of the file which we want to open.

    For Example, in my case, C:\Users\Naeem\Desktop\bunch of text.txt. Please note that we won't put double quotes around the path. Final screenshot of our new Appium client custom server to launch Windows 10 Notepad with a file opened inside of it is given below:


    Appium desktop client

    I'll Click the "Start Session" button. You'll see that the file you specified as a parameter will open. 



    The same technique can be used with Microsoft Excel to open a file right out of the gates. 


    Click on the given link to find out "How to Download and Run WinAppDriver UI Recorder."
    It is also possible to open files in Microsoft Excel launched through WinAppDriver using appArguments Appium Option. 
    Specify the desired capabilities in your test automation code will be done through the method call listed below: 

    AppiumOptions.AddAdditionalCapability("appArguments", "c:\textfile.txt");
    AppiumOptions.AddAdditionalCapability("ms:waitForAppLaunch", "50");

    ms:waitForAppLaunch Handling Splash Screen in WinAppDriver


    How to wait for an application splash screen to display? How to use ms:waitForAppLaunch AppiumOption? 

    Some applications show a splash screen when they launch. The splash is mistakenly considered the main application window by the WinAppDriver and this leads to automation failure. 



    Microsoft Outlook



    If you're using WinAppDriver 1.2 RC, you can also make the WinAppDriver wait for a little bit so that the splash goes away, and then the WinAppDriver attaches to the application window. 

    For Example, let's try a demo with Microsoft Outlook(2019), Desktop e-mail client application. 

    Free code sample of Outlook 2019 automation using WinAppDriver can be found in this GitHub repository published by yours indeed. I am going to launch it in a straight forward way first of all. I'll create a new session window, and I'll put Outlook against the "app" in desired capabilities. 

    Now I'll click the "Start Session" button.




    You'll see that the app preview will not load. The progress animation will keep spinning. Let's close the session window and come again. This time, I'm going to add a new Desired Capability. In the name field, I'll put ms:waitForAppLaunch in the value field, I'll put the number 15. 

    Now I'll click the "Start Session" button. 




    This time around, you'll see that the application preview will take a while to load in the Appium Desktop Client. Now you can check all properties of the Windows Elements inside this application too. 



    This is the end of this article, and I hope you found it to be useful. Please feel free to ask questions.

    Do share it in your social circles as well. Please do visit my Udemy course as well, and the link is given AppiumWinAppDriver UI Automation Testing.


    3 comments:

    1. Thanks for according to critical information including all of us. It was surprisingly soft to work. I absolutely like your opinions. I personally relish your work. Your article is very practical and helpful for us.
      click Here

      ReplyDelete
    2. I really liked reading your post! Very high quality content and useful information similar to my post on places to visit to With such a valuable website I believe you deserve to be ranking even higher in the search engines.

      click Here

      ReplyDelete

    Feel free to talk back...