How to run a test multiple times with data read from a CSV file (data transfer)

I am trying to automate some tests for one of our web applications, and I need to know how I can get my encoded user interface project to read data from a CSV file. Suppose I want to check the login screen. My CSV file will contain several usernames and passwords. I want my Coded UI test to read this log data and skip it to run the test on each data set.

+4
source share
3 answers

There are many guides on how to process data from encoded user interfaces on the Internet. The main steps for managing data with a CSV file are as follows.

  • Create a CSV file.
  • Add the CSV file to the project.
  • Make sure the CSV file is deployed.
  • Add the CSV file as a data source for a separate test.
  • Read the CSV fields and use them in the test.

Detailed instructions with some options are described below.

Visual Studio 2010 has a “data source wizard” that performs some of these steps. In versions of Visual Studio 2012 and 2013 there is no wizard, so all steps must be performed manually.

Create CSV File

- , , . - . . (BOM) , CSV, , , . . .

CSV

, . . , , , *.* *.csv.

, CSV

CSV . " " " , " " ". " , ", " ", , . - , , . , , , , .

CSV

[TestMethod] . Microsoft . CSV:

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

, , #, .. Datasource(...), , , CSV.

|DataDirectory| , . , .

CSV

, , . ...Params, assert ...ExpectedValues, ... - . - , . action assertion. TestContext.DataRow[...].

, Coded UI test EnterValue, , CheckResult, . .

[DataSource...
    TestMethod]
public void CodedUITestMethod1()
{
    this.UIMap.EnterValueParams.UIItem0TextSendKeys = TestContext.DataRow["ValueOne"].ToString();
    this.UIMap.EnterValueParams.UIItem1TextSendKeys = TestContext.DataRow["ValueTwo"].ToString();
    this.UIMap.EnterValue();

    this.UIMap.CheckResultExpectedValues.UIItem0TextDisplayText = TestContext.DataRow["Result"].ToString();
    this.UIMap.CheckResult();
}

...Params ...ExpectedValues . , EnterValue , :

this.UIMap.EnterValueParams.UIItem2TextSendKeys = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd");
+7

.

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

, : http://blogs.msdn.com/b/mathew_aniyan/archive/2009/03/17/data-driving-coded-ui-tests.aspx

+3

. [TestMethod] script:

[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\LoginInfo.csv", "Sheet$1", DataAccessMethod.Sequential), DeploymentItem("LoginInfo.csv"), TestMethod]

From there, change the name of LoginInfo.csv to the name of your CSV file. To link to your data simply use:

// Username and Password are Column Headers
UIMap.LoginParams.UserNameTextBox = TestContext.DataRow["UserName"].ToString();
UIMap.LoginParams.PasswordTextBox = TestContext.DataRow["Password"].ToString();
UIMap.Login();

This will take an element in each column and will use it sequentially in each test.

+2
source

Source: https://habr.com/ru/post/1539249/


All Articles