【发布时间】: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
【问题讨论】:
-
请出示 CSV 文件。但是我怀疑您的问题与 stackoverflow.com/questions/24735579/… 重复。此外,您可能想阅读stackoverflow.com/questions/23469100/…
标签: c# coded-ui-tests