0

I have a csv file. All I have to do is to read the csv file and display an assert if the condition is met.

My values are - TLevel,0.2; Mtr, 1; Rmt, TRUE; K, 0

I have to read this csv file and create an assert if " Rmt is False,TLevel is > 0.5 and Mtr =1 " then make the test pass. Otherwise it should make the test fail. Any help is appreciated. I'm new to coded UI and haven't used C#.

I have already created data binding to read the csv file.

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

public void displayTTL()
{
    string a = TestContext.DataRow["value"].ToString();
    string Controls = TestContext.DataRow["Con"].ToString();
    System.Console.WriteLine("The value of "
        +this.TestContext.DataRow["Con"]
        + " is " + a);
    Assert.AreEqual(1, this.TestContext.DataRow["value"]);

This only displays the last line from my csv file in the test output. I would like to assert every single line of my csv file. Every single row has a different assert condition. My csv file has

Con,Value MTL1,1 TTL1.L, 0.5
AdrianHHH
  • 13,492
  • 16
  • 50
  • 87
  • Possible duplicate of [How to run a test many times with data read from .csv file (data driving)](http://stackoverflow.com/questions/23469100/how-to-run-a-test-many-times-with-data-read-from-csv-file-data-driving) – AdrianHHH Apr 03 '17 at 08:05
  • @AdrainHHH, Thanks for the response. In my case I'm not looking for a data driven test. Moreover, the CUIT did not record the controls of my sheet, because the sheet had drawings in it. So based on some research I created a csv file , and would like to display value of row 3(for example), and assert that if this value is present, then make the test pass. I'm looking for a way to display the value in coded UI. Thanks! – user7806789 Apr 04 '17 at 03:52
  • 1
    You are using the `[DataSource...]` attribute, that is for data driven tests. You do not *"display an assert"*, you assert that a condition holds. If it does not hold then the test fails. The rest of your question is not at all clear. What values are you testing, where are they located, what have you tried so far. I think you need to learn about data driven testing, or possibly about C# and Coded UI in general. – AdrianHHH Apr 04 '17 at 08:10
  • If you are trying to quote my name then please spell it correctly, otherwise I will not be notified of your response. – AdrianHHH Apr 04 '17 at 08:11
  • @AdrianHHH, the below is what I have done so far to display the values from csv file. – user7806789 Apr 04 '17 at 23:02
  • public void displayTTL() { string a = TestContext.DataRow["value"].ToString(); string Controls = TestContext.DataRow["Con"].ToString(); System.Console.WriteLine("The value of " +this.TestContext.DataRow["Con"] + " is " + a); Assert.AreEqual(1, this.TestContext.DataRow["value"]); This only displays the last line from my csv file in the test output. I would like to assert every single line of my csv file. Every single row has a different assert condition. My csv file has Con,Value MTL1,1 TTL1, 0.5 MTR, False – user7806789 Apr 04 '17 at 23:12
  • @AdrianHHH, the csv file format didn't appear correctly when I sent it. Sending the csv file again. Con,Value MTL1,1 TTL1.L, 0.5 Thanks! – user7806789 Apr 04 '17 at 23:15
  • Please do not put lumps of unformatted code and data in comments. Please [edit] the question (use the link below the question) and add the code there where it can be nicely formatted by you. Also add the CSV data. This time I have added the code for you. ------- Analysis: I do not know what you are trying to do! You use the `[DataSource...]` attribute which is for a data driven test, but you want to do something else. Please describe in great detail (in the question, not a comment) what you are trying to do and what you are having problems achieving. – AdrianHHH Apr 05 '17 at 08:28

1 Answers1

0

As Adrian says, it's completely unclear:

  • What you're trying to do
  • Why you're using CodedUI

If you're trying to just look at text files in a CSV, you should NOT be using CodedUI. CodedUI is for interacting with controls in a web browser or a windows application and testing them. From what I'm reading here, you shouldn't be using CodedUI at all.

CodedUI is built on something called MSTest. MSTest allows you to use C# assert that concepts are either true or not. You can test a great many things as long as they can be expressed in C#.

Your CSV file doesn't make any sense right now. A CSV file has rows with different columns separated by commas. Many have headers showing what each column represents as the first row.

Please consider taking a pluralsight course in C# or really any programming at all. If I'm being honest, your knowledge level right now is below what's necessary to even ask a question, much less get any meaningful help.

Ryanman
  • 880
  • 1
  • 8
  • 20