Selenium with C# 64 - Selenium Data Driven Testing using CSV file in MS Test | DataSource attribute

Опубликовано: 14 Февраль 2026
на канале: Ankpro Training
7,015
50

Selenium Data Driven Testing using CSV file in MS Test

0:50 What is a CSV file
1:21 What is datasource attribute
2:00 What is TestContext class
3:00 Code demo - CSV file creation
4:06 Code demo - Creation of test method
6:05 Adding TestContext property
7:45 Test method execution
8:57 Possible interview questions on data driven testing using csv file

#selenium #webdriver #qa #tester #datadriventesting

Data driven testing using csv file

What is a CSV file?
1. Comma Separated Values (CSV)
2. It is a plain file text file that contains a list of data
3. A CSV file has a fairly simple structure
4. It’s a list of data separated by commas



Possible Interview Questions
1. How to achieve the data driven testing using csv file
2. What is DataSource attribute
3. What is TestContext class
4. What is DataRow property


Code :

[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV","|DataDirectory|\\data.csv", "data#csv", DataAccessMethod.Sequential)]
[TestMethod]
public void DataDrivenTestingUsingCSVFile()
{
IWebDriver driver = new ChromeDriver();
driver.Manage().Window.Maximize();
driver.Url = "http://uitestpractice.com/Students/Cr...";

driver.FindElement(By.Id("FirstName")).SendKeys(TestContext.DataRow[0].ToString());
driver.FindElement(By.Id("LastName")).SendKeys(TestContext.DataRow[1].ToString());
driver.FindElement(By.Id("EnrollmentDate")).SendKeys(TestContext.DataRow[2].ToString());
driver.FindElement(By.XPath("//input[@type='submit']")).Click();

Thread.Sleep(2000);
driver.Quit();
}