What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 1529 |  Welcome, Guest!   Register  Login
Home > Articles > Visual Studio 2010/12 > Data Driven Approach in Coded UI Test

Data Driven Approach in Coded UI Test

Article posted by Dynamicruchi on 3/14/2011 | Views: 15258 | Category: Visual Studio 2010/12 | Level: Beginner | Points: 250 red flag


In my previous articles, we have discussed about Coded UI basics and Object Identification Mechanism in Coded UI .
In this article we will look into Data Driven approach in Coded UI. What dataSources it supports for providing the test data and how to use these datasources while working with CodedUI.


To test the functionality of any application, we test it with different identified sets of data to make sure the functionality does not break while iterating through all these data sets.

Coded UI supports 3 different datasources that can be used for providing the test data.

1.       CSV files

2.       Xml files

3.       Databases

In the following sections we will discuss about CSV files as datasources in detail. We will discuss about XML files and Databases in detail in the next articles.

Steps to perform before configuring the DataSource

Before we start discussing about the datasources we will setup the recording of a scenario of opening the Internet Explorer, type http://www.bing.com/ in address bar, click on enter. Once the Search page gets opened, type ‘Visual Studio 2010’ in the search text boa and click on the search button. The Search results will come up.

I have already used the same example while we discussed about the record and playback in the article Coded UI basics .

Now we will see how we can provide various test data for Search instead of hardcoding ‘Visual Studio 2010’ as the test data. We will use each DataSource one by one for demonstration.

We will follow the following  steps for opening the DataSource selection wizard:

1. Open the Test List Editor and you will find the recorded method ‘CodedUITestMethod1’ present in the editor.

 

 

 

2. Right click on the Test Name ‘CodedUITestMethod1’ and click on the Properties.

 

 

 

3. Select the Data Connection String property from the Property Browser and open it. You will see the ‘New Test DataSource Wizard’ as shown below:
 


Configuring the Different DataSources

CSV Files

1. Select the CSV File as the datasource and click on the ‘Next’ button.

 

   

 

2. Choose the CSV files from the next screen. 

 

 

    

 

You will see the data present in CSV file as below:

 

 

3.       Click on the Finish button to complete the configuration. Clicking on Finish will show a pop up to copy the database file into the current project.

 

 

4. Click on ‘Yes’ button and it will copy the csv file in the current project.

 

   

 

5. Open the CodedUITestMethod1 and notice the attribute on top of the method:

 

 

[

DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\TestData.csv", "TestData#csv",

DataAccessMethod.Sequential), DeploymentItem("SampleCodedUIProject\\TestData.csv"), TestMethod]

public void CodedUITestMethod1()

{

this.UIMap.RecordedMethod1();

}

 

 

The information related to the TestData Source get added on top of the method.
 
6.  Now, modify the CodedUITestMethod1 a bit to parameterize the test using TestContext. Add the following line in the test method:

 

string testData = TestContext.DataRow ["SearchData"].ToString();

this.UIMap.RecordedMethod1(testData);

 

7. As we have changed RecordedMethod1 to take one input parameter ‘testData’, we will change its implementation a bit. Go to the method definition and supply the testData where we were taking the ‘Visual Studio 2010’ as a hardcoded input. See the below highlighted line, we will change this line to take ‘testData’ as the value.


public void RecordedMethod1(string testData)

{

#region

Variable Declarations

HtmlEdit uIEnteryoursearchtermEdit = this.UIExercise3DataDrivenDWindow.UIBingDocument.UIEnteryoursearchtermEdit;

HtmlDiv uIItemPane = this.UIExercise3DataDrivenDWindow.UIBingDocument.UISb_formCustom.UIItemPane;

HtmlInputButton uISearchButton = this.UIExercise3DataDrivenDWindow.UIBingDocument.UISearchButton;

WinButton uICloseButton = this.UIExercise3DataDrivenDWindow.UIVisualstudio2010BingTitleBar.UICloseButton;

#endregion

// Go to web page 'http://www.bing.com/' using new browser instance

this.UIExercise3DataDrivenDWindow.LaunchUrl(new System.Uri(this.RecordedMethod3Params.UIExercise3DataDrivenDWindowUrl));

// Set flag to allow play back to continue if non-essential actions fail. (For example, if a mouse hover action fails.)

Playback.PlaybackSettings.ContinueOnError = true;

// Mouse hover 'Enter your search term' text box at (213, 5)

Mouse.Hover(uIEnteryoursearchtermEdit, new Point(213, 5));

// Reset flag to ensure that play back stops if there is an error.

Playback.PlaybackSettings.ContinueOnError = false;

// Click 'Unknown Name' pane

Mouse.Click(uIItemPane, new Point(151, 34));

// Type 'visual studio 2010' in 'Unknown Name' pane

Keyboard.SendKeys(uIItemPane, this.RecordedMethod3Params.UIItemPaneSendKeys, ModifierKeys.None);

// Type 'visual studio2010' in 'Enter your search term' text box

uIEnteryoursearchtermEdit.Text = testData;

// Click 'Search' button

Mouse.Click(uISearchButton, new Point(21, 20));

// Click 'Close' button

Mouse.Click(uICloseButton, new Point(18, 8));

}



 

