Unable to generate a loop that every userid
finishes the test passing to the next userid
via the Excel.
PropertiesCollections.driver.FindElement(By.LinkText("Sales Panel")).Click();
ExcelLib.PopulateInCollection(@"C:\Users\Numg\Desktop\da\Copy_of_webusers.xlsx");
PropertiesCollections.driver.FindElement(By.Id("web_user_user_id")).SendKeys(ExcelLib.ReadData(2, "Id"));
PropertiesCollections.driver.FindElement(By.LinkText("Ok")).Click();
Thread.Sleep(5000);
}
Thread.Sleep(4000);
PropertiesCollections.driver.FindElement(By.Id("4")).Click();
Thread.Sleep(4000);
var option = PropertiesCollections.driver.FindElement(By.Id("aggrupations_653_shares"));
var SelectElement = new SelectElement(option);
Thread.Sleep(4000);
SelectElement.SelectByValue("3");
Thread.Sleep(4000);
PropertiesCollections.driver.FindElement(By.CssSelector("#bet-group > #send > i.fa.fa-arrow-right")).Click();
Thread.Sleep(4000);
PropertiesCollections.driver.FindElement(By.Id("code")).SendKeys("testQA");
Thread.Sleep(4000);
PropertiesCollections.driver.FindElement(By.CssSelector("#new_reduction > input[name=\"commit\"]")).Click();
Thread.Sleep(4000);
PropertiesCollections.driver.FindElement(By.LinkText("Clear")).Click();
}
This is the class for Excel
class ExcelLib
{
private static DataTable ExcelToDataTable(string fileName)
{
//open file and returns as Stream
FileStream stream = File.Open(fileName, FileMode.Open, FileAccess.Read);
//Createopenxmlreader via ExcelReaderFactory
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); //.xlsx
//Set the First Row as Column Name
excelReader.IsFirstRowAsColumnNames = true;
//Return as DataSet
DataSet result = excelReader.AsDataSet();
//Get all the Tables
DataTableCollection table = result.Tables;
//Store it in DataTable
DataTable resultTable = table["Sheet1"];
//return
return resultTable;
}
static List<Datacollection> dataCol = new List<Datacollection>();
public static void PopulateInCollection(string fileName)
{
DataTable table = ExcelToDataTable(fileName);
//Iterate through the rows and columns of the Table
for (int row = 1; row <= table.Rows.Count; row++)
{
for (int col = 0; col < table.Columns.Count; col++)
{
Datacollection dtTable = new Datacollection()
{
rowNumber = row,
colName = table.Columns[col].ColumnName,
colValue = table.Rows[row - 1][col].ToString()
};
//Add all the details for each row
dataCol.Add(dtTable);
}
}
}
public static string ReadData(int rowNumber, string columnName)
{
try
{
//Retriving Data using LINQ to reduce much of iterations
string data = (from colData in dataCol
where colData.colName == columnName && colData.rowNumber == rowNumber
select colData.colValue).SingleOrDefault();
//var datas = dataCol.Where(x => x.colName == columnName && x.rowNumber == rowNumber).SingleOrDefault().colValue;
return data.ToString();
}
catch (Exception e)
{
return null;
}
}