How to Run a Test Many Times with Data Read from .CSV File (Data Driving)

Why run three row if the csv store tow data row?

Its your CVS file, its got extra line or CR at the end, use notepad to delete all empty space and line after the last character of 2nd line. Also remember to delete and reload the file in Data Driven

Is there a way to query a csv file in Karate?

There's no need. Karate can transform a CSV file into a JSON array in one line:

* def data = read('data.csv')

After that just use JsonPath or a "filter" operation to "query" for data (search the docs for more examples):

* def found = data.find(x => x['TC-ID'] === 'TC-1')
* def results = data.filter(x => x.FNAME.startsWith('A'))

Karate Skip test cases read from CSV in a Scenario Outline

Let's say you have three rows and you just want to run one. You can read the csv and then filter it using JsonPath filters. The following code will run only testcase "tc02".

Sample Code:

Feature: CSV Filter

Background:
* def data = read('testdata.csv')
* def data = get data[?(@.testcase=='tc02')]

Scenario Outline: <testcase>,<desc>
* def look = "<testcase>,<desc>"
* print look

Examples:
| data |

# testdata.csv
# testcase,desc
# tc01,desc01
# tc02,desc02
# tc03,desc03

Input from CSV file to a text field in Web C# without using UIMap/Recorded code

Add in a data source to your test method.
add in the csv file to your solution. Right click folder /solution, add existing item, select the file, change the properties of the file 'Copy to Output Directory' to 'copy always'

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

BrowserWindow browser = BrowserWindow.Launch("www.google.com");
UITestControl UISearch = new UITestControl(browser);
UISearch.TechnologyName = "Web";
UISearch.SearchProperties.Add("ControlType", "Edit");
UISearch.SearchProperties.Add("Id", "lst-ib");
//search by column1
Keyboard.SendKeys(UISearch, TestContext.DataRow["column1"].ToString());

}


Related Topics



Leave a reply



Submit