public RunLog ParseAction(Steps step) { //Wait(1000); RunLog log = new RunLog(); switch(step.Keyword) { case "group": log.Pass = true; break; case "url": log = Url(step.Value); break; case "click": log = ClickAndWait(step.Element); break; case "doubleclick": log = DoubleClick(step.Element); break; case "type": log = Type(step.Element, step.Value); break; case "select": log = Select(step.Element, step.Value); break; case "wait": log = Wait(Convert.ToInt32(step.Value)); break; case "switchtopopup": log = Popup(step.Element); break; case "switchtomainwindow": log = MainWindow(); break; case "submit": log = Submit(step.Element); break; default: break; } return log; }
private RunLog Popup(string element) { RunLog thislog = new RunLog(); try { IWebElement thisElement = WaitForElementToAppear(driver, 10, By.XPath(element)); PopupWindowFinder finder = new PopupWindowFinder(driver); string popupWindowHandle = finder.Click(thisElement); driver.SwitchTo().Window(popupWindowHandle); thislog.Pass = true; thislog.Message = "Popup"; } catch(Exception ex) { thislog.Pass = false; thislog.Message = ex.Message; } return thislog; }
public RunLog Select(string element, string value) { RunLog thislog = new RunLog(); try { IWebElement wait = WaitForElementToAppear(driver, 10, By.XPath(element)); new SelectElement(wait).SelectByText(value); thislog.Message = "Select Box found and selected"; thislog.Pass = true; } catch(Exception ex) { thislog.Message = "Element" + element + "\n" +ex.Message; thislog.Pass = false; } return thislog; }
private RunLog Type(string element, string text) { RunLog thislog = new RunLog(); try { IWebElement wait = WaitForElementToAppear(driver, 10, By.XPath(element)); wait.SendKeys(text); thislog.Message = "Element found and typed " + text + "."; thislog.Pass = true; } catch(Exception ex) { thislog.Message = "Element" + element + "\n" + ex.Message; thislog.Pass = false; } return thislog; }
private RunLog Url(string url) { RunLog thislog = new RunLog(); try { driver.Navigate().GoToUrl(url); thislog.Message = "Redirection to " + url + " completed"; thislog.Pass = true; } catch(Exception ex) { thislog.Message = ex.Message; thislog.Pass = false; } //WebDriverWait waitForLoad = new WebDriverWait(driver, 10); return thislog; }
private RunLog DoubleClick(string element) { RunLog thislog = new RunLog(); try { IWebElement wait = WaitForElementToAppear(driver, 10, By.XPath(element)); new Actions(driver).DoubleClick(wait).Perform(); thislog.Message = "Element " + element + " has been found"; thislog.Pass = true; } catch (Exception ex) { thislog.Message = "Element" + element + "\n" + ex.Message; thislog.Pass = false; } return thislog; }
private RunLog ClickAndWait(string element) { RunLog thislog = new RunLog(); try { IWebElement wait = WaitForElementToAppear(driver, 10, By.XPath(element)); IWebElement newwait = WaitForElementToBeVisible(driver, 10, By.XPath(element)); if (newwait.Displayed) { thislog.Message = "Element " + element + " has been found"; thislog.Pass = true; } else { thislog.Message = "Element " + element + " why not selected?!?!"; thislog.Pass = true; } newwait.Click(); } catch(Exception ex) { thislog.Message = ex.Message + "stuff"; thislog.Pass = false; } return thislog; }
private RunLog Submit(string element) { RunLog thislog = new RunLog(); try { IWebElement newwait = WaitForElementToBeVisible(driver, 10, By.XPath(element)); thislog.Message = "Element " + element + " has been found"; thislog.Pass = true; newwait.Submit(); } catch (Exception ex) { thislog.Message = ex.Message + "stuff"; thislog.Pass = false; } return thislog; }
private RunLog Wait(int time) { RunLog thislog = new RunLog(); Thread.Sleep(time); thislog.Pass = true; return thislog; }
private RunLog MainWindow() { RunLog thislog = new RunLog(); if (driver.CurrentWindowHandle != baseWindow) { driver.SwitchTo().Window(baseWindow); thislog.Pass = true; } return thislog; }