我正在通过Coded UI 2012高级版为计算器编写数据驱动代码。下面是代码,问题是每当我运行测试时我都会收到此错误:
消息:测试方法Code_MK.CodedUITest1.CodedUITestMethod1抛出异常: System.ArgumentException:Column' Num1'不属于桌子。
我使用csv文件作为数据,名为data.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
答案 0 :(得分:0)
我在执行数据驱动的测试脚本时遇到了同样的错误。我发现我没有为我的CSV文件创建数据源。 (我仍在研究如何创建数据源以使用我的data.csv文件。)
目前,作为替代方案,我用0,1和2更新我的列名.0 - Num1,1 - Num2和2 -Sum
答案 1 :(得分:0)
问题在于,当我通过VS创建和编辑文件时,它并没有读取数据,但是当我进入目录并通过文本编辑器更新文件时,这段代码就像一个魅力。 / p>
答案 2 :(得分:0)
您需要确保UIItem5Button和UIItem6Button的搜索属性正确设置为&#39; Name&#39;它将正确识别价值的属性。
为此,您可以访问“物业”。来自UIMap.uitest文件的UIItem5Button和UIItem6Button - 编辑&#39;搜索属性&#39;到&#39;姓名&#39; &安培;保存解决方案
答案 3 :(得分:0)
这解决了我在Visual Studio 2010上的问题。
(注意:您还应检查CSV文件中是否有空格。)