1

I'm writing a data driven code for a calculator through Coded UI 2012 premium version. Below is the code, the issue is that whenever I run the test I get this error:

Message: Test method Code_MK.CodedUITest1.CodedUITestMethod1 threw exception: System.ArgumentException: Column 'Num1' does not belong to table.

Iam using a csv file for the data, named data.csv. I have also placed the file in the correct directory and changed the 'Copy to Output Directory' to Copy always

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 Microsoft.VisualStudio.TestTools.UITesting.WinControls;
using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;


namespace Code_MK
{
    /// <summary>
    /// Summary description for CodedUITest1
    /// </summary>
    [CodedUITest]
    public class CodedUITest1
    {
        public CodedUITest1()
        {
        }

        [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\data.csv", "data#csv", DataAccessMethod.Sequential), DeploymentItem("data.csv"), TestMethod]
        public void CodedUITestMethod1()
        {
            // 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 http://go.microsoft.com/fwlink/?LinkId=179463
            this.UIMap.LaunchCalc();
            this.UIMap.UICalculatorWindow.UIItemWindow.UIItem5Button.SearchProperties[WinButton.PropertyNames.Name] = TestContext.DataRow["Num1"].ToString();
            this.UIMap.UICalculatorWindow.UIItemWindow2.UIItem6Button.SearchProperties[WinButton.PropertyNames.Name] = TestContext.DataRow["Num2"].ToString();

            this.UIMap.AddNumbers();

            this.UIMap.AssertEqualsExpectedValues.UIItem11TextDisplayText = TestContext.DataRow["Total"].ToString();

            this.UIMap.AssertEquals();
        }

        #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 
        //[TestInitialize()]
        //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 http://go.microsoft.com/fwlink/?LinkId=179463
        //}

        ////Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //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 http://go.microsoft.com/fwlink/?LinkId=179463
        //}

        #endregion

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }
        private TestContext testContextInstance;

        public UIMap UIMap
        {
            get
            {
                if ((this.map == null))
                {
                    this.map = new UIMap();
                }

                return this.map;
            }
        }

        private UIMap map;
    }
}

I couldn't figure out what Iam doing wrong in this code. If anybody could help, it'd be appreciated

TIA

bushra
  • 11
  • 2
  • Please show the CSV file. However I suspect your question is a duplicate of http://stackoverflow.com/questions/24735579/codedui-test-does-not-read-data-from-csv-input-file . Additionally you might like to read http://stackoverflow.com/questions/23469100/how-to-run-a-test-many-times-with-data-read-from-csv-file-data-driving – AdrianHHH Feb 06 '15 at 09:22

4 Answers4

0

I was getting the same error while executing my data driven test script. I found out that I hadn’t created a data source for my CSV file. (I am still working on how to create data source to aces my data.csv file.)

The the time being, as an alternative, I have update my column names with 0, 1 and 2. 0 – Num1, 1 - Num2 and 2 -Sum

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
0

The issue was that when I was creating and editing file through VS, it wasn't reading the data, but when I went to the directory and updated the file through a text editor this code worked like a charm.

bushra
  • 11
  • 2
0

You need to make sure that Search Properties for UIItem5Button and UIItem6Button correctly set to 'Name' Property that it will correctly identify value.

For that you can go to 'Properties' for UIItem5Button and UIItem6Button from UIMap.uitest file - Edit 'Search Properties' to 'Name' & Save Solution

This has greater details

Unnati Shukla
  • 342
  • 3
  • 15
0
  1. Open the CSV file under Project
  2. Open the "File" menu
  3. Click on the "Advanced Select Options"
  4. Select "Western European (Windows) CodePage(1252)"
  5. Click "OK".

This solved the problem for me on Visual Studio 2010.

(Note: You should also check that you don't have any spaces in your CSV file.)

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574