Tuesday, 25 April 2017

Produce Functional Test Automation in Visual Studio

This post will provide you a single source for producing your test automation for your Web Application, your UWP Apps and Mobile Apps on Android by just writing 2-3 reusable lines of code. It also provides the capability of executing the tests on different platforms e.g. Windows machine, mobile devices (Windows and Android).

Targeted Audience:
QA team members and DevOps team members who wanted to generate their automated tests for their regression suites and Continuous Integration in their Application life cycle.


For TFS support:

Install Excel Providers on the machines:

Running UWP Tests:
Appium Test Running on real devices and Emulator
Pre Requisites:

Configure the environment variables in your machine:
  • JAVA_HOME: Pointing to the Java SDK folder\bin
  • ANDROID_HOME: Pointing to the Android SDK Folder.
  • Add the following paths in the Path variable: %JAVA_HOME%, %ANDROID_HOME%, %ANDROID_HOME%\tools\, %ANDROID_HOME%\platform-tools\, %JAVA_HOME%\bin\
  • Visual Studio Android Emulator: https://www.visualstudio.com/en-us/features/msft-android-emulator-vs.aspx
  • Hyper V is enabled (only for running test on Emulator)

Developing Automated Tests in Visual Studio:
  1. First download the Develop Automated UI Tests extension from Visual Studio Gallery and install it.
  2. After that go for creating a new Project in Visual Studio and select the Template "Develop UI Test Automation", provide a desired name to project and click on "Ok" button to create the project.
  3. Expends the Solution Explorer, it will show the structure as given below:
  4. It has some sample test included in the project. Expend the TestCases Folder to view the test cases, here the format for test cases is in the form of Excel file. This format is very handy business users to write their scenario which we can later convert into automated tests. Following is a typical structure of test case file, it has predefined list of Keywords, Objects are the user defined names to identify the objects, Value field contains the value to be enter on UI or to be validated on UI and Last IncludedInTestRun field specified if particular test steps need to be executed or not while running the tests:
  1. This framework stores the Objects definition in a resource file associated with the project i.e. Objects.resx file. This file has definition(s) for objects in the test case file given above by having property value of test objects for application under test. E.g. for above Objects following details of objects stored: 

  1. Once we are done with updating the Objects.resx file and creating the Test Case excel file, save the file under Test cases (or under a Subfolder) folder in the solution.
  2. Add a new unit test case class file or update existing unit test case file, create a new test method and copy paste following lines and make changes as illustrated below:


  1. Update App.config file:
    Make sure to update the highlighted keys according to your system:


  1. Update the Key TestCaseFolderFullPath to point to correct path:


  1. Run the tests and view the results, it provides proper results e.g. following output from a failed test case:


Result for a passed test case:  

Used to provide the user values to a text box or an edit box.


It also contains the conditions for Username & password.
Used to perform a click operation on buttons or similar controls.

Ex: Clicking a Login button in login page
Used to set the page when there is change in pages during consecutive navigations. This will ensure for the easy identification of objects for the next action


Navigate to a page


Set the current page with or without title

Used to perform a click operation on links or similar controls

Ex: Clicking on a Select link after filtering the respective role
Used to perform an action of opening a drop down item
Used to perform an action of selecting a drop down item
Used to compare the drop down items for a specific search criteria in application against to the data retrieved from database for the same search criteria

Ex: The Grade options retrieved for a specific School and School Year
Used to perform an action on Menu items like Admin, Support etc. for providing more options for consecutive actions
Used to validate the content of a label
Used to make the script wait for different conditions like : Wait for control ready
Used to compare the Grid results in application against to the data retrieved from database

Ex: Student Contact Information, Student category information
Used to perform click operation on div or similar controls

Ex: Clicking on Section Editor div
Used to dismiss the popup window

Ex: Clicking on “OK” or “Cancel” button
Used to validate the message on popup window                     
Used to validate the existence of any control
Used to set the focus on control before performing any action

Ex: Setting focus on the button before clicking it
Used to perform drag and drop a control(with value as optional) from source location into target container
Used for double-clicking a control

 Tools used for getting the properties used for find objects and running tests:

  1. For UWP app, we have to use Inspect.exe for finding the objects properties. It comes by default on Windows 8 or later and typical location for this is Program Files(x86)\Windows Kit\8.0\bin\ and then type of your system i.e. x64 or x86. 
  2. For Android we can use the UIAutomatorViewer tool, which come bundled with Android SDK, once you setup the Pre requisites, you can access it just by opening up command prompt and typing uiautomatorviewer. 
  3. For normal web based application in Device or on desktop we can use Dev toolbar in browsers (by pressing the F12 key) to find the objects.

  • If getting the error on running test in Chrome then download the latest version of Chrome driver 2.28 from Google's site and copy it to following folder in Appium: \node_modules\appium\node_modules\appium-chromedriver\chromedriver\win
  • UIAutomatorViewer for getting native app's controls. Make sure devices name in Appium and Code are same and devices should have Debugging Mode enabled.

1 comment:

  1. I am getting this error when trying to compile the created project:
    This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Selenium.WebDriver.ChromeDriver.2.36.0\build\Selenium.WebDriver.ChromeDriver.targets. AutomatedTest D:\Workspace\Test\AutomatedTest\AutomatedTest.csproj 313


Emerging Technologies and Next Leap in Software Testing

In my tenure in Software Industry, I have witnessed tremendous transformation in the industry. To name a few… starting waterfall model to ...