Пример #1
0
 /// <summary>
 /// Close current active window and switch to another window
 /// </summary>
 /// <param name="switchToWindowAssertFunc">Assertion function to find the window</param>
 /// <param name="customPreWait">Custom action wait upon before closing and switching to another window</param>
 /// <param name="customPostWait">Custom action wait upon after closing and switching to another window</param>
 /// <returns></returns>
 public T CloseCurrentAndSwitchToWindow(AssertionFunc switchToWindowAssertFunc, AssertionFunc customPreWait = null, AssertionFunc customPostWait = null)
 {
     return(RunTask(b => {
         b.CloseWindow();
         b.SwitchToWindow(switchToWindowAssertFunc);
     }, customPreWait, customPostWait));
 }
Пример #2
0
 public T EnterDate(string cssSelector, DateTime date, AssertionFunc preWait = null, AssertionFunc postWait = null)
 {
     return(RunTask(browser => {
         var dateInputElement = browser.FindElementsByCssSelector(cssSelector).LocateFirstVisibleElement();
         dateInputElement.EnterDate(date);
     }, preWait, postWait));
 }
Пример #3
0
 /// <summary>
 /// Enters the text into the element specified.
 /// By default waits for the element to exist before entering the text
 /// </summary>
 /// <param name="cssSelector">The css selector of the element</param>
 /// <param name="text">The text to insert</param>
 /// <param name="customPreWait">Custom action wait upon before entering the text in the element</param>
 /// <param name="customPostWait">Custom action wait upon after entering the text in the element</param>
 public T EnterText(string cssSelector, string text, AssertionFunc customPreWait = null, AssertionFunc customPostWait = null)
 {
     return(RunTask(browser => {
         var textInputElement = browser.FindElementsByCssSelector(cssSelector).LocateFirstVisibleElement();
         textInputElement.EnterText(text);
     },
                    customPreWait ?? (a => a.CustomAssertion(b => b.FindElementsByCssSelector(cssSelector).LocateFirstVisibleElement().IsVisible)),
                    customPostWait));
 }
Пример #4
0
        /// <summary>
        /// Selects an element in a dropdown list with specified text
        /// </summary>
        /// <param name="cssSelector">The css selector of the element</param>
        /// <param name="text">The text of the option to select</param>
        /// <param name="customPreWait">Custom action wait upon before selecting the option</param>
        /// <param name="customPostWait">Custom action wait upon after selecting the option</param>
        /// <returns></returns>
        public T SelectList(string cssSelector, string text, AssertionFunc customPreWait = null, AssertionFunc customPostWait = null)
        {
            return(RunTask(browser =>
            {
                Click(cssSelector);

                browser.FindElementsByCssSelector(cssSelector + " option").First(x => x.Text == text).ScrollToElement().Click();
            },
                           customPreWait ?? (a => SelectListPreWait(a, cssSelector, text)),
                           customPostWait));
        }
Пример #5
0
        /// <summary>
        /// Asserts
        /// </summary>
        /// <param name="assertion">The Function with your assertions</param>
        /// <returns></returns>
        public T Assert(AssertionFunc assertion, string message = "")
        {
            WaitUntil(assertion);
            var assertionResult = assertion(new XenonAssertion(_xenonBrowser));

            if (string.IsNullOrEmpty(message))
            {
                message = string.Join("\r\n", assertionResult.FailureMessages);
            }
            _xenonTestOptions.AssertMethod(assertionResult.Passing, message);
            return(this as T);
        }
Пример #6
0
        public IXenonBrowser SwitchToWindow(AssertionFunc assertion)
        {
            foreach (var windowHandle in _driver.WindowHandles)
            {
                var switchedWindowDriver       = _driver.SwitchTo().Window(windowHandle);
                var switchedWindowXenonBrowser = new SeleniumXenonBrowser((RemoteWebDriver)switchedWindowDriver);
                if (assertion(new XenonAssertion(switchedWindowXenonBrowser)).Passing)
                {
                    return(switchedWindowXenonBrowser);
                }
            }

            return(new SeleniumXenonBrowser(_driver));
        }
