Articles On Testing

Wecome to !!!

Articles On Testing

Wecome to !!!

Articles On Testing

Wecome to !!!

Articles On Testing

Wecome to !!!

Articles On Testing

Wecome to !!!

Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Issues in Visual Studio Coded ui Automation Testing

I received a mail from one of my colleagues in the automation testing arena who is using Coded Ui test project of the Visual Studio to automate some features. Below is the mail I recieved, and I shall be replying to the issues specified here itslef, so that the more audience can acquaint themselves with this issues in Coded Ui automation.

Mail :
Hi Viplav,
I am using VSTS2010 for automating a search functionality in my application. I recorded three coded UI test for-

a) Login- CodedUItest
b) Policy Search using some search criteria & then editing a policy selecting from search results- CodedUItest
c) Logout- CodedUItest

Thereafter I called login & logout functions from Search codedUITest.cs

I also have parameterized search criteria values (PolicyNumber, Policystatus etc) from  excel sheet (Used AppConfig for excel data connection).
I have 4 data rows in my input data sheet (to parameterize search criteria at the rum time).
Issue 1- Now what is Currently happening is- That my coded UITest runs , it does login, perform policy search and edit policy & then gets logout for each and every interation i.e for each data row, causing Opening of multiple browser instances.

My expectation :
            What I want to implement is just one login & one logout. So that- 
            a)users logins
            b)Perform search for all iterations, edit policy
            c)Go back to main page, Repeat steps a-c for all iterations
            d) then log out

Comments : A very geniuinely valid point raised by you Mahesh. Would definitely provide resolution to the same.

Issue2-  The second issue happening with all the iterations is that even after my script has executed for all data rows,It keeps on running and opening browser instances taking parametrized values as blank.
My expectation :
            Ideally it should stops once test is executed for all data rows, When it found no search criteria that is empty cells it should stop running.
            Here i need help, If we can implement some End of Row (EOR) in scripts, As soon as scripts finds EOR it should stop execution.
Comments : Would definitely provide its resolution.

Issue 3-
This issue is related to issue 3, as multiple browser instances are opening. I need some way to close them as soon as test completes for all iterations, better if they get closed after every iteration. I know we can use KILL IE function but I have to give control back to the interface where from I have invoked the scripts that is opened in IE browser. If I apply Kill IE function after all iterations are done, Interface brwoser gets closed as well.

Need you support in all this issues. Please guide.
I really appreciate any help in this regard.


Hi Mahendra,

I would be giving resolution to these three issues in the below comment chain one at a time. Do stay posted.

- Viplav Anand

The better approach is available here to address the business scenario handling :

Code Customization In VSTS CodedUi Testing

How to do custom clicking in any particular checkbox in a web table based on specific field value within the one row in the complete table.

Before explaining or walking through the solution statement, I would prefer to explain to you the business scenario we often come across in our day to day automation testing experience during the course of functional testing automation.

Problem Statement:
We have a Table and within table a certain number of rows having certain number of columns. Suppose 5 rows and 3 columns. The first column has an html control in it of type Checkbox, Second column is having a particular field name, suppose product name in it and the third column is having the quantity of the item that has to be purchased. We have to check that particular row’s checkbox which has a particular product name in its product name column field.

Solution Approach:
We can break the problem statement into Five solution components –
1.  Fetch the row count in that particular table.
2.  Figure out the relation between the control id of the checkbox on the row number within the table.
3.  Fetch the row number in the table that has the corresponding Product name in the second column.
4.  Get the control id of the corresponding Checkbox generated based on Step 2 relationship establishment
5.  Set the checked status of the checkbox to True.

Before going through the codes below don ot forget to add the required objects by the below method by using the Add objects to the Ui Control map feature of the UITest Recording menu.

public void CodedUITestMethodCustomization()
// To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.

#region Variable Declaration
HtmlControl uiTable = this.UIMap.HierarchyWindow.HierarchyFrame.HierarchyTable;
HtmlCell uiTablecell = this.UIMap.HierarchyWindow.HierarchyFrame. HierarchyTable.uiTableCell;
string strProdTobDel= "Groceries";
string str1;
HtmlCheckBox chkbox = this.UIMap.HierarchyWindow.HierarchyFrame.uiTableCell CheckBox;
// To convert str1 into integer and then increment by one for checkbox recognition as inthis application the checkbox number is one more than the product control id‘s number
int intstr1;
string strCheckBoxId;

