public static bool LoadFromGrid(By Str, IWebDriver driver, int timer, string val) { bool Rtn = false; try { int ct = 0; while (ct <= timer) { if (ObjectIsEnabled(Str, timer, driver)) { IWebElement Tbl = driver.FindElement(Str); string[] vals = val.Split('¦'); Str2 = GetStr(vals[0], vals[1]); if (vals[2] != null && vals[3] != null) { Str3 = GetStr(vals[2], vals[3]); } IList <IWebElement> tableRow = Tbl.FindElements(Str2); IList <IWebElement> rowTD; int colct = 0; foreach (var Col in tableRow) { rowTD = Col.FindElements(Str3); foreach (var col in rowTD) { colct++; if (RunTesting.UpdateStepValues(TestRun.TestStep, colct.ToString(), col.Text)) { log.Info("Grid Data for " + TestRun.TestStep + " : " + colct + " : " + col.Text + " added to dictionary"); } } colct = 0; } return(true); } Thread.Sleep(1); ct++; if (ct > timer) { log.Error("Error selecting from drop down list"); return(false); } } } catch (Exception Exp) { log.Error(Exp); Rtn = false; } return(Rtn); }
public static bool Runstep(string steps) { bool Rtn = true; if (steps == null || steps == "") { return(true); } if (steps.Contains("<<<")) { steps = RunTesting.ResolveVariables(steps); } string[] v = steps.Split(Convert.ToChar(Config.Delim)); TestStep = v[0]; Dep = v[1]; if (RunTesting.Results.ContainsKey(Dep) && RunTesting.Results[Dep] == false) { log.Warn("Test Step '" + TestStep + "' skipped as dependent step '" + Dep + "' failed."); return(false); } Type = v[2]; Page = v[3]; URL = v[4]; Load = v[5]; Reload = v[6]; Elem = v[7]; if (v[9] != null && v[9] != "" && v[8] != null && v[8] != "") { Str = SeleniumActions.GetStr(v[8], v[9]); } Disp = v[10]; Act = v[11]; Val = v[12]; Exp = v[13]; WaitParm = Config.Time; if (v[14] != null && v[14] != "") { Pause = Convert.ToInt32(v[14]); } APIuser = v[15]; APIpass = v[16]; ExpectedResult = v[17]; if (v[0].Substring(0, 1) == "!") { log.Info("Test Step" + " " + v[0].Substring(1) + " : " + v[6] + " skipped!"); return(true); } Rtn = RunTesting.RunStep(TestStep, Dep, Type, Page, URL, Load, Reload, Elem, Str, Disp, Act, Val, Exp, Pause, WaitParm); if (TestStep != "Close") { log.Info(" ***** Running test " + TestStep + " : GUI Page: " + Page + " *****"); OldTest = TestStep; } else { log.Info("**** Test Set completed ****"); } return(Rtn); }
public static bool SelectFromList(By Str, IWebDriver driver, int timer, string val) { bool Rtn = false; try { bool Notselected = false; int ct = 0; string itemText = ""; while (ct <= timer && !Notselected) { if (ObjectIsEnabled(Str, timer, driver)) { IWebElement items = driver.FindElement(Str); string[] vals = val.Split(':'); vals[0] = vals[0].Trim('"'); vals[0] = vals[0].Trim().Trim('"'); vals[2] = vals[2].Trim('"'); vals[2] = vals[2].Trim().Trim('"'); int ItemCt = items.FindElements(By.TagName(vals[0])).Count; if (vals[1] != "Text" && ItemCt < Convert.ToInt32(vals[2]) + 1) { log.Error("selection value " + Convert.ToInt32(vals[2]) + " +1 greater than number in list " + ItemCt); return(false); } foreach (IWebElement item in items.FindElements(By.TagName(vals[0]))) { itemText = item.Text; if (vals[1] == "Value" && ct == Convert.ToInt32(vals[2])) { log.Info(ItemCt + " items in list."); item.Click(); log.Info("Item " + vals[2] + " selected."); Notselected = true; Rtn = true; break; } if (vals[1] == "Text" && item.Text.Contains(vals[2])) { log.Info(ItemCt + " items in list."); item.Click(); log.Info("Item containing '" + vals[2] + "' selected."); Notselected = true; Rtn = true; break; } } } Thread.Sleep(1); ct++; if (ct > timer) { log.Error("Error selecting from drop down list"); return(false); } } RunTesting.UpdateStepValues(TestRun.TestStep, "TextValue", itemText); } catch (Exception Exp) { log.Error(Exp); Rtn = false; } return(Rtn); }
static void Main(string[] args) { Config.DIR = args[0]; Config.Browser = args[1]; Config.Delim = args[2]; Config.Time = Convert.ToInt32(args[3]); Config.GUIurl = args[4]; Config.BaseUrl = args[5]; Config.LogFile = args[6]; //SendKeys.Send("{ESC}"); GlobalContext.Properties["LogName"] = Config.LogFile; ILog log = LogManager.GetLogger(typeof(Program)); log.Info("Initialising........"); var csvFiles = Directory.EnumerateFiles(Config.DIR, "*.csv", SearchOption.AllDirectories); int filect = 0; foreach (string CSV in csvFiles) { filect++; log.Info(filect + ". " + CSV); } foreach (string currentFile in csvFiles) { //RunTesting Testlines = new RunTesting(); log.Info("Processing file : " + currentFile); string[] TestSteps; using (StreamReader sr = new StreamReader(currentFile)) { string TestFile = sr.ReadToEnd(); TestSteps = TestFile.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); } if (Config.Browser != "None") { TestRun.Driver = SeleniumActions.GetDriver(Config.Browser); } RunTesting.Steps(TestSteps, TestRun.Driver); log.Info("Testing Summary for file " + currentFile); log.Info("==============="); int passct = 0; int failct = 0; int totalct = 0; foreach (var item in RunTesting.Results.Keys) { totalct++; if (RunTesting.Results[item] == true) { passct++; } else { failct++; } } log.Info("Total passes = " + passct); log.Info("Total fails = " + failct); log.Info("Total Tests = " + totalct); log.Info("Asta la vista!"); } }