Пример #7
0
        public XenonAssertion RunAssertion(AssertionFunc assertion)
        {
            XenonAssertion result;

            try
            {
                result = assertion(new XenonAssertion(this));
            }
            catch (StaleElementException exception)
            {
                result = new XenonAssertion(this).BrowserFailure(exception.Message);
            }

            return(result);
        }
Пример #8
0
        private IXenonBrowser SwitchToWindowWithRetries(AssertionFunc assertion, int attemptNumber)
        {
            const int maxTries = 5;

            foreach (var windowHandle in _driver.WindowHandles)
            {
                var switchedWindowDriver       = _driver.SwitchTo().Window(windowHandle);
                var switchedWindowXenonBrowser = new SeleniumXenonBrowser((RemoteWebDriver)switchedWindowDriver);

                if (assertion(new XenonAssertion(switchedWindowXenonBrowser)).Passing)
                {
                    return(switchedWindowXenonBrowser);
                }
            }

            return(attemptNumber > maxTries
                                ? new SeleniumXenonBrowser(_driver)
                                : SwitchToWindowWithRetries(assertion, ++attemptNumber));
        }
Пример #9
0
        private void WaitUntil(AssertionFunc wait)
        {
            var endTime = DateTime.Now.AddSeconds(_xenonTestOptions.WaitForSeconds);

            do
            {
                try
                {
                    if (_xenonBrowser.RunAssertion(wait).Passing)
                    {
                        break;
                    }
                }
                catch (Exception)
                { }

                Thread.Sleep(10);
            } while (DateTime.Now < endTime);
        }
Пример #10
0
        private T RunTask(Action <IXenonBrowser> task, AssertionFunc preWait, AssertionFunc postWait)
        {
            if (preWait != null)
            {
                WaitUntil(preWait);
            }

            try
            {
                task(_xenonBrowser);
            }
            catch (StaleElementException)
            {
                return(RunTask(task, preWait, postWait));
            }

            if (postWait != null)
            {
                WaitUntil(postWait);
            }

            return(this as T);
        }
Пример #11
0
 /// <summary>
 /// Allow you create a custom interaction with browser
 /// </summary>
 /// <param name="task">The custom interaction with the browser</param>
 /// <param name="customPreWait">Custom action wait upon before calling custom interaction</param>
 /// <param name="customPostWait">Custom action wait upon after calling custom interaction</param>
 /// <returns></returns>
 public T Custom(Action <IXenonBrowser> task, AssertionFunc customPreWait = null, AssertionFunc customPostWait = null)
 {
     return(RunTask(task, customPreWait, customPostWait));
 }
Пример #12
0
 /// <summary>
 /// Cancel an active dialog box on the page
 /// </summary>
 /// <param name="customPreWait">Custom action wait upon before cancelling the dialog box</param>
 /// <param name="customPostWait">Custom action wait upon after cancelling the dialog box</param>
 /// <returns></returns>
 public T CancelDialogBox(AssertionFunc customPreWait = null, AssertionFunc customPostWait = null)
 {
     return(RunTask(b => b.CancelDialogBox(), customPreWait ?? (a => a.DialogBoxIsActive()), customPostWait ?? (a => a.DialogBoxIsNotActive())));
 }
Пример #13
0
 /// <summary>
 /// Enter text in an active prompt dialog box on the page
 /// </summary>
 /// <param name="text">text to be entered in the prompt</param>
 /// <param name="customPreWait">Custom action wait upon before entering text in the prompt dialog box</param>
 /// <param name="customPostWait">Custom action wait upon after entering text in the prompt dialog box</param>
 /// <returns></returns>
 public T EnterTextInDialogBox(string text, AssertionFunc customPreWait = null, AssertionFunc customPostWait = null)
 {
     return(RunTask(b => b.EnterTextInDialogBox(text), customPreWait ?? (a => a.DialogBoxIsActive()), customPostWait));
 }