#region  Get the rowcounts of the table
string RowCount = uiTable.GetProperty(HtmlTable.PropertyNames.RowCount).ToString();

#region Search for the Row and store in str1 having the Product to be deleted
uiTableCell.SearchProperties[HtmlCell.PropertyNames.InnerText] = strProdTobDel;
str1 = uiTableCell.GetProperty(HtmlCell.PropertyNames.RowIndex).ToString();

#region Click Corresponding Checkbox To The User That Is Fetched From Datasheet
// Increment str by one due to bad coding discipline and resulting mismatch in column and row increments
intstr1 = Convert.ToInt16(str1);
intstr1 = intstr1 + 1;
strCheckBoxId = "ctl00_ContentMain_grdCreateCustRepoUsersModerator_ctl0" + intstr1 + "_chkUser";
strCheckBoxId.SearchProperties[HtmlCell.PropertyNames.Id] = strCheckBoxId;
strCheckBoxId.Checked = true;


For more on Automation Testing using CodedUitesting in VSTS :Log On To
Automation Testing Using Coded Ui Testing In VSTS

Why VSTS For Automation Testing

Automation Testing ?
There has been a fast pace growth in the market capitalization of the VSTS tool for various Testing requirements at the various. It Service as well as Product based organisation. It has been not just the ability to market its products well by the Microsoft on this occasion but also the high quality packaged product that has been in the shipping container named as VSTS 2010 i:e Visual Studio 2010.

People for long in the IT industry has been using several stand alone tools for activities related to software development. In the fast paced environment that IT industry projects today, VSTS has definitely been an intelligent product and also the most competitive one.

Looking into the tools abilities we can keep exploring it for long long timelines, but some features that have made it a unique one is the Testing management at a   single platform that has been offered  in its integrated environment that brings all the various teams of Industrial development activities at one place and always in synch.

Primarily a current day Software Development comprises of three teams, namely Requirement Team, Development Team, and the Quality Assurance Team. In the old scenario we had all these three teams in a geographically separated environment as well as there was no tool to keep them in synch. This is the right tool that has been able to bring all of them together and the Dashboard feature provides the complete status automatically with various Project related metrics getting reflected.

Earlier versions of Visual studio had lots of features and we were definitely on the expectation that something had to be incorporated with the Testing features coming up in future releases. This is definitely  a well laid out feature with both the Manual as well as Automation Testing having been uniquely cared for on this occasion, VSTS will be able to bring all the three stakeholder groups on a synchronized platform of TFS with VSTS IDE being the client environment. 

Regarding the cost effectiveness we have just $25 tool in for the complete products requirement management to its development as well as testing on a single platform. We run no more the synch issues of multiple teams due to the TFS availability. We  no more need separate bunch of tools  such as QTP, QC, Excel to manage just the testing requirements. Now its all availed at just throwaway price of $25, and I guess you know what QTP, QC  is charged at. Automation Testing had never been that cheap!

Though we have shortcoming such as Add Ons unavailability but with slowly market getting acclimatized to this new low price tool, we are always going to benefit as business would flourish at the optimized cost now. So happy testing !!!

We can keep talking of the various integrated features but the best process is to explore the tool using its most advanced version The VSTS Ultimate.

Write Text Log For Coded Ui Testing in VSTS

How to : Write Text Log For Coded Ui Testing in VSTS

Test Logs are nothing but Results during the Test script run:

Suppose we have a specific scenario of logging into an application ( SignInGlobal in the below discussed case ). In general if we have a successfull Log In we need to maintain a log report that the Scenario has been executed successfully and that the functionality is working fine within the application. Contrarily speaking, in case the scenario/functionality is not working as per the expectation we need the same to be maintained in the log file, so that we can figure out from the Log files after the complete run as to which particular module has failed :

The definition of the below two function calls are available in the UIMap.cs partial class file :

1. SignInGlobal
2. WriteLogs : It is taking two parameters One being the TestC ontext and the other the status message as Failure/Pass.

                this.UIMap.WriteLogs(TestContext, "Logging Into Aplication Event Success");
            catch (PlaybackFailureException e)
                this.UIMap.WriteLogs(TestContext, "Logging Into Aplication Event Failure");

