Selenium with C# 63 - Selenium Data Driven Testing using excel in MS Test and EPPlus library

preview_player
Показать описание
Data driven testing using excel EPPlus library
Create a utility method which reads excel file & returns data row by row

What is EPPlus library
EPPlus is a .NET library
Reads and writes Excel files using the Open Office XML format (*.xlsx)

ExcelPackage class
Represents an Excel  XLSX file package. 
This is the top level object  to access all parts of the document.
Has a FileInfo parameterized

ExcelWorksheet class Represents an Excel worksheet and provides access to its properties and methods

Cells Property
ReadOnly property
Returns a cell value when we provide Row and Column parameters

ReadExcel() Method Code:

public static IEnumerable lessthan object[]greaterthan ReadExcel()
{
{
//get the first worksheet in the workbook
                ExcelWorksheet worksheet = package.Workbook.Worksheets["Sheet1"];
                int rowCount = worksheet.Dimension.End.Row;     //get row count
                for (int row = 2; row lessthan= rowCount; row++)
                {
                    yield return new object[] {
                        worksheet.Cells[row, 1].Value?.ToString().Trim(), // First name
                        worksheet.Cells[row, 2].Value?.ToString().Trim(), // Last name
                        worksheet.Cells[row, 3].Value?.ToString().Trim()  // Enrollment date
                    };
                }
            }
        }

Test method code:
[DynamicData(nameof(ReadExcel), DynamicDataSourceType.Method)]
[TestMethod]
public void DataDrivenTestingUsingExcelSheet(string fName, string lName, string eDate)
{
IWebDriver driver = new ChromeDriver();
driver.Manage().Window.Maximize();

driver.FindElement(By.Id("FirstName")).SendKeys(fName);
driver.FindElement(By.Id("LastName")).SendKeys(lName);
driver.FindElement(By.Id("EnrollmentDate")).SendKeys(eDate);

driver.Quit();
}

Possible Interview Questions
How to achieve the data driven testing using excel sheet
What is EPPlus library?
Рекомендации по теме
Комментарии
Автор

Thank you for watching. Cheers! would you mind hitting *_like_* button and *_subscribe_* to our channel!
That will be awesome. We would be grateful to you. And also share this video in your circle via whatsapp, facebook and twitter.

AnkproTraining
Автор

Can you please suggest if the same code will work for NUnit? Or if what modifications are required to support Nunit?

viveknew
Автор

Build Is Succesful, but test case is failed says Object reference not set to an instance of an object.
stackTrace <ReadExcel>d__4.MoveNext() line 82
source)

sachinpawar
Автор

hello, sir, your classes are very helpful. sir at this line, DynamicDataSourceType.Method)]
i am getting this error "dynamic data attribute does not contain a constructor that takes two arguments "

phaniraja
Автор

Could you pls share all the codes, include the past videos pls or if you can share the repository of github or some like that

JavierLavandierTejada
Автор

Can you please create the same with Nunit?

gamehacks
Автор

for (int row = 2; row <= rowCount; row++)
{
for(int col=1; col<=colCount; col++)

{
yield return new object[] {
worksheet.Cells[row, col].Value?.ToString().Trim(), // First name
};

}
}

this is not returning multiple colums, , its returning only 1 column

lakshmanreddy
welcome to shbcf.ru