Пример #1
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);
        }
Пример #2
0
        public static void ClearSessionStorage()
        {
            LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name);
            ExecuteScript("sessionStorage.clear()");

            LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name);
        }
Пример #3
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);
        }
Пример #4
0
        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]));
        }
Пример #5
0
        public static void ClearCookies()
        {
            LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name);

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

            LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name);
        }
Пример #6
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);
        }
Пример #7
0
        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));
        }
Пример #8
0
        public string GetCssValue(By locator, string propertyName)
        {
            LoggerSelenium.LogReturn(MethodBase.GetCurrentMethod().Name, locator);

            Wait.StandardWait();

            return(DriverSingleton.Driver.FindElement(locator).GetCssValue(propertyName));
        }
Пример #9
0
        public bool IsLinkActive(By locator)
        {
            LoggerSelenium.LogReturn(MethodBase.GetCurrentMethod().Name, locator);

            Wait.StandardWait();

            return(DriverSingleton.Driver.FindElement(locator).GetCssValue("cursor").Equals("pointer"));
        }
Пример #10
0
        public string GetValue(By locator)
        {
            LoggerSelenium.LogReturn(MethodBase.GetCurrentMethod().Name, locator);

            Wait.StandardWait();

            return(JsExecutor.Value(locator));
        }
Пример #11
0
        public void ScrollElementByJs(By locator, int scroll)
        {
            LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name);

            JsExecutor.ScrollElementBy(locator, scroll);

            LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name);
        }
Пример #12
0
        public string GetTextByJs(By locator)
        {
            LoggerSelenium.LogReturn(MethodBase.GetCurrentMethod().Name, locator);

            Wait.StandardWait();

            return(JsExecutor.InnerText(locator));
        }
Пример #13
0
        public ReadOnlyCollection <IWebElement> FindElements(By locator)
        {
            LoggerSelenium.LogReturn(MethodBase.GetCurrentMethod().Name, locator);

            Wait.StandardWait();

            return(DriverSingleton.Driver.FindElements(locator));
        }
Пример #14
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);
        }
Пример #15
0
        public static void ScrollBy(int y)
        {
            LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, y);

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

            LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, y);
        }
Пример #16
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);
        }
Пример #17
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);
        }
Пример #18
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);
        }
Пример #19
0
        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);
        }
Пример #20
0
        public static void ScrollIntoView(By locator)
        {
            LoggerSelenium.LogStart(MethodBase.GetCurrentMethod().Name, locator);

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

            LoggerSelenium.LogEnd(MethodBase.GetCurrentMethod().Name, locator);
        }
Пример #21
0
        public ReadOnlyCollection <IWebElement> FindElementsInReport(By locator)
        {
            LoggerSelenium.LogReturn(MethodBase.GetCurrentMethod().Name, locator);

            Wait.StandardWait();
            Wait.ForRollerOnReportsToGoAway();

            return(this.FindElements(locator));
        }
Пример #22
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);
        }
Пример #23
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);
        }
Пример #24
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);
        }
Пример #25
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);
        }
Пример #26
0
        public void OpenReportsPage()
        {
            LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name);

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

            LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name);
        }
Пример #27
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);
        }
Пример #28
0
        public void ClearStorage()
        {
            LoggerSelenium.LogStart(System.Reflection.MethodBase.GetCurrentMethod().Name);

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

            LoggerSelenium.LogEnd(System.Reflection.MethodBase.GetCurrentMethod().Name);
        }
Пример #29
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);
        }
Пример #30
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);
        }