/// <summary>
        /// Retrieves the viewmodel.
        /// </summary>
        /// <returns></returns>
        public virtual HeaderLinksModel ViewModel()
        {
            var wait = WrappedDriver.Wait(TimeSpan.FromSeconds(30));

            var isLoggedIn           = wait.Exists(LogoutSelector.ToString());
            var hasShoppingCartItems = wait.Exists(ShoppingCartSelector);
            var hasPrivateMessages   = wait.Exists(PrivateMessagesSelector);
            var hasWishList          = WrappedDriver.FindElements(WishListSelector).Any();

            var model = new HeaderLinksModel
            {
                IsAuthenticated = isLoggedIn,
                CustomerName    = isLoggedIn
                    ? CustomerInfoElement.Text
                    : null,
                ShoppingCartEnabled = hasShoppingCartItems,
                ShoppingCartItems   = hasShoppingCartItems
                    ? ShoppingCartQtyElement.TextHelper().ExtractInteger()
                    : 0,
                AllowPrivateMessages  = hasPrivateMessages,
                UnreadPrivateMessages = hasPrivateMessages
                    ? PrivateMessageLabelElement.Text
                    : null,
                WishlistEnabled = hasWishList,
                WishlistItems   = hasWishList
                    ? WishListQtyElement.TextHelper().ExtractInteger()
                    : 0,
                Currency = CurrencyElement.SelectedOption.TextHelper().InnerText,
                Language = LanguageElement.SelectedOption.TextHelper().InnerText
            };

            return(model);
        }
        /// <summary>
        /// If overridding this don't forget to call base.Load().
        /// NOTE: Will navigate to the pages url if the current drivers url
        /// is empty.
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// If the driver is an EventFiringWebDriver an event listener will
        /// be added to the 'Navigated' event and uses the url to determine
        /// if the page is 'stale'.
        /// </remarks>
        public override ILoadableComponent Load()
        {
            base.Load();
            basePage.Load();

            pageObjectFactory.PrepareComponent(CategoriesComponent);
            pageObjectFactory.PrepareComponent(ManufacturersComponent);
            pageObjectFactory.PrepareComponent(PopularTagsComponent);

            // Verify this is displayed before loading it.
            if (WrappedDriver.FindElements(recentlyViewedProductsSelector).Any())
            {
                RecentlyViewProductsComponent = new CatalogBlockComponent(
                    recentlyViewedProductsSelector,
                    WrappedDriver);

                pageObjectFactory.PrepareComponent(RecentlyViewProductsComponent);
            }
            else
            {
                // Assign to null if not loaded.
                RecentlyViewProductsComponent = null;
            }

            return(this);
        }
コード例 #3
0
        /// <summary>
        /// If overridding this don't forget to call base.Load().
        /// NOTE: Will navigate to the pages url if the current drivers url
        /// is empty.
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// If the driver is an EventFiringWebDriver an event listener will
        /// be added to the 'Navigated' event and uses the url to determine
        /// if the page is 'stale'.
        /// </remarks>
        public override ILoadableComponent Load()
        {
            base.Load();

            if (WrappedDriver.FindElements(pagingFilterSelcetor).Any())
            {
                PagingFilterComponent = new CatalogPagingFilterComponent(
                    By.CssSelector(".search-input"),
                    WrappedDriver);

                pageObjectFactory.PrepareComponent(PagingFilterComponent);
            }
            else
            {
                PagingFilterComponent = null;
            }

            if (WrappedDriver.FindElements(pagerSelector).Any())
            {
                PagerComponent = new PagerComponent(
                    By.CssSelector(".pager"),
                    WrappedDriver);

                pageObjectFactory.PrepareComponent(PagerComponent);
            }
            else
            {
                PagerComponent = null;
            }

            return(this);
        }
コード例 #4
0
 private bool HasExistingShippingAddresses()
 {
     // If the element exists then there are existing addresses.
     return(WrappedDriver
            .FindElements(shippingAddressDropDownSelector)
            .Any());
 }
