CodedUI测试不从CSV输入文件读取数据 [英] CodedUI test does not read data from CSV input file

查看:225
本文介绍了CodedUI测试不从CSV输入文件读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用编码用户界面测试方法映射CSV文件。这很可能是一个愚蠢的问题,但我似乎找不到我的问题的解决方案,至少没有一个工作。我已确保将CSV文件的属性设置为始终复制
我也通过在测试方法上面写下面一行来导入CSV文件。

I am having difficulty mapping a CSV file with the Coded UI test method. This is most likely a stupid question but I cannot seem to find a solution for my problem, at least not one that works. I have made sure to set the property of the CSV file to Copy always. I have also imported the CSV file by writing the following line above the test method.

[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\Data\\login.csv", "login#csv", DataAccessMethod.Sequential), DeploymentItem("login.csv"), TestMethod]

文件名为 login.csv 它位于 Data 文件夹中。

The file name is login.csv and it resides in the Data folder.

测试将编译没有任何问题,但一旦测试执行字段应该从CSV文件接收的输入留空,并且执行中断。我试图使用字符串替换CSV文件中的数据,它的工作原理非常好。我使用导入每个参数的代码片段是:

The test will compile without any problem but once the test executes the fields that should receive input from the CSV file are left empty and the execution is interrupted. I've tried replacing the data from the CSV file by using Strings and it works perfectly fine. The piece of code I am using to import each parameter is:

TestContext.DataRow["Username"].ToString()

此外,CSV文件包含以下行:

Also, the CSV file contains something along the following lines:

Username,Password,Fullname
admin@mail.com,password,Admin

有没有人可以指出我在忘记什么。

Is there anyone who can point what it is I am forgetting.

更新:我确定了问题,看起来像问题只围绕csv文件中的第一列。当我尝试导入任何其他值时,它工作得很好。

Update: I pinpointed the issue, it seems like the issue only revolves around the first column in the csv file. When I try to import any of the other values it works perfectly fine.

推荐答案

一些文本文件以字节顺序标记BOM)。 Coded UI中的CSV读取器不处理BOM,将其视为第一个字段名称的一部分。下面的屏幕截图显示了带有BOM的CSV文件的调试跟踪,以及记事本++中显示的相同文件。 DataRow.ItemArray [...] 值如预期。 DataRow.Table.Columns.ResultsView [...] 显示字段名称,但第一个字段名称包括BOM。

Some text files start with a Byte Order Mark (BOM). The CSV reader within Coded UI does not handle the BOM and treats it as part of the first field name. The screen shot below shows the debug trace of a CSV file with a BOM and that same file shown in Notepad++. The DataRow.ItemArray[...] values are as expected. The DataRow.Table.Columns.ResultsView[...] shows the field names, but the first field name includes the BOM.

这个带有BOM的CSV文件是在Visual Studio中使用解决方案资源管理器=>添加=>新建项目=> C#=>通用=>文本文件创建的。以前,我用Microsoft Excel创建了一个电子表格,并将其另存为CSV文件,该文件没有BOM。我也用Notepad ++创建了文件并保存为CSV,他们没有BOM。看来Visual Studio使用BOM创建文件,但是在编辑CSV文件时,它不会添加BOM。

This CSV file with a BOM was created in Visual Studio using Solution Explorer => Add => New item => C# => General => Text file. Previously I have created a spread sheet with Microsoft Excel and saved it as a CSV file, that file did not have a BOM. I have also created files with Notepad++ and saved as CSV and they did not have a BOM. It appears that Visual Studio creates files with a BOM but when editing CSV files it does not add a BOM.

Visual Studio可以使用正确编码。在第2步 - 创建数据集 rel =nofollow noreferrer>这个Microsoft 页面,它指出下面的文本。 (感谢整体开发者在评论中提供非常相似的细节。):

Visual Studio can create files with the correct encoding. Within "Step 2 - Create a data set" of this Microsoft page it states the text below. (Thanks also to Holistic Developer for providing very similar details in a comment.):



  1. 使用正确的编码保存.csv文件很重要。在文件菜单上,选择高级保存选项并选择Unicode
    (UTF-8无签名) - 代码页65001作为编码。


这篇关于CodedUI测试不从CSV输入文件读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