For long this has been a debatable issue as to how we can unleash the data driving functionality in the Automation Testing that needs to be done in the Visual Studio tool using its Test project feature. We utilize the Coded Ui Test approach for functional automation testing to achieve the same. With initial hiccups always going to ramp down the confidence one can repose in a tool, I am sure that with experience and devoted mindset the same can be overcome and the great quality this tool has in it can be leveraged with slight knowledge of the usage of the hierarchy available therein.

We already have gone through the tool basics on how it does object recognition and how it undergoes the test effort automatically , but when it comes to take the data drving approach we might just encounter some hiccups as has been outlined by some of my colleagues in the IT industry with tons of mail shooting into my inbox on their inability to do the data driving for the test projects. The error they complain or more clinically speaking the shortcoming the tool has in it is that when we need to data drive the test file wherein separate Coded ui Class file has separate number of iterations to be undergone, the Coded Ui Test approach does not meet the expectation of the automation gurus in the IT sector !

How good that holds is for all of us to take a call on but as a matter of fact the approach that we try to adopt in data driving our test files need to be addressed first and that might just provide a necessary resolution of the problems that we encounter.

As has been provided at the below link [ Mahe's mail ]http://www.articlesontesting.com/2011/07/issues-in-visual-studio-coded-ui.html the issue is simple . The Test project created by the user has in it three Coded Ui Test files addressing three different business scenarios, and the business requirement that needs to be addressed is that the three different coded ui Test files need to iterate different number of times. The below description is definitely going to clear the cloud on this.

Three business scenarios are as under :

1.One being the Login Scenario

2.Second being the business requiremenmt such as doing some search event/transaction.

3.Third being the Log Out Scenario.

The traditional approach we have been following is have a single data file with all data in it. The same can be adopted with this set of scenarios as well, but it definitely will involve some degree of coding and technical skills which we can avoid by transforming our approach to test the same.

Have one data sheet file in csv format for the Login Scenario.

Have one data sheet file in csv format for the search event.

Third scenario is definitely not dependent on data set up.

But one general issue that would be pondered upon is how to run all the three in unison .

This has a solution in the following approach . Just add an ordered test file by using the following link.

And then call them in the order the business requirement is. First Login Coded ui test file, then Search Coded uI test file and then finally log out Coded Ui test file.

The business runs smooth and also the effort and expertise you need to implement the same is very less .

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-

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.

Regards,
Mahendra.

Hi Mahendra,

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

What is an Ordered Test ?When do we use an Ordered Test ?How do we utilize Ordered Test feature of Test Projects in VSTS ?

Let us first look into the following slides as to how do we add an Ordered test in a Test Project in VSTS .

This last screenshot is the Solution Explorer View of the Test Project we have created comprising of two CodedUi Class files and one Ordered Test file.

Our aim now restricts to just the execution of this very ordered test file as all the methods present in the Class files of the CodedUi class files have been integrated within this very ordered test file.

Its this way that we can give an overnight execution of the scripts and hope the site remains up and the script logs all the execution states in a separate log file which I have discussed a couple of post back linked Here.

How to add objects in the uimap.uitest that is the CodedUi Control map file ?
Do you actually know how the automation testing proceeds in a tool. It is very simple, we store the object's properties in some repository files and as and when we need to do some operation on those objects we identify those objects using some logical names that we might choose on our own and then call specific events such as click events to do the required operation.

For example we might have a sign out link available in the website and our sole aim is to click the sign out link.

The way we can proceed is two:
1. It is simple record and playback approach and parameterise any data that has been making the sign out link dependent on the logged in user.
2. Just add the respective object in the repository file in coded ui testing it is the uimap file. Then call the mouse.click event on that particular object that is sign out object.

Now suppose the added object is sign out link we will be having below outlined methodology.
Declare the object with its particular hierarchy order and then call mouse.click event.

The above method signifies the syntax associated with the Mouse.click event.
The first parameter it takes is an object as has been declared in a line above and the second paramater it takes is a sort of syntax that needs to be cared for , do remain informed that the co-ordinates are no way deciding the object recognition, so it is immaterial whetehre we keep co-ordinates as 0,0 or some other as 56,67.

In the below screenshots, I have outlined some of the process to be followed to get the particular object added into the Uimap file that is the object repository file of the CodeduiTest project.

In the below sequence we will add an object using uitest control of the recording window.

Planning to add the tag of the blog : "Automation Testing On Share" into the uitest control map file .
So what I have just done is drag the cross hair which we use for inserting assertion points onto the psecific object by highlighting it as is shown below .

Now just open up the closed arrow sequence to get the object hierarchy established and understood by us and also find the options of adding the object into the Test Project's specific control map file.We can see the Add object button which we need to click and the object that has been in ticked status will be hence added to our control map file.

We can then find the message at the bottom that the object has been added successfully into the uimap file.

So guys whatever we have done till now has been in the IDE's buffer only, we need to store it into the uimap file and hence need to generate code for the object's addition into the uimap file for all our future access of the objects and perform relevant operations on the same. Hence we are needed to click Generate Code button.

The code is being generated now.

Okay so this is how we have learnt to add objects onto our object repository in the VSTS CodedUi Test Project automation tetsing.
I know this might just seem to be a bit complex in intial phase but once you can catch onto what has been outlined above, the usage can be really awesome and the code rework that we generally do in our automation script run during the regression suite execution can be made very easy.

A $25 tool has so much in offering I never could have thought of but the way this tool's utilisation has been encashed upon by us in our team, I think the day is not far off , when the VSTS Test Projects might just be the most sought after automation tool in the industry .

For more on Automation Testing using CodedUitesting in VSTS :Log On To

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

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.

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.

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.

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 :

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.

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

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.

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 : gmail.com

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 ?

No!!!

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.

Uitestcontrolnotfoundexception.

Playback.error exception

Assertionfailed exception.

Put the complete assertion function call within the try block.

Try {

Assertion_Fun1()

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 {

Assertion_Fun1()

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.

User interfaces frequently change during development. Here are some ways to reduce the effect of these changes:

Find the recorded method which references this control and use the Coded UI Test Builder to re-record the actions for this method. You can use the same name for the method to overwrite the existing actions. Do keep track that you record no multiple flows under single function module. Because that will bring lot of dependency of one module on other. For example you might be having the scenario of logging into Gmail and then clicking on the MyContacts link. One record action should be under one function module that is Login and the other event that is navigating to the MyContact link by clicking it.
As a result of which what we shall be able to acheive is that even if tomorrow the Management decides to alter the MyContact link into some new name as MyRelatives , our script being specifically modularised into separate function name as in our case now is we can record just the Click event on the one control that is the new link for MyContacts that is MyRelatives. What comes out is that our script gets very modularised. And maintenance effort is minimised.

If a control has an assertion that is no longer valid:

Delete the method that contains the assertion.

Remove the call to this method from the test method.

Add a new assertion by dragging the cross-hair button onto the UI control, open the UI map, and add the new assertion.

But this logic works successfully only in the case wherein we have just one assertion condition and this very function name can be hence re recorded and validated for our code maintenance ease.

UiMap.cs File In Coded Ui Testing In VSTSWhat is : UiMap.cs file is a partial class file in the Coded UI Testing approach used in the VSTS.

The general perception that a Automation Testing concept involves is the possibility of incorporating a framework approach on the top of any automation tool. This very class file which is a partial class file can be used to serve the same purpose in VSTS Automation Testing.

This is the one single place wherein we can build the utility functions that can be used across the application by the Automation Test Class files : which are none other than the Coded UI Class files. Also from here we can even override the properties of the objects available in the application as per the recorded scripts. At times we even refer the UIMap.cs files as the extensions for the uimap.designer.cs files. The only difference between the two being the Former one is editable while the latter is not editable at all. The latter one's editable fetaure is availed by overriding the objects porperties.

Partial class files are in genuine a file which has some reusable code blocks that act as a continuance to some other class files. In our case it is the designer file that is the class file and the uimap.cs file is the continuance to it. Generally some very raw features such as a link click or a URL load, or some other sceraios where in the Robustness of a Uimap.Cs partial class file can be brought to use is when we have multiple types of users who can log into an application and it is the role based authorization that is provided after having been authenticated to be a valid user in the application, we bring this very partial class to an optimum use.

We may record a scenario for the features of an application wherein the access to various sub - features may be on the basis of roles provided , so by the usage of some Switch case from within the partial class files, we can attain the flexibility of code once reuse everywhere.

A small code to simulate the behavior is shown for reference to illustrate the usage of the UImap.cs partial class file:

By this block of code what we can do is call the login function with Two parameters, one being the Testcontext and the other one being the Role. depending on the role the specific authorized user can log inot the application. We have genuinely considered some eight sets of users, however any programmar can guess that it remains a valid intelligence to use it as per our requirements.