コード例 #5
0
        /// <summary>
        /// Checks if the email is invalid.
        /// </summary>
        /// <returns></returns>
        public virtual bool HasInvalidEmail()
        {
            if (WrappedDriver.FindElements(emailValidatorSelector).Any())
            {
                return(String.IsNullOrWhiteSpace(EmailValidationElement.Text));
            }

            return(false);
        }
        /// <summary>
        /// Accepts the terms and conditions.
        /// </summary>
        /// <param name="accept">if set to <c>true</c> [accept].</param>
        /// <returns></returns>
        public virtual OrderSummaryComponent AcceptTermsAndConditions(bool accept)
        {
            // Check if terms and conditions are present.
            if (WrappedDriver.FindElements(termsOfServiceSelector).Any())
            {
                TermsOfServiceElement.Check(accept);
            }

            return(this);
        }
コード例 #7
0
        private bool HasExistingBillingAddresses()
        {
            if (GetCurrentStepName() != "Billing address")
            {
                throw new Exception("Not on correct step.");
            }

            // If the element exists then there are existing addresses.
            return(WrappedDriver
                   .FindElements(billingAddressDropDownSelector)
                   .Any());
        }
コード例 #8
0
        /// <summary>
        /// Gets the products.
        /// </summary>
        /// <returns></returns>
        public virtual IEnumerable <OrderSummaryReadOnlyRowComponent> GetProducts()
        {
            var rowEls = WrappedDriver.FindElements(productRowsSelector);

            foreach (var rowEl in rowEls)
            {
                yield return(pageObjectFactory.PrepareComponent(
                                 new OrderSummaryReadOnlyRowComponent(
                                     ByElement.FromElement(rowEl),
                                     WrappedDriver)));
            }
        }
コード例 #9
0
        /// <summary>
        /// If overriding don't forget to call base.Load() or make sure to
        /// assign the WrappedElement.
        /// </summary>
        /// <returns></returns>
        public override ILoadableComponent Load()
        {
            base.Load();

            pagerSelector = new ByChained(
                new ByElement(WrappedElement),
                By.CssSelector(".k-pager-wrap.k-grid-pager"));

            toolbarSelector = new ByChained(
                new ByElement(WrappedElement),
                By.CssSelector(".k-toolbar"));

            if (WrappedDriver.FindElements(toolbarSelector).Any())
            {
                Toolbar = new KToolbarComponent <KGridComponent <T> >(
                    configuration,
                    toolbarSelector,
                    WrappedDriver,
                    this);

                pageObjectFactory.PrepareComponent(Toolbar);
            }
            else
            {
                Toolbar = null;
            }

            if (WrappedDriver.FindElements(pagerSelector).Any())
            {
                Pager = new KPagerComponent <KGridComponent <T> >(
                    configuration,
                    pagerSelector,
                    pageObjectFactory,
                    WrappedDriver,
                    this);

                pageObjectFactory.PrepareComponent(Pager);
            }
            else
            {
                Pager = null;
            }

            // Check for multi-column headers.
            var theadRows = WrappedElement
                            .FindElements(By.CssSelector("thead > tr"))
                            .ToList();

            IsMultiColumnHeader = theadRows.Count > 1;

            return(this);
        }
コード例 #10
0
        /// <summary>
        /// Similar to <c>Search</c> but waits for the ajax results to resolve
        /// and returns those items.
        /// </summary>
        /// <param name="searchFor">The search for.</param>
        public virtual IReadOnlyCollection <IWebElement> SearchAjax(string searchFor)
        {
            // Cache the searchbox element.
            var searchBoxEl = SearchBoxElement;

            searchBoxEl.SetValue(searchFor);

            // Wait for the loading class to toggle on the input el.
            WrappedDriver.Wait(TimeSpan.FromSeconds(30))
            .TrySequentialWait(
                out var exc,
                d => searchBoxEl.Is(searchAjaxLoadingSelector),
                d => !searchBoxEl.Is(searchAjaxLoadingSelector));

            var els = WrappedDriver.FindElements(ajaxSearchResultsSelector);

            return(els);
        }
