I need help reading all the rows from excel sheet as a test data in my selenium test case.
I can read only one row of an excel sheet with the following code.
//set up test for selenium
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*googlechrome", "http://www.google.com/");
selenium.Start();
verificationErrors = new StringBuilder();
}
//Connects me to my excel sheet which is SampleTestData.xls
public void ConnectExcel()
{
excel.Application excelApp = new excel.Application();
excelApp.Visible = true;
string ExcelDataPath = @"C:\SampleTestData.xls";
excel.Workbook excelWorkBook = excelApp.Workbooks.Open(ExcelDataPath, 0, false, 5, "", "", false, excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
excel.Sheets excelSheets = excelWorkBook.Worksheets;
excel.Worksheet DataworkSheet = (excel.Worksheet)excelSheets.get_Item("Sheet1");
System.String Search1 = ((excel.Range)DataworkSheet.get_Range("A1", Type.Missing)).Value2 as string;
}
//selenium code to run the test
public void StartTest()
{
selenium.open("");
selenium.WaitForPageToLoad("100000");
selenium.Type("gbqfif", search1);
selenium.Click("btnG");
selenium.WaitForPageToLoad("100000");
}
This code lets me select only one row that contains value of search1. However, I need to iterate it such a way that it will keep running StartTest() method until all the rows(50) in the excel sheet are entered.
Any help would be appreciated.