【问题标题】:Error CodedUITest1.CodedUITestMethod1 threw exception: System.ArgumentException: Column 'Num1' does not belong to table错误 CodedUITest1.CodedUITestMethod1 抛出异常:System.ArgumentException:列 'Num1' 不属于表
【发布时间】:2015-02-06 04:47:41
【问题描述】:

我正在通过 Coded UI 2012 高级版为计算器编写数据驱动代码。下面是代码,问题是每当我运行测试时都会出现这个错误:

消息:测试方法 Code_MK.CodedUITest1.CodedUITestMethod1 抛出异常: System.ArgumentException:列“Num1”不属于表。

我正在为数据使用一个名为 data.csv 的 csv 文件。我还将文件放在正确的目录中,并将“复制到输出目录”更改为始终复制

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;
    }
}

我无法弄清楚我在这段代码中做错了什么。如果有人可以提供帮助,将不胜感激

TIA

【问题讨论】:

标签: c# coded-ui-tests


【解决方案1】:

问题是当我通过 VS 创建和编辑文件时,它没有读取数据,但是当我进入目录并通过文本编辑器更新文件时,这段代码就像一个魅力。

【讨论】:

    【解决方案2】:

    您需要确保 UIItem5Button 和 UIItem6Button 的 Search Properties 正确设置为 'Name' 属性,以便正确识别值。

    为此,您可以从 UIMap.uitest 文件转到 UIItem5Button 和 UIItem6Button 的“属性” - 将“搜索属性”编辑为“名称”并保存解决方案

    This has greater details

    【讨论】:

      【解决方案3】:
      1. 在 Project 下打开 CSV 文件
      2. 打开“文件”菜单
      3. 点击“高级选择选项”
      4. 选择“西欧 (Windows) 代码页 (1252)”
      5. 点击“确定”。

      这解决了我在 Visual Studio 2010 上的问题。

      (注意:您还应该检查您的 CSV 文件中没有任何空格。)

      【讨论】:

        【解决方案4】:

        我在执行我的数据驱动测试脚本时遇到了同样的错误。我发现我没有为我的 CSV 文件创建数据源。 (我仍在研究如何创建数据源来访问我的 data.csv 文件。)

        目前,作为替代方案,我已将列名更新为 0、1 和 2。0 - Num1、1 - Num2 和 2 -Sum

        【讨论】:

          猜你喜欢
          • 2021-04-20
          • 2021-01-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-05-24
          • 1970-01-01
          相关资源
          最近更新 更多