コード例 #11
0
        /// <summary>
        /// If overridding this don't forget to call base.Load().
        /// NOTE: Will navigate to the pages url if the current drivers url
        /// is empty.
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// If the driver is an EventFiringWebDriver an event listener will
        /// be added to the 'Navigated' event and uses the url to determine
        /// if the page is 'stale'.
        /// </remarks>
        public override ILoadableComponent Load()
        {
            base.Load();

            if (WrappedDriver.FindElements(mainSideBarSelector).Any())
            {
                MainSideBar = pageObjectFactory.PrepareComponent(
                    new AdminMainSideBarComponent(
                        mainSideBarSelector,
                        pageObjectFactory,
                        WrappedDriver));
            }
            else
            {
                MainSideBar = null;
            }

            if (WrappedDriver.FindElements(navigationBarSelector).Any())
            {
                NavigationBar = pageObjectFactory.PrepareComponent(
                    new AdminMainHeaderComponent(
                        navigationBarSelector,
                        pageObjectFactory,
                        WrappedDriver));
            }
            else
            {
                NavigationBar = null;
            }

            if (WrappedDriver.FindElements(footerSelector).Any())
            {
                Footer = pageObjectFactory.PrepareComponent(
                    new AdminFooterComponent(WrappedDriver));
            }
            else
            {
                Footer = null;
            }

            return(this);
        }
コード例 #12
0
        /// <summary>
        /// If overridding this don't forget to call base.Load().
        /// NOTE: Will navigate to the pages url if the current drivers url
        /// is empty.
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// If the driver is an EventFiringWebDriver an event listener will
        /// be added to the 'Navigated' event and uses the url to determine
        /// if the page is 'stale'.
        /// </remarks>
        public override ILoadableComponent Load()
        {
            base.Load();

            // Load the headerlinks.
            pageObjectFactory.PrepareComponent(HeaderLinks);

            // Check if the admin header links exist, if they don't set to
            // null.
            if (WrappedDriver.FindElements(adminHeaderLinks.By).Any())
            {
                AdminHeaderLinks = pageObjectFactory
                                   .PrepareComponent(adminHeaderLinks);
            }
            else
            {
                AdminHeaderLinks = null;
            }

            return(this);
        }
コード例 #13
0
 public int CountElements(By locator)
 {
     return(WrappedDriver.FindElements(locator).Count);
 }
コード例 #14
0
 public IEnumerable <IWebElement> FindAll(ByEx byEx)
 {
     return(WrappedDriver.FindElements(byEx));
 }
コード例 #15
0
 public IEnumerable <IWebElement> FindAll(ByEx byEx)
 {
     WrappedDriver.WaitForPageLoad();
     return(WrappedDriver.FindElements(byEx));
 }
コード例 #16
0
        private IEnumerable <IWebElement> FindMe()
        {
            WrappedDriver.WaitForAjax(_timeoutMs);
            _webElements = WebElementsCache.GetCachedElements(this.ToString());
            if (IsStale())
            {
                var stopwatch = Stopwatch.StartNew();
                if (_container != null)
                {
                    var root = _container.FindMe();
                    if (_frame != null)
                    {
                        Logger.Log($"Select frame {_frame}");
                        WrappedDriver.SwitchTo().Frame(_frame.FindMe());
                    }

                    if (FindHidden)
                    {
                        Logger.Log($"Find {this}");
                        _webElements = root.FindElements(_by);
                    }
                    else
                    {
                        Logger.Log($"Find visible {this}");
                        _webElements = root.FindVisibleElements(_by);
                    }
                }
                else
                {
                    if (_frame != null)
                    {
                        Logger.Log($"Select frame {_frame}");
                        WrappedDriver.SwitchTo().Frame(_frame.FindMe());
                    }

                    if (FindHidden)
                    {
                        Logger.Log($"Find {this}");
                        _webElements = WrappedDriver.FindElements(_by);
                    }
                    else
                    {
                        Logger.Log($"Find visible {this}");
                        _webElements = WrappedDriver.FindVisibleElements(_by);
                    }
                }
                foreach (var ele in _webElements)
                {
                    if (TestContext.CurrentContext.TestConfig.HighlightElements)
                    {
                        ele.Highlight(50, "red");
                    }
                }


                stopwatch.Stop();
                Logger.Log($"Found {_webElements.Count()} Elements {_by} after {stopwatch.ElapsedMilliseconds} ms");
            }

            _elements = new List <Element>();
            int i = 1;

            foreach (var webele in _webElements)
            {
                var elem = new Element(webele, by, i);
                elem.WrappedElement = webele;
                _elements.Add(elem);
                WebElementCache.SaveElementToCache(webele, this.ToString(), i);
                i++;
            }
            WebElementsCache.SaveElementsToCache(_webElements.ToList(), this.ToString());
            return(_webElements);
        }
