Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public static void ClearSessionStorage()
        {
            LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name);
            ExecuteScript("sessionStorage.clear()");

            LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name);
        }
Esempio n. 4
0
        public static void ScrollIntoView(By locator)
        {
            LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, locator);

            ExecuteScript("arguments[0].scrollIntoView()", locator);

            LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, locator);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        public void ScrollElementByJs(By locator, int scroll)
        {
            LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name);

            JsExecutor.ScrollElementBy(locator, scroll);

            LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        public static void ScrollBy(int y)
        {
            LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, y);

            ExecuteScript($"window.scrollBy(0, {y})");

            LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, y);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        public static void ClearCookies()
        {
            LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name);

            DriverSingleton.Driver.Manage().Cookies.DeleteAllCookies();

            LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name);
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        public void OpenReportsPage()
        {
            LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name);

            Navigate.ToMiDashboardReports();
            this.miDashboardPage.WaitForMiDashboardLoaded();

            LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name);
        }
Esempio n. 17
0
        public static void Refresh()
        {
            LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name);

            DriverSingleton.Driver.Navigate().Refresh();
            Wait.ForDocumentLoaded();

            LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name);
        }
Esempio n. 18
0
        public void ClearStorage()
        {
            LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name);

            JsExecutor.ClearSessionStorage();
            Wait.FromSeconds(1);

            LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name);
        }
Esempio n. 19
0
        public static void ForRollerOnReportsToGoAway()
        {
            LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name);

            ForDocumentLoaded();
            ForElementToLeave(ReportLocators.Spinner, DriverConsts.FourMinInMilliseconds);

            LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name);
        }
Esempio n. 20
0
        public void Click(By locator, int index = 0)
        {
            LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, locator);

            Wait.StandardWait();

            DriverSingleton.Driver.FindElements(locator)[index].Click();

            LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, locator);
        }
Esempio n. 21
0
        public void Click(IWebElement element)
        {
            LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name);

            Wait.StandardWait();

            element.Click();

            LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name);
        }
Esempio n. 22
0
        public void ClickByJs(By locator, int index = 0, int scroll = -90)
        {
            LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, locator, index);

            JsExecutor.ScrollIntoView(locator);
            JsExecutor.ScrollBy(scroll);
            JsExecutor.Click(locator, index);

            LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, locator, index);
        }
Esempio n. 23
0
        public void MouseOverJs(IWebElement element)
        {
            LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, element);

            Wait.StandardWait();

            JsExecutor.MouseOver(element);

            LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, element);
        }
Esempio n. 24
0
        public static void Until(Func <IWebDriver, bool> condition)
        {
            LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var wait = new WebDriverWait(DriverSingleton.Driver, new TimeSpan(0, 0, DriverConsts.Twenty));

            wait.Until(condition);

            LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name);
        }
Esempio n. 25
0
        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);
        }
Esempio n. 26
0
        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);
        }
Esempio n. 27
0
        public void SendKeysByJs(By locator, string value)
        {
            LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, locator, value);

            Wait.StandardWait();

            JsExecutor.SendKeys(locator, value);
            JsExecutor.CallEventOnElement(locator);

            LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, locator, value);
        }
Esempio n. 28
0
        public static void ForRollersOnWidgetsToGoAway()
        {
            LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name);

            ForDocumentLoaded();
            ForElementToLeave(
                By.CssSelector(@"div[class='spinner--overlay'] div[class='lds-roller']"),
                DriverConsts.ThreeMinInMilliseconds);

            LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name);
        }
Esempio n. 29
0
        public static void ForElement(By locator, int milliseconds = DriverConsts.TwoMinInMilliseconds)
        {
            LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name, locator, milliseconds);

            StandardWait();

            WebDriverWait wait = new WebDriverWait(
                DriverSingleton.Driver,
                TimeSpan.FromMilliseconds(milliseconds));

            wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
            wait.Until(ExpectedConditions.ElementExists(locator));

            LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name, locator, milliseconds);
        }
Esempio n. 30
0
        public static void MouseOver(IWebElement element)
        {
            LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, element);

            ExecuteScript(
                @"
                if (document.createEvent) {
                    var evObj = document.createEvent('MouseEvents');
                    evObj.initEvent('mouseover', true, false);
                    arguments[0].dispatchEvent(evObj);
                } else if (document.createEventObject) {
                    arguments[0].fireEvent('onmouseover');
                }",
                element);

            LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, element);
        }