In UiMap.cs Partial class file keep the below function body defined :

 public void WriteLogs(TestContext varTestcontext, string Status)
            string strAppPath = varTestcontext.DataRow["AppPath"].ToString();
            FileInfo f = new FileInfo(strAppPath + "Results.txt");
            StreamWriter w = f.AppendText();
            w.WriteLine("Module : " + Status + " TimeStamp : " + DateTime.Now.ToString());

So this particular function namely WriteLogs will append the current status message in the same file .

This is how we can successfully maintain a Log file for the series of events that are happening during the course of script run.

TestContext in a CodedUi Testing

What is a Testcontext in a Codedui testing ?

When we record a scenario using the codedui testing methodology in the process of automating any particular scenario, a hierarchy gets generated. The hierarchy is nothing but a reflection of the mechanism that can be employed in order to associate a set of features with the particular class file. Normally, when we click on the project in the solution explorer, we get the option of add new test, which by default is a codedui test, a recording pop up comes up, clicking on the red button on the same starts up the scenario recording. But when recording starts how is that things get organised within the particular codedui test class file ?

It is all very complex to decipher out on the first go, but slowly as one matures with all this things become much more clear, as stuffs are very logically organised and inter related.

Every class file has the instantiation of a TestContext paramter with it. To be more useful, we can use some layman terms to understand the same term, as nothing more than the present context. Present context refers to the class file's associated set of methods and other features, more commonly used being, a data sheet file that we extensibly use very often.

This very logic can be very easily understood by the fact that when we attach a file such as a csv file, it si the TestContext.datarow method is brought into use to refer to the contents of the specific file.

Remove Property in Coded Ui Testing

Normally when we go ahead with recording the scenario of logging into the gmail account, we navigate to the user login page from their to the User specific page with the controls being displayed from the automation testing perspective in some way or the other dependent on the logged in user details, such as the user pane containing the username type of account et al.

When we record the login scenario and validate the logged in user details, we generate a code suppose for the below code its like :

Validate User logged in details :

public void ValidateUesrDetails()
            #region Variable Declarations
            HtmlDiv uIGuserPane = this.UIGmailEmailfromGoogleWindow.UIMainFrame.UIHttpsmailgooglecommaDocument.UIGuserPane;

            // Verify that 'guser' pane's property 'InnerText' contains ''
            StringAssert.Contains(uIGuserPane.InnerText, this.ValidateUesrDetailsExpectedValues.UIGuserPaneInnerText);

            // Verify that 'guser' pane's property 'InnerText' contains 'Sign out'
            StringAssert.Contains(uIGuserPane.InnerText, this.ValidateUesrDetailsExpectedValues.UIGuserPaneInnerText1);

Now when we go through the properties of the associated set of control in our case being UIGuserPane , we find so many  search properties based on which the QTAgent of VSTS recognizes that very control in the screen. However these set of search properties have some expected values, which was as per the record time data in the AUT[application under test].

SO when we use the concept of Data Driven testing in order to replicate the flow for various types of users having different set of the properties associated with them, in that case the recorded set of script might fail just because the search properties as per expectation has been hardcoded for the Record time environment.

This is wherein comes the Remove property feature by which we can just remove the or rather modify the search criterion for such data bind controls which are bound as per the logged in username.

#region Properties
        public HtmlDiv UIGuserPane
                if ((this.mUIGuserPane == null))
                    this.mUIGuserPane = new HtmlDiv(this);
                    #region Search Criteria
                    this.mUIGuserPane.SearchProperties[HtmlDiv.PropertyNames.Id] = "guser";
                    this.mUIGuserPane.SearchProperties[HtmlDiv.PropertyNames.Name] = null;
                    this.mUIGuserPane.FilterProperties[HtmlDiv.PropertyNames.InnerText] = " | Settings | Help | S";
                    this.mUIGuserPane.FilterProperties[HtmlDiv.PropertyNames.Title] = null;
                    this.mUIGuserPane.FilterProperties[HtmlDiv.PropertyNames.Class] = "a8";
                    this.mUIGuserPane.FilterProperties[HtmlDiv.PropertyNames.ControlDefinition] = "class=a8 id=guser";
                    this.mUIGuserPane.FilterProperties[HtmlDiv.PropertyNames.TagInstance] = "25";
                    this.mUIGuserPane.WindowTitles.Add("Gmail - Inbox (1294) -");
                    this.mUIGuserPane.WindowTitles.Add("Gmail - Inbox (1295) -");
                return this.mUIGuserPane;