8.  Now we are ready to run our test with different testData values as supplied from the CSV file. Run your test case, the test will run as many times the data present in csv file.


See the result of the sample run below. The test run for two iterations as we have provided two values in the CSV file.

 

Conclusion

Coded UI provides 3 different datasources support. Based on the project requirement we can use any of these datasources. In this article we discussed about how to use CSV files as the source of TestData. In next articles we will talk about XML files and Databases in detail.

   

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:4 year(s)
Home page:http://www.dotnetfunda.com
Member since:Wednesday, March 02, 2011
Level:Starter
Status: [Member]
Biography:
 Responses
Posted by: Tripati_tutu | Posted on: 16 Mar 2011 02:37:39 AM | Points: 25

Nice one, but you have placed as an image for codes. It is not clearly visible.

So if its possible, then try to attach your project in this article or place the codes in place of code images, then I think it will helpful for the viewers.

Thanks,

Posted by: Dynamicruchi | Posted on: 19 Mar 2011 02:37:03 AM | Points: 25

Hi Tripati

I have put the code instead of code images. It should be clearly visible now.

Posted by: Tripati_tutu | Posted on: 19 Mar 2011 03:53:46 AM | Points: 25

Thanks for doing this...

Posted by: Smsbvt | Posted on: 19 Jun 2012 11:45:06 AM | Points: 25

Thanks for the post Ruchi. I don't mean any dis-respect, but there seem to be about a dozen web blogs where people are talking about data-driven CodedUI. Most of them show the simple work of attaching to a CSV, XML or dataset from a db, and this is great. I like the way you show the code page with the changes in place and the images of setting up the db connection.

I just have a few problems with the information provided by most of them:

1. The samples uses a data connector, what if the data connection is in the web.config or uses a DAL to collect the data?

2. Most samples show direct modification in a single method within the test methods, why not change the value at the field itself? This way the data is consistent across all the test case code and you do not have to track down every method using the field to make changes.

3. What if the data content for the test sets is different from shall we say navigational data? Example, we have a seperate database that handles our navigational structure, which is where we have to derrive what page to load, and verify that we have arrived at the expected page. Meanwhile, we have another data source where we compare our tests data on the pages, such as the content values from a search post.

4. Which brings up the final question, this method of "Data Driven CodedUI" is great for iterrating through test sets, but What about "Data Driven Methods". This is to say, the code itself from a click through is pretty static. The first thing a QA dev wants to do is to make it more dynamic to reduce redundancy in code, improve effiency and handle dynamic linkages. No one talks about these things. Maybe when a web site loads on one www server and jumps to another based on user navigation events, what about handling these things. No samples out there for this. Although the answer is similar, it would create a new test result if this data was tied to the provided data sources this "Data Driven CodedUI" process would utilize (potentially).

Along with #4 above come other issues to resolve when using data navigation content.

>> Write Response - Respond to this post and get points
Related Posts

Visual Studio 2012 introduced a very helpful feature called Code Clone Analysis, which will search the solution and find out the duplicate code snippets.

VSTS 2010 added lot of new IDE [Integrated Development Environment] features along with the other language or SDLC features. This IDE feature includes features to help in fast development and efficient debugging tools. This article will help you in understanding few of the IDE features introduced in VSTS 2010.

In my previous article on data driven approach in coded UI, we have discussed about how to use the CSV files as the dataSource. In this article we will look into Data Driven approach in Coded UI using XML files for providing the test data and how to use this dataSource while working with CodedUI.

In this article, I am going to share some shortcuts of Visual Studio. Hope this will be helpful.

Performance of an application is very important for a multi-user application. Performance is not only the speed of execution; it includes the load and concurrency aspects. Visual Studio is one of the tools used for Performance Test. Visual Studio Test edition or Visual Studio 2010 Ultimate provides the support for test automation.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 1:04:32 PM