public static ArrayList GetExcelQueryData(string testCase) { //create datatable object DataTable dt = new DataTable(); var fileName = @"C:\Users\Christopher\source\repos\SeleniumHybridTestFramework\SeleniumHybridTestFramework\Data\TestData.xlsx"; //Open the Excel file using ClosedXML. using (XLWorkbook workBook = new XLWorkbook(fileName)) { //Read the first Sheet from Excel file. IXLWorksheet workSheet = workBook.Worksheet(1); //Loop through the Worksheet rows. bool firstRow = true; foreach (IXLRow row in workSheet.Rows()) { //Use the first row to add columns to DataTable. if (firstRow) { foreach (IXLCell cell in row.Cells()) { dt.Columns.Add(cell.Value.ToString()); } firstRow = false; } else { //Add rows to DataTable if the testcase id matches IXLCell TestCaseIDCell = row.Cell("1"); if (TestCaseIDCell.Value.ToString() == testCase) { dt.Rows.Add(); int i = 0; foreach (IXLCell cell in row.Cells()) { dt.Rows[dt.Rows.Count - 1][i] = cell.Value.ToString(); i++; } } } } } ArrayList keywordDataList = new ArrayList(); foreach (DataRow row in dt.Rows) { KeywordData kd = new KeywordData(); kd.TestCaseID = row["TestCaseID"].ToString(); kd.Keyword = row["Keyword"].ToString(); kd.Object = row["Object"].ToString(); kd.ObjectType = row["ObjectType"].ToString(); kd.Value = row["Value"].ToString(); keywordDataList.Add(kd); } return(keywordDataList); }
public static void PerformStep(KeywordData data, SeleniumDriver selenDriver, Reports report) { string desc = data.Keyword + " " + data.Object; try { performAction(data, selenDriver); report.addLine(desc, "PASS", ""); } catch (Exception ex) { report.addLine(desc, "Fail", ex.Message); } }
public static void performAction(KeywordData data, SeleniumDriver selenDriver) { switch(data.Keyword.ToUpper()) { case "GOTOURL": selenDriver.Navigate(data.Value); break; case "CLICK": selenDriver.Click(data.Object, data.ObjectType); break; case "SETTEXT": selenDriver.SetText(data.Object, data.ObjectType, data.Value); break; case "GETTEXT": selenDriver.GetText(data.Object, data.ObjectType); break; case "ASSERTELEMENTVISIBLE": selenDriver.AssertElementIsVisible(data.Object, data.ObjectType); break; case "ASSERTELEMENTNOTVISIBLE": selenDriver.AssertElementNotVisible(data.Object, data.ObjectType); break; case "ASSERTELEMENTTEXTCONTAINS": selenDriver.AssertElementTextContains(data.Object, data.ObjectType, data.Value); break; case "ASSERTELEMENTHASCLASS": selenDriver.AssertElementHasClass(data.Object, data.ObjectType, data.Value); break; case "REFRESH": selenDriver.ClickRefresh(); break; case "WAIT": selenDriver.ImplicitWait(int.Parse(data.Value)); break; default: break; } selenDriver.ImplicitWait(10); }