This is how we can go across the above scenario and validate the requirement to suite the cause of Data Driven testing.  The code modification will be always done in the test class file, prior to the relevant method call.
Now modifying the container class properties :
// Declare the container variable as an html control as described in the uImap.designer.cs file

HtmlDiv uIGuserPane = this.UIMap.UIGmailEmailfromGoogleWindow.UIMainFrame.UIHttpsmailgooglecommaDocument.UIGuserPane;

            HtmlDiv uIGuserPane = this.UIMap.UIGmailEmailfromGoogleWindow.UIMainFrame.UIHttpsmailgooglecommaDocument.UIGuserPane;
            this.UIMap.SignIntoGmailGlobal(TestContext );

By this block of code what we have done above is modified the container classs properties.
When I say container class properties, it is nothing but the container that contains the specific controls, such as in this very case is the User pane which has in it the username attached. In VSTS automation , what we do is that since we have the container class property associated with the content directly, we need to modify the properties of the container as per the degree of data independence that needs to be brought for our usage.

For example suppose Viplav15 user has logged into his gmail account, so from automation perspective the pane or the html control that has the user specific details in it, as well might be dynamically generated with the container properties  as per the user name or things like that, we need to make that independent of the specific user, by using the remove properties of the tags as is described above.

VSTS Testing Resources

 Defining Your Testing Effort Using Test Plans

 Creating Manual Test Cases

 VS 2010 Testing Capabilities (Videos):

Recording and Playing Back Manual Tests

Testing the User Interface with Automated UI Tests (Coded UI Test)

How to: Create a Coded UI Test  (Documentation):

What's new in the Visual Studio 2010 Web performance and load test documentation

Exploratory testing with Visual Studio Test Pro

Debugging With Intellitrace and Test impact analysis

Please feel free to contact us for any further assistance or clarifications, we will be more than happy to assist you.

Exception handling in codedUi Testing

