protected async Task GoToNextStepAsync()
        {
            await _session.InvokeOnElementAsync(NextButton, x => x.Click());

            await _session.WaitForInteractiveReadyStateAsync();

            await _session.InvokeAsync(x => Thread.Sleep(500));
        }
Пример #2
0
        public static Task WaitForAsync(this IBrowserSession session, Func <RemoteWebDriver, bool> condition)
        {
            return(session.InvokeAsync(driver =>
            {
                var wait = new WebDriverWait(_systemClock, driver, DefaultTimeout, TimeSpan.FromMilliseconds(100));

                wait.Until(_ => condition(driver));
            }));
        }
Пример #3
0
        public static Task WaitForInteractiveReadyStateAsync(this IBrowserSession session)
        {
            return(session.InvokeAsync(driver =>
            {
                var wait = new WebDriverWait(_systemClock, driver, DefaultTimeout, TimeSpan.FromMilliseconds(100));

                wait.Until(_ => (bool?)driver.ExecuteScript("return (document.readyState === 'interactive' || document.readyState === 'complete') && window.jQuery && window.jQuery.active === 0") == true);
            }));
        }
Пример #4
0
        public static async Task InvokeOnElementAsync(this IBrowserSession session, By by, Action <IWebElement> handler)
        {
            await WaitForElementToAppearAsync(session, by, 1);

            await session.InvokeAsync(driver =>
            {
                var element = driver.FindElements(by).Single(x => x.IsDisplayed());

                handler(element);
            });
        }
Пример #5
0
        public Task LoginAsync(string username, string password)
        {
            return(ExecuteWithRetry(async() =>
            {
                if (await _session.InvokeAsync(x => x.FindElements(BookingDetailsContainerDiv).Count > 0))
                {
                    // Already logged in
                    return;
                }

                await _session.InvokeOnElementAsync(UsernameText, x => x.SendKeys(username));
                await _session.InvokeOnElementAsync(PasswordText, x => x.SendKeys(password));
                await _session.InvokeOnElementAsync(SubmitButton, x => x.Click());

                await _session.WaitForElementToAppearAsync(BookingDetailsContainerDiv);
            }));
        }
Пример #6
0
        public Task LoginAsync(string bookingNumber, string bookingPassword)
        {
            return(ExecuteWithRetry(async() =>
            {
                if (await _session.InvokeAsync(x => x.FindElements(CancelBookingButton).Count > 0))
                {
                    // Already logged in
                    return;
                }

                await _session.InvokeOnElementAsync(BookingNumberText, x => x.SendKeys(bookingNumber));
                await _session.InvokeOnElementAsync(BookingPasswordText, x => x.SendKeys(bookingPassword));
                await _session.InvokeOnElementAsync(SubmitButton, x => x.Click());

                await _session.WaitForElementToAppearAsync(CancelBookingButton);
            }));
        }
        protected async Task <(string BookingNumber, string BookingPassword, decimal TotalPrice)> ReadBookingDetailsAsync()
        {
            string  bookingNumber   = null;
            string  bookingPassword = null;
            decimal totalPrice      = 0;

            await _session.InvokeOnElementAsync(BookingNumberDiv, x => bookingNumber = x.Text);

            await _session.InvokeOnElementAsync(BookingPasswordDiv, x => bookingPassword = x.Text);

            await _session.InvokeAsync(driver =>
            {
                var element = driver.FindElements(TotalPriceSpans).First();

                totalPrice = decimal.Parse(element.Text.Replace(" DKK", string.Empty).Replace(".", string.Empty).Replace(',', '.'), CultureInfo.InvariantCulture);
            });

            return(bookingNumber, bookingPassword, totalPrice);
        }
Пример #8
0
        public static async Task <bool> TryInvokeOnElementAsync(this IBrowserSession session, By by, Action <IWebElement> handler)
        {
            try
            {
                await WaitForElementToAppearAsync(session, by, 1);

                await session.InvokeAsync(driver =>
                {
                    var element = driver.FindElements(by).Single(x => x.IsDisplayed());

                    handler(element);
                });

                return(true);
            }
            catch (WebDriverTimeoutException)
            {
                return(false);
            }
        }
Пример #9
0
 public static Task SetValueWithScriptAsync(this IBrowserSession session, string cssSelector, string value)
 {
     return(session.InvokeAsync(driver => driver.ExecuteScript($"document.querySelector('{cssSelector}').value='{value}'")));
 }