Пример #14
0
 /// <summary>
 /// Switch To another window in the browser
 /// </summary>
 /// <param name="assertion">Assertion function to find the window</param>
 /// <param name="customPreWait">Custom action wait upon before switching to another window</param>
 /// <param name="customPostWait">Custom action wait upon after switching to another window</param>
 /// <returns></returns>
 public T SwitchToWindow(AssertionFunc assertion, AssertionFunc customPreWait = null, AssertionFunc customPostWait = null)
 {
     return(RunTask(b => _xenonBrowser = b.SwitchToWindow(assertion), customPreWait, customPostWait));
 }
Пример #15
0
 /// <summary>
 /// Selects an element in a dropdown list with specified text
 /// </summary>
 /// <param name="cssSelector">The css selector of the element</param>
 /// <param name="text">The text of the option to select</param>
 /// <param name="customPreWait">Custom action wait upon before selecting the option</param>
 /// <param name="customPostWait">Custom action wait upon after selecting the option</param>
 /// <returns></returns>
 public T SelectList(string cssSelector, string text, AssertionFunc customPreWait = null, AssertionFunc customPostWait = null)
 {
     return(RunTask(browser => browser.FindElementsByCssSelector(cssSelector).First().SelectDropdownItem(text),
                    customPreWait ?? (a => SelectListPreWait(a, cssSelector, text)),
                    customPostWait));
 }
Пример #16
0
 public IXenonBrowser SwitchToWindow(AssertionFunc assertion)
 {
     return(SwitchToWindowWithRetries(assertion, 0));
 }
Пример #17
0
 /// <summary>
 /// Goes to the url specified.
 /// </summary>
 /// <param name="url">The url you want to goto, must be absolute</param>
 /// <param name="customPreWait">Custom action wait upon before going to the url</param>
 /// <param name="customPostWait">Custom action wait upon after going to the url</param>
 public T GoToUrl(string url, AssertionFunc customPreWait = null, AssertionFunc customPostWait = null)
 {
     return(RunTask(w => w.GoToUrl(url), customPreWait, customPostWait));
 }
Пример #18
0
 /// <summary>
 /// Right clicks the element specified
 /// By default waits for the element to exist before clicking
 /// </summary>
 /// <param name="cssSelector">The css selector of the element</param>
 /// <param name="customPreWait">Custom action wait upon before clicking to the element</param>
 /// <param name="customPostWait">Custom action wait upon after clicking to the element</param>
 public T RightClick(Func <XenonElementsFinder, XenonElementsFinder> where, AssertionFunc customPreWait = null, AssertionFunc customPostWait = null)
 {
     return(RunTask(browser => where (new XenonElementsFinder(browser)).FindElements().LocateSingleVisibleElement().RightClick(),
                    customPreWait ?? (a => a.CustomAssertion(b => where (new XenonElementsFinder(b)).FindElements().LocateSingleVisibleElement().IsVisible)),
                    customPostWait));
 }
Пример #19
0
 /// <summary>
 /// Right clicks the element specified
 /// By default waits for the element to exist before clicking
 /// </summary>
 /// <param name="cssSelector">The css selector of the element</param>
 /// <param name="customPreWait">Custom action wait upon before clicking to the element</param>
 /// <param name="customPostWait">Custom action wait upon after clicking to the element</param>
 public T RightClick(string cssSelector, AssertionFunc customPreWait = null, AssertionFunc customPostWait = null)
 {
     return(RunTask(browser => browser.FindElementsByCssSelector(cssSelector).LocateFirstVisibleElement().RightClick(),
                    customPreWait ?? (a => a.CustomAssertion(browser => browser.FindElementsByCssSelector(cssSelector).LocateFirstVisibleElement().IsVisible)),
                    customPostWait));
 }
Пример #20
0
 private void AssertThat(AssertionFunc assertion)
 => PerformXenonAction(x => x.Assert(assertion));