コード例 #17
0
        /// <summary>
        /// Tries the go to step.
        /// </summary>
        /// <param name="step">The step (zero based).</param>
        /// <param name="resolve">The resolve.</param>
        /// <param name="reject">The reject.</param>
        /// <returns>
        /// The operation success status.
        /// </returns>
        /// <exception cref="ArgumentOutOfRangeException">step</exception>
        /// <exception cref="ArgumentNullException">
        /// resolve
        /// or
        /// reject
        /// </exception>
        public virtual bool TryGoToStep(int step,
                                        Action <ICheckoutStepPage> resolve = null,
                                        Action <ICheckoutStepPage> reject  = null)
        {
            if (step < 0 || step >= GetTotalSteps())
            {
                throw new ArgumentOutOfRangeException(nameof(step));
            }

            var result      = false;
            var currentStep = GetCurrentStep();

            // Check if already on step.
            if (currentStep == step)
            {
                result = true;
            }
            else
            {
                if (step > currentStep)
                {
                    // Trying to go to the next step. Since steps might be
                    // skipped it can be any number greater then the current
                    // one.
                    IWebElement nextStepEl   = null;
                    IWebElement pleaseWaitEl = null;

                    if (BillingAddressNextStepElement?.Displayed ?? false)
                    {
                        nextStepEl   = BillingAddressNextStepElement;
                        pleaseWaitEl = BillingAddressPleaseWaitElement;
                    }
                    else if (ShippingAddressNextStepElement?.Displayed ?? false)
                    {
                        nextStepEl   = ShippingAddressNextStepElement;
                        pleaseWaitEl = ShippingAddressPleaseWaitElement;
                    }
                    else if (ShippingMethodNextStepElement?.Displayed ?? false)
                    {
                        nextStepEl   = ShippingMethodNextStepElement;
                        pleaseWaitEl = ShippingMethodPleaseWaitElement;
                    }
                    else if (PaymentMethodNextStepElement?.Displayed ?? false)
                    {
                        nextStepEl   = PaymentMethodNextStepElement;
                        pleaseWaitEl = PaymentMethodPleaseWaitElement;
                    }
                    else if (PaymentInformationNextStepElement?.Displayed ?? false)
                    {
                        nextStepEl   = PaymentInformationNextStepElement;
                        pleaseWaitEl = PaymentInformationPleaseWaitElement;
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }

                    // Click the next step button.
                    nextStepEl.Click();

                    WrappedDriver
                    .Wait(TimeSpan.FromSeconds(30))
                    .TrySequentialWait(
                        out var exc,
                        d => pleaseWaitEl.Displayed,
                        d => !pleaseWaitEl.Displayed);

                    // Sometimes the next step hasn't fully loaded even though
                    // the loading indicator has been hidden.
                    WrappedDriver
                    .Wait(TimeSpan.FromSeconds(2))
                    .Until(d => GetCurrentStep() == step);

                    // Verify the step changed to the correct one.
                    result = GetCurrentStep() == step;
                }
                else if (step < currentStep)
                {
                    // Trying to back to a previous step.
                    var activatableSteps = WrappedDriver
                                           .FindElements(activeTabTitleSelector);

                    // Verify still in range.
                    if (activatableSteps.Count > step)
                    {
                        activatableSteps[step].Click();
                    }
                    else
                    {
                        result = false;
                    }
                }
                else
                {
                    result = false;
                }
            }

            if (result)
            {
                resolve?.Invoke(this);
            }
            else
            {
                reject?.Invoke(this);
            }

            return(result);
        }
 private bool IsSidebarCollapsed()
 {
     return(!WrappedDriver
            .FindElements(By.CssSelector(".sidebar-collapse"))
            .Any());
 }
コード例 #19
0
 /// <summary>
 /// Checks for any errors.
 /// </summary>
 /// <returns></returns>
 public virtual bool HasMessageErrorSummary()
 {
     return(WrappedDriver.FindElements(messageErrorSelector).Any());
 }