Site Loader
Auckland, New Zealand
Data Driven Testing is one of the most useful part in any automation testing tool, it can be any testing tool like Selenium, QTP or Test Complete, we do data driven automation testing with it. Data Driven testing in Coded UI Testing is done especially to replace the hard coded value with external data source. The external data source can be either a
  • Excel
  • CSV
  • Data base Table
  • XML etc
All the above data sources are supported in Coded UI testing.

Working with Data Driven Testing

In this post, we are going to use CSV (Comma Separated Value) file as external data source and using TestContext property of Coded UI class to populate data into our code. Hence, we need to perform following steps to make our testing data driven
Creating External Data Source
Adding Data Source Attribute
Using TestContext.Data[] to retrieve the data from external data source and passing it

Creating External Data Source

To Create External data source, first add a new file using New à File Then enter the Data into the CSV file as shown As you can see above, I am creating two columns, first column indicates the operation which we are going to perform, in our case we are going to just add two number and we are going to verify if its output is same as “Result” column.

Adding Data Source Attribute

Next add, the data source attribute for CSV as shown below As you can see above, the data source is CSV and the DataDirectory is \\data.csv, which is nothing but our data.csv file.

Retrieving Data using TestContext.DataRow

We can retrieve the data from data source using the following code As you can see above, I have create a AssertMethod to verify if the Result in actual application is generating the value which we specified in the CSV file

Assertion Code

The assertion code to verify if the value in calculator result for 89 + 23 = 112 is same as CSV   Please watch the full explanation of article as Video to fully understand the concept with in-depth details. Please leave your comments and thanks for reading and watching the article. Thanks, Karthik KK

Post Author: Karthik kk

13 Replies to “Data Driven Testing in Coded UI Test Record and Playback”

  1. Hi,
    nice article!!

    one question:
    how can we do DDT on Windows Phone Coded UI test, i could not find a way, so I developed my own solution to the problem, but I would like to know if there is another way to do this.

    1. Can anybody please tell me how to automate the right click action and get context menu and then select an option in that context menu in c# Visual Studio 2012? I am working with WEBAII framework

  2. Hi Kartik,

    I have downloaded calculator plus (since I have Windows 10) and was able to record and play back.
    Now I am on 6th video (Data Driven Testing in Coded UI Test Record and Playback). My test is failing and after looking into my designer.cs found below under AssertAdd()
    WinEdit uIItemEdit = this.UICalculatorPlusWindow.UIItemWindow2.UIItemEdit;
    but you have in your video as below
    WinText uIItem112Text = this.UICalculatorWindow.UIItemWindow112.UIItem112Text;
    Now, question is why I am having “uIItemEdit” and you have “uIItem112Text”.
    Am I suppose to download any particular Calculator, if your answer yes. Which calculator is that and where do I find.

    public void AssertAdd()
    #region Variable Declarations
    WinEdit uIItemEdit = this.UICalculatorPlusWindow.UIItemWindow2.UIItemEdit;

    // Verify that the ‘Text’ property of text box equals ’90. ‘
    Assert.AreEqual(this.AssertAddExpectedValues.UIItemEditText, uIItemEdit.Text, “Result should be 90, or else Calculation Fails”);


  3. HI Karthik,

    I am facing a problem about test inputs from xml file.Basically i used a method to call xmlfile and node name rather than datasource attribute.When i executed for the first time , inputs are successfully taken into UI. but when i change the inputs,still its taking old inputs.It’s strange.
    Did you ever faced this issue like this.?

    1. Right click the XML file and click properties.

      There is an option where you can select copy if new or always copy in “Copy to output directory” of build action.

      Select any of those save and compile.

      It should work by theory !!!

  4. Hi Karthik,

    How to stop flickering(Blinking) in data driven framework when my csv file has more than one row.



  5. Hi Kartik,
    I am using .csv file . Using “TestContext.DataRow[“ColumnName”].ToString()”,
    I am fetching data. Always it is taking the values in first row. I want to use the values in remaining rows also.
    How can I go to next row or how can i set a particular row is current row. Can I pass row number using 2nd parameter i.e. DataRowVersion.

    ex: TestContext.DataRow[“Columnname”,DataRowVersion version].ToString();
    Awaiting for your reply.

    Thanks in advance.

  6. I need to connect from VS 2015 to an Oracle DB, to find a record with appropriate conditions for each test scenario. All the [Datasource…] examples I found are for Excel files.
    I installed Oracle ODAC and added references Oracle.ManagedDataAccess and Oracle.ManagedDataAccess.EntityFramework to my solution. How do I write my DataSource attribute?

  7. Hi Karthik,

    I want to write result in to CSV file under Result column. Can you please help me how to use TestContext class with method that can write output result under Result column ?

  8. First thank you for making these tutorials.
    In Topic 6: Data Driven testing in Coded UI, I had to enter the absolute path of the csv file in the DataSource attribute. The “|DataDirectory|\\data.csv” param did not work; the test could not find the file.

  9. The video series about code ui is very interesting to me.
    In this video, about 9min you change UIMap method AssertAdd – add parameter expDate. However, as explain it is bad practice.
    What is the right way to pass parameter?

Leave a Reply

Your email address will not be published. Required fields are marked *