Tuesday 25 April 2017

Produce Functional Test Automation in Visual Studio

Introduction:
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.

Pre-Requites:

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:  



Keywords:
Keyword
Description
Entertext
Used to provide the user values to a text box or an edit box.

+

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

Ex: Clicking a Login button in login page
setpage
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


clicklink
Used to perform a click operation on links or similar controls

Ex: Clicking on a Select link after filtering the respective role
opendropdown
Used to perform an action of opening a drop down item
selectdropdownitem
Used to perform an action of selecting a drop down item
verifydropdownitem
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
openmenu
Used to perform an action on Menu items like Admin, Support etc. for providing more options for consecutive actions
verifylabel
Used to validate the content of a label
waitforprocess
Used to make the script wait for different conditions like : Wait for control ready
validategrid
Used to compare the Grid results in application against to the data retrieved from database

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

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

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

Ex: Setting focus on the button before clicking it
DragAndDrop
Used to perform drag and drop a control(with value as optional) from source location into target container
DoubleClick
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.
Troubleshooting:

  • 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.

2 comments:

  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

    ReplyDelete
  2. I'M NOW FULFILL FINANCIALLY BECAUSE OF THE LOAN I GOT FROM LFDS .I would like to bring this to the notice of the public about how i came in contact with LFDS after i lost my job and being denied loan by my bank and other financial institution due to my credit score. I could not pay my children's fees. I was behind on bills, about to be thrown out of the house due to my inability to pay my rent, It was during this period my kids were taken from me by foster care. Then i set out to seek for funds online where i lost $3,670 that i borrowed from friends which i was rip off by two online loan companies. Until i read about:Le_Meridian Funding Service  (lfdsloans@outlook.com / lfdsloans@lemeridianfds.com) somewhere on the internet, Still wasn't convince because of what i have been through until a relative of mine who is a clergy also told me about the ongoing loan scheme of LFDS at a very low interest rate of 1.9%% and lovely repayment terms without penalty for default of payment. I have no choice than to also contact them which i did through text +1-989-394-3740 and Mr Benjamin responded back to me That day was the I'M best and greatest day of my life which can never be forgotten when i receive a credit alert of $400,000.00 Usd loan amount i applied for. I utilized the loan effectively to pay up my debts and to start up a business and today i and my kids are so happy and fulfill. You can as well contact them through email: (lfdsloans@outlook.com / lfdsloans@lemeridianfds.com)  WhatsApptext  helpline: +1-989-394-3740 Why am i doing this? I am doing this to save as many that are in need of a loan not to be victim of scams on the internet. Thanks and God bless you all, I'm Oleksander Artem from Horizon Park BC , Ukrain.

    ReplyDelete

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 ...