/// <summary> /// Get Test data from excel /// </summary> /// <param name="MethodName"></param> /// <param name="TestData"></param> /// <returns></returns> public static string GetTestData(string MethodName, string TestData) { try { List <string> word = new List <string>(); Tuple <string, string> Factor = SplitString(MethodName); if (Factor != null) { String currentCellValue; List <DataRow> rows = dt.Select("TestCaseName = '" + testcasename.Trim().ToLower() + "' AND " + "MethodName = '" + Factor.Item2.Trim().ToLower() + "'").ToList(); foreach (DataRow dr in rows) { currentCellValue = dr[TestData].ToString(); if (currentCellValue.Contains(";")) { word = currentCellValue.Split(';').ToList(); } else { word.Add(currentCellValue); } } return(word[Int32.Parse(Factor.Item1)]); } return(string.Empty); } catch (Exception ex) { ExtentReport.LogTestSteps(RelevantCodes.ExtentReports.LogStatus.Fail, "Check Test Data " + ex.Message); return(string.Empty); } }
/// <summary> /// Driver settings /// </summary> /// <param name="driver"></param> private void driverSettings(ref IWebDriver driver) { try { //driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2)); driver.Manage().Window.Maximize(); driver.Manage().Cookies.DeleteAllCookies(); } catch (Exception e) { ExtentReport.LogTestSteps(RelevantCodes.ExtentReports.LogStatus.Fatal, "Driver Settings Failed" + e.Message); } }
/// <summary> /// initialize browser /// </summary> private void InitBrowser() { try { string browserName = ConfigurationManager.AppSettings["BROWSER"]; string downloadFilePath = ConfigurationManager.AppSettings["FileDownloadPath"]; switch (browserName) { case "Chrome": if (driver == null) { ChromeOptions options = new ChromeOptions(); options.AddArgument("--disable-extensions"); options.AddUserProfilePreference("download.default_directory", downloadFilePath); options.AddUserProfilePreference("disable-popup-blocking", "true"); driver = new ChromeDriver(options); driverSettings(ref driver); Drivers.Add("Chrome", driver); } //For future enhancement //case "Firefox": // if (driver == null) // { // driver = new FirefoxDriver(); // driverSettings(ref driver); // Drivers.Add("Firefox", driver); // } break; } } catch (Exception e) { ExtentReport.LogTestSteps(RelevantCodes.ExtentReports.LogStatus.Fatal, "Initialization of browser failed " + e.Message); } }
/// <summary> /// split string /// </summary> /// <param name="Value"></param> /// <returns></returns> private static Tuple <string, string> SplitString(string Value) { try { List <string> methodname = new List <string>(); string factor; if (Value.Contains(':')) { methodname = Value.Split(':').ToList(); factor = methodname[1]; } else { methodname.Add(Value); factor = "0"; } return(new Tuple <string, string>(factor, methodname[0])); } catch (Exception ex) { ExtentReport.LogTestSteps(RelevantCodes.ExtentReports.LogStatus.Fail, "Check Test Data " + ex.Message); return(new Tuple <string, string>(string.Empty, string.Empty)); } }