Exception Handling in Coded Ui Testing is one of the most powerful of the innumerable tools available within the VSTS Functional Automation framework. VSTS testing involves the record and play approach with the assertion points playing a major role in validating the various scenarios as and when they arise.
Going by the simplest assertions of all is the string Assert.contains assertion point which we bring to an immense use . The very relevance of this very assertion can be understood from the genuine scenario of logging into the application as discussed in some of my previous topics with Coded Ui Testing. Logging into the gmail application, however aany tester can validate and verify the authentication by checking whether the signed in user name is displayed as was used during the logging in process.
For example suppose Viplav15 has logged into the gmail website, we generally put an assertion point validating the display of viplav15 in the top right hand side of the gmail application.  In all functionl automation testing Validation is a must , we use different naming conventions in the various tools language such as checkpoint in QTP and an assertion point in VSTS.
We will use string assert.contains verification point / assertion point to validate that the logged in user is as per the expectation.
But now just do one thing.
Log out from the application and then login with a new userid.
DO you get surprised as to why I ask you to do this?
I know you would. But I would just say you would figure out one of the most indispensable of the many features of VSTS CodedUi testing getting exposed with perfect ease though I struggled to get it under my knowledge belt in short time period.
Now we have a new user logged into the application :
The new user is not viplav15 may be its some xyz..
And what do you think you need to validate this time ?
And you have to validate that the new user is not “viplav15”.
I do not ask you to validate that the user logged in is xyz or whosoever it be may be your girlfriend or boy..
What my expectation is you need to validate that the upper right panel does not contain viplav15 anymore.
Do you think VSTS CodedUi Testing has anything of the sort of String assert.doesnotcontain ?
Sorry to say but it does not contain any such assertion point . So how is it we can get this scenario covered ?
In fact if you are not a quality tester , you might just not understand the reason why I have been stressing so much on the not presence of some particular controls.
This is the place wherein we can bring some of the best of coding practices in place and may be remove some of the shortcomings that we might have been concluding to be present in the VSTS tool itself.
Do you think this has any solution ?
Even I used to think the same but today have a very genuine solution to it and in fact a lot more of such related issues which I used to think to be  a shortcoming within the tool.
Playback.error exception
Assertionfailed exception.
Put the complete assertion function call within the try block.
Try {
This.contextwriteline(Test case passed)
  Catch(exception playback.Assertionfailed )
This.contextwriteline(Test case failed)

The above code will be useful for the string assert.contains validation.
For the negative scenario validation :
Try {
This.contextwriteline(Test case failed)
  Catch(exception playback.Assertionfailed )
This.contextwriteline(Test case passed)
We will take this in detail with an example in the next content. Till then keep exploring the VSTS Functional automation tool offering bets automation at lowest cost.

Multiple UiTest Files in VSTS CodedUi Testing

How to create Multiple UiTset files in a  CodedUi Test Project?

 The logically inter related blocks of modules within a System Under Test can be automated in a modularized  block of code, in the following outlined manner. for our case we will just have a look at how we have create three different Uitest files. 

The first UiTest file is AllLink.uitest file, which is actually a xml file, and its two components are namely , AllLink.cs and AllLink.designer.cs file. The designer file is non editable file which incorporates all the recorded set of scripts in it. The AllLink.cs file is again a partial class file which is used for more of data overriding and code globalisation along with reusability.

The second UiTest file is UsrIntrfc.uitest file, which is actually a xml file, and its two components are namely ,  UsrIntrfc.cs and  UsrIntrfc.designer.cs file. The designer file is non editable file which incorporates all the recorded set of scripts in it. The  UsrIntrfc.cs file is again a partial class file which is used for more of data overriding and code globalisation along with reusability.

The third  UiTest file is MsgValidatn.uitest file, which is actually a xml file, and its two components are namely ,  MsgValidatn.cs and  MsgValidatn.designer.cs file. The designer file is non editable file which incorporates all the recorded set of scripts in it. The  MsgValidatn.cs file is again a partial class file which is used for more of data overriding and code globalisation along with reusability.

The approach for recording the various functions outlined as under has thus been classified into three specific categories, namely clicking the links, doing the functional event, and finally validating the final event of functionality being successful.

The AllLink uitest file is actually an xml file having the events related to clicking the links, similarly UsrIntrfc is the functional event, MsgValdtn is the validation checkpoint also called the assertion point in VSTS as termed in QTP automation.

At last we have  one class file wherein , we will bring into use all three events from three uitest files and create a standard framework for automating with minimal rework effort.
Just have a look at the snapshot below to gain insights into how we arrange the multiple uitst files :

As outlined in the code below, we create an instance of all three uitest files, and utilize the features available as per the record time in them.

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows.Input;
using System.Windows.Forms;
using System.Drawing;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UITest.Extension;
using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
using multipleuimaps.Uimaps.AllLinkClasses;
using multipleuimaps.UIAssertions.UsrIntrfcClasses;
using multipleuimaps.MsgValdtn.MsgValdtnClasses;

namespace multipleuimaps.Uimaps.AllLinkClasses

    /// Summary description for CodedUITest1
    public class UploadValidation
        public UploadValidation()

        public void UploadValidationTestMethod1()
            // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
            // For more information on generated code, see



        #region Additional test attributes

        // You can use the following additional attributes as you write your tests:

        ////Use TestInitialize to run code before running each test
        //public void MyTestInitialize()
        //    // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
        //    // For more information on generated code, see

        ////Use TestCleanup to run code after each test has run
        //public void MyTestCleanup()
        //    // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
        //    // For more information on generated code, see



        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        public TestContext TestContext
                return testContextInstance;
                testContextInstance = value;
        private TestContext testContextInstance;

        // References made to each of the three uitest files :
        // AllLnk
        // UsrIntrfc

        public multipleuimaps.MsgValdtn.MsgValdtnClasses.MsgValdtn MsgValdtn
                if ((this.map2 == null))
                    this.map2 = new multipleuimaps.MsgValdtn.MsgValdtnClasses.MsgValdtn();

                return this.map2;

        private multipleuimaps.MsgValdtn.MsgValdtnClasses.MsgValdtn map2;

       public AllLink AllLink
                if ((this.map1 == null))
                    this.map1 = new AllLink();

                return this.map1;

        private AllLink map1;

        public UsrIntrfc UsrIntrfc
                if (( == null))
           = new UsrIntrfc();


        private UsrIntrfc map;