public static void ForElementToLeave(By locator, int milliseconds = DriverConsts.TwoMinInMilliseconds) { LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name, locator, milliseconds); IWebElement element = null; string startTime = DateTime.Now.ToString("yyyyMMdd-HHmmss"); DateTime endTime = DateTime.Now.AddMilliseconds(milliseconds); while (DateTime.Now < endTime) { try { element = DriverSingleton.Driver.FindElement(locator); } catch (NoSuchElementException) { // This is an expected exception return; } } if (element != null) { string endTime2 = DateTime.Now.ToString("yyyyMMdd-HHmmss"); Logger.Log(startTime); Logger.Log(endTime2); throw new Exception($"Element still found! {locator}"); } LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name, locator, milliseconds); }
public static void ClearSessionStorage() { LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name); ExecuteScript("sessionStorage.clear()"); LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name); }
public IWebElement FindElement(By locator, bool elementRequired = true) { LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, locator, elementRequired); Wait.StandardWait(); IWebElement element = null; try { if (elementRequired) { Wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(locator)); } element = DriverSingleton.Driver.FindElement(locator); } catch (Exception) { if (elementRequired) { Console.WriteLine($"Element not found: {locator}"); throw; } } LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, locator, elementRequired); return(element); }
private static object ExecuteScript(string script, By locator, int index = 0) { LoggerSelenium.LogReturn(MethodBase.GetCurrentMethod().Name, script, locator); return(((IJavaScriptExecutor)DriverSingleton.Driver).ExecuteScript( script, DriverSingleton.Driver.FindElements(locator)[index])); }
public static void ClearCookies() { LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name); DriverSingleton.Driver.Manage().Cookies.DeleteAllCookies(); LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name); }
public static void ScrollElementBy(By locator, int y) { LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, locator, y); ExecuteScript($"arguments[0].scrollTop = {y}", locator); LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, locator, y); }
public string GetAttribute(By locator, string attributeName, int index = 0) { LoggerSelenium.LogReturn(MethodBase.GetCurrentMethod().Name, locator, attributeName, index); Wait.StandardWait(); return(DriverSingleton.Driver.FindElements(locator)[index].GetAttribute(attributeName)); }
public string GetCssValue(By locator, string propertyName) { LoggerSelenium.LogReturn(MethodBase.GetCurrentMethod().Name, locator); Wait.StandardWait(); return(DriverSingleton.Driver.FindElement(locator).GetCssValue(propertyName)); }
public bool IsLinkActive(By locator) { LoggerSelenium.LogReturn(MethodBase.GetCurrentMethod().Name, locator); Wait.StandardWait(); return(DriverSingleton.Driver.FindElement(locator).GetCssValue("cursor").Equals("pointer")); }
public string GetValue(By locator) { LoggerSelenium.LogReturn(MethodBase.GetCurrentMethod().Name, locator); Wait.StandardWait(); return(JsExecutor.Value(locator)); }
public void ScrollElementByJs(By locator, int scroll) { LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name); JsExecutor.ScrollElementBy(locator, scroll); LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name); }
public string GetTextByJs(By locator) { LoggerSelenium.LogReturn(MethodBase.GetCurrentMethod().Name, locator); Wait.StandardWait(); return(JsExecutor.InnerText(locator)); }
public ReadOnlyCollection <IWebElement> FindElements(By locator) { LoggerSelenium.LogReturn(MethodBase.GetCurrentMethod().Name, locator); Wait.StandardWait(); return(DriverSingleton.Driver.FindElements(locator)); }
public static void ToUrl(string url) { LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name, url); DriverSingleton.Driver.Navigate().GoToUrl(url); LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name, url); }
public static void ScrollBy(int y) { LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, y); ExecuteScript($"window.scrollBy(0, {y})"); LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, y); }
public static void ToMiDashboardWorkspace() { LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name); DriverSingleton.Driver.Navigate().GoToUrl($"{TestContexts.BaseAddress}/workspace"); LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name); }
public static void Click(By locator, int index = 0) { LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, locator, index); ExecuteScript("arguments[0].click()", locator, index); LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, locator, index); }
public static void SendKeys(By locator, string value) { LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, locator, value); ExecuteScript($"arguments[0].value = '{value}'", locator); LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, locator, value); }
private static void ExecuteScript(string script, IWebElement element) { LoggerSelenium.LogReturn(MethodBase.GetCurrentMethod().Name, script, element); ((IJavaScriptExecutor)DriverSingleton.Driver).ExecuteScript(script, element); LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, script, element); }
public static void ScrollIntoView(By locator) { LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, locator); ExecuteScript("arguments[0].scrollIntoView()", locator); LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, locator); }
public ReadOnlyCollection <IWebElement> FindElementsInReport(By locator) { LoggerSelenium.LogReturn(MethodBase.GetCurrentMethod().Name, locator); Wait.StandardWait(); Wait.ForRollerOnReportsToGoAway(); return(this.FindElements(locator)); }
public static void Clear(By locator) { LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, locator); Wait.StandardWait(); DriverSingleton.Driver.FindElement(locator).Clear(); LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, locator); }
public void SendKeys(By locator, string value) { LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, locator, value); Wait.StandardWait(); DriverSingleton.Driver.FindElement(locator).SendKeys(value); LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, locator, value); }
public static void ForRollerOnReportsToGoAway() { LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name); ForDocumentLoaded(); ForElementToLeave(ReportLocators.Spinner, DriverConsts.FourMinInMilliseconds); LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name); }
public static void ForRollersToGoAway() { LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name); ForDocumentLoaded(); ForElementToLeave(By.CssSelector(@"div[class='lds-roller'] [style='display:block']")); LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name); }
public void OpenReportsPage() { LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name); Navigate.ToMiDashboardReports(); this.miDashboardPage.WaitForMiDashboardLoaded(); LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name); }
public static void Refresh() { LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name); DriverSingleton.Driver.Navigate().Refresh(); Wait.ForDocumentLoaded(); LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name); }
public void ClearStorage() { LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name); JsExecutor.ClearSessionStorage(); Wait.FromSeconds(1); LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name); }
public static void ForDocumentLoaded() { LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name); var wait = SetWaitTime(DriverConsts.ThreeMinInMilliseconds); wait.Until(d => JsExecutor.DocumentComplete()); LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name); }
public static void Until(Func <IWebDriver, IWebElement> condition) { LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name); WebDriverWait wait = new WebDriverWait(DriverSingleton.Driver, TimeSpan.FromSeconds(DriverConsts.Twenty)); wait.Until(condition); LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name); }