コード例 #1
0
        /// <summary>
        /// Prints the order details.
        /// </summary>
        public virtual void Print()
        {
            var tabHelper   = WrappedDriver.TabHelper();
            var initialTabs = tabHelper.GetTabHandles().ToList();
            var initialTab  = WrappedDriver.CurrentWindowHandle;

            WrappedDriver
            .Wait(TimeSpan.FromSeconds(30))
            .Until(
                d => tabHelper.GetTabHandles().Count() > initialTabs.Count);

            WrappedDriver
            .SwitchTo()
            .Window(tabHelper
                    .GetTabHandles()
                    .Except(initialTabs)
                    .First());

            var printWindowHandle = WrappedDriver.CurrentWindowHandle;

            WrappedDriver.WaitForUserSignal(TimeSpan.FromMinutes(5));

            // Close the tab if it's still open.
            if (WrappedDriver.CurrentWindowHandle == printWindowHandle)
            {
                WrappedDriver.Close();
            }

            // Switch back to the initial window handle.
            WrappedDriver.SwitchTo().Window(initialTab);
        }
        /// <summary>
        /// Adds the new related product.
        /// </summary>
        /// <param name="productName">Name of the product.</param>
        /// <returns></returns>
        public virtual RelatedProductsComponent AddNewRelatedProduct(string productName)
        {
            var currentPageHandle = WrappedDriver.CurrentWindowHandle;
            var windowHandles     = WrappedDriver.WindowHandles;
            var newWindowHandle   = default(string);

            AddNewRelatedProductElement.Click();

            // Wait for the new window to appear.
            WrappedDriver
            .Wait(TimeSpan.FromSeconds(10))
            .Until(d => newWindowHandle = d.WindowHandles
                                          .Except(windowHandles)
                                          .FirstOrDefault());

            // Switch to the new window.
            WrappedDriver.SwitchTo().Window(newWindowHandle);

            SearchProductPopup.Load();
            SearchProductPopup.SearchForProduct(productName);

            // Switch back.
            WrappedDriver.SwitchTo().Window(currentPageHandle);

            // Wait for the grid to finish loading.
            WrappedDriver
            .Wait(TimeSpan.FromSeconds(10))
            .UntilChain(d => RelatedProductsGrid.IsBusy())
            .UntilChain(d => !RelatedProductsGrid.IsBusy());

            return(this);
        }
コード例 #3
0
 public void SwitchToFrame(Frame frame)
 {
     if (frame.WrappedElement != null)
     {
         WrappedDriver.SwitchTo().Frame(frame.WrappedElement);
     }
 }
コード例 #4
0
ファイル: Element.cs プロジェクト: Torlan1/Animatronio
        /// <summary>
        /// FindMe() selects the iframe, and waits for the element to appear.  Once found the IWebElement
        /// is stored in the WrappedElement for future use
        /// Waits an amount of time specified by the timeoutMs value.
        /// </summary>
        /// <returns></returns>
        public IWebElement FindMe()
        {
            var wait = new WebDriverWait(WrappedDriver, TimeSpan.FromMilliseconds(_timeoutMs));

            wait.Message = $"{this} was not found";

            //wait for all ajax requests to finish
            WrappedDriver.WaitForAjax(_timeoutMs);

            //If the element was already found, and has not gone stale, return the previously found IWebElement
            if (IsStale())
            {
                WrappedDriver.SwitchTo().DefaultContent();
                //if the container is not null, use it as the root element (search in descendents)
                if (_container != null)
                {
                    //find the root element using the container's findMe
                    var root = _container.FindMe();
                    //select an iframe if necessary
                    if (_frame != null)
                    {
                        WrappedDriver.SwitchTo().Frame(_frame.FindMe());
                    }
                    //if FindHidden is false, only find visible elements
                    if (!FindHidden)
                    {
                        _webelement = wait.Until(drv => root.FindVisibleElement(_by));
                    }
                    else
                    {
                        //find any element, even if its hidden
                        _webelement = wait.Until(drv => root.FindElement(_by));
                    }
                }
                else
                {
                    //select the iframe if appropriate
                    if (_frame != null)
                    {
                        WrappedDriver.SwitchTo().Frame(_frame.FindMe());
                    }
                    //find hidden elements if appropriate
                    if (!FindHidden)
                    {
                        _webelement = wait.Until(drv => drv.FindVisibleElement(_by));
                    }
                    //find any element including hidden ones
                    else
                    {
                        _webelement = wait.Until(drv => drv.FindElement(_by));
                    }
                }
            }
            //highlight the element so the user can see what element was found
            _webelement.Highlight();
            return(_webelement);
        }
コード例 #5
0
        public string Execute(string frameName, string script)
        {
            WrappedDriver.SwitchTo().Frame(frameName);
            var result = (string)Execute(script);

            WrappedDriver.SwitchTo().DefaultContent();

            return(result);
        }
コード例 #6
0
        /// <summary>
        /// Deletes this instance.
        /// </summary>
        /// <returns></returns>
        public virtual T Delete()
        {
            DeleteElement.Click();
            WrappedDriver
            .SwitchTo()
            .Alert()
            .Accept();

            return(Parent());
        }
コード例 #7
0
ファイル: Elements.cs プロジェクト: jkwaldrip/page-components
        public IEnumerable <IWebElement> FindMe()
        {
            var wait = new WebDriverWait(WrappedDriver, TimeSpan.FromMilliseconds(_timeoutMs));

            wait.Message = $"{this} was not found";
            WrappedDriver.WaitForAjax(_timeoutMs);
            if (IsStale())
            {
                if (_container != null)
                {
                    var root = _container.FindMe();
                    if (_frame != null)
                    {
                        WrappedDriver.SwitchTo().Frame(_frame.FindMe());
                    }

                    if (FindHidden)
                    {
                        _webElements = wait.Until(drv => root.FindElements(_by));
                    }
                    else
                    {
                        _webElements = wait.Until(drv => root.FindVisibleElements(_by));
                    }
                }
                else
                {
                    if (_frame != null)
                    {
                        WrappedDriver.SwitchTo().Frame(_frame.FindMe());
                    }

                    if (FindHidden)
                    {
                        _webElements = wait.Until(_driver => _driver.FindElements(_by));
                    }
                    else
                    {
                        _webElements = wait.Until(_driver => _driver.FindVisibleElements(_by));
                    }
                }
            }

            _elements = new List <Element>();
            foreach (var webele in _webElements)
            {
                webele.Highlight();
                var elem = new Element(by);
                elem.WrappedElement = webele;
                _elements.Add(elem);
            }
            return(_webElements);
        }
        /// <summary>
        /// Adds the new tier price.
        /// </summary>
        /// <param name="tierPricingModel">The tier pricing model.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">tierPricingModel</exception>
        public virtual TierPricesComponent AddNewTierPrice(
            TierPriceModel tierPricingModel)
        {
            if (tierPricingModel == null)
            {
                throw new ArgumentNullException(nameof(tierPricingModel));
            }

            var cachedWindowHandle  = WrappedDriver.CurrentWindowHandle;
            var cachedWindowHandles = WrappedDriver.WindowHandles;

            AddNewTierPriceElement.Click();

            WrappedDriver
            .Wait(TimeSpan.FromSeconds(10))
            .Until(d => d.WindowHandles.Count > cachedWindowHandles.Count);

            // Switch to new window.
            var newHandle = WrappedDriver.WindowHandles
                            .Except(cachedWindowHandles)
                            .First();

            WrappedDriver.SwitchTo().Frame(newHandle);

            // Load the StartDate/EndDate components.
            StartDateComponent.Load();
            EndDateComponent.Load();

            // Enter values.
            QuantityElement.SetValue(tierPricingModel.Quantity);
            PriceElement.SetValue(tierPricingModel.Price);
            StoreElement.SelectByText(tierPricingModel.Store);
            CustomerRoleElement.SelectByText(tierPricingModel.CustomerRole);
            StartDateComponent.SetValue(tierPricingModel.StartDate);
            EndDateComponent.SetValue(tierPricingModel.EndDate);

            // Save.
            var saveEl = SaveElement; // Cache this to avoid extra lookups.

            saveEl.Click();
            WrappedDriver
            .Wait(TimeSpan.FromSeconds(10))
            .Until(d => saveEl.IsStale());

            // Switch back to the original handle.
            WrappedDriver.SwitchTo().Frame(cachedWindowHandle);

            return(this);
        }
コード例 #9
0
        public void Handle(Action <IAlert> action = null, DialogButton dialogButton = DialogButton.Ok)
        {
            var alert = WrappedDriver.SwitchTo().Alert();

            action?.Invoke(alert);
            if (dialogButton == DialogButton.Ok)
            {
                alert.Accept();
                WrappedDriver.SwitchTo().DefaultContent();
            }
            else
            {
                alert.Dismiss();
                WrappedDriver.SwitchTo().DefaultContent();
            }
        }
        /// <summary>
        /// Previews product and switches to the new window.
        /// </summary>
        /// <param name="switchToNewWindow">if set to <c>true</c> [switch to new window].</param>
        /// <returns></returns>
        public virtual string Preview(bool switchToNewWindow = true)
        {
            var oldWindowHandles = WrappedDriver.WindowHandles;

            PreviewButtonElement.Click();

            WrappedDriver
            .Wait(TimeSpan.FromSeconds(10))
            .Until(d => d.WindowHandles.Count != oldWindowHandles.Count);

            var newHandle = WrappedDriver.WindowHandles
                            .Except(oldWindowHandles)
                            .First();

            if (switchToNewWindow)
            {
                WrappedDriver.SwitchTo().Window(newHandle);
            }

            return(newHandle);
        }
コード例 #11
0
 /// <summary>
 /// Instructs the driver to send future commands to a different frame or window.
 /// </summary>
 /// <returns>
 /// An <see cref="ITargetLocator"/> object which can be used to select a frame or window.
 /// </returns>
 public ITargetLocator SwitchTo()
 {
     return(WrappedDriver.SwitchTo());
 }
コード例 #12
0
 public void SwitchWindowByName(string windowName)
 {
     WrappedDriver.SwitchTo().Window(windowName);
 }
コード例 #13
0
 public void SwitchToTab(string tabName) => WrappedDriver.SwitchTo().Window(tabName);
コード例 #14
0
 public void SwitchToLastTab() => WrappedDriver.SwitchTo().Window(WrappedDriver.WindowHandles.Last());
コード例 #15
0
 public void SwitchToFirstBrowserTab() => WrappedDriver.SwitchTo().Window(WrappedDriver.WindowHandles.First());
コード例 #16
0
 public void SwitchToActive() => WrappedDriver.SwitchTo().ActiveElement();
コード例 #17
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);
        }
コード例 #18
0
        /// <summary>
        /// FindMe() selects the iframe, and searches for the element.  Once found the IWebElement
        /// is stored in the WrappedElement for future use
        /// Waits an amount of time specified by the timeoutMs value.
        /// </summary>
        /// <returns></returns>
        public IWebElement FindMe()
        {
            //wait for all ajax requests to finish
            WrappedDriver.WaitForAjax(TimeoutMs);

            //look for a non-null reference in the cache
            if (WebElement == null)
            {
                WebElement = WebElementCache.GetCachedElement(this.ToString(), Index);
            }

            //If the element was already found, and has not gone stale, return the previously found IWebElement

            if (IsStale())
            {
                var stopwatch = Stopwatch.StartNew();
                WrappedDriver.SwitchTo().DefaultContent();
                //if the container is not null, use it as the root element (search in descendents)
                if (Container != null)
                {
                    //find the root element using the container's findMe
                    var root = Container.FindMe();
                    //select an iframe if necessary
                    if (Frame != null)
                    {
                        Logger.Log($"Select frame {Frame}");

                        WrappedDriver.SwitchTo().Frame(Frame.WaitForMe());
                    }

                    //if FindHidden is false, only find visible elements
                    if (!FindHidden)
                    {
                        Logger.Log($"Finding visible {this}");

                        WebElement = root.FindVisibleElement(By);
                    }
                    else
                    {
                        Logger.Log($"Finding {this}");

                        //find any element, even if its hidden
                        WebElement = root.FindElement(By);
                    }
                }
                else
                {
                    //select the iframe if appropriate
                    if (Frame != null)
                    {
                        Logger.Log($"Selecting frame {Frame}");

                        WrappedDriver.SwitchTo().Frame(Frame.WaitForMe());
                    }
                    //find hidden elements if appropriate
                    if (!FindHidden)
                    {
                        Logger.Log($"Finding visible {this}");

                        WebElement = WrappedDriver.FindVisibleElement(By);
                    }
                    //find any element including hidden ones
                    else
                    {
                        Logger.Log($"Finding {this}");

                        WebElement = WrappedDriver.FindElement(By);
                    }
                }
                stopwatch.Stop();
                Logger.Log($"{this} found after {stopwatch.ElapsedMilliseconds} ms");
                //save the found element to the cache
                WebElementCache.SaveElementToCache(WebElement, this.ToString(), Index);
            }

            return(WebElement);
        }
コード例 #19
0
 public void SwitchToDefault() => WrappedDriver.SwitchTo().DefaultContent();
コード例 #20
0
        /// <summary>
        /// Adds the new associated products.
        /// </summary>
        /// <param name="productName">Name of the product.</param>
        /// <returns></returns>
        public virtual AssociatedProductsVariantsComponent AddNewAssociatedProducts(
            string productName)
        {
            var productNameSelector = By.CssSelector("#SearchProductName");
            var searchSelector      = By.CssSelector("#search-products");
            var saveSelector        = By.CssSelector("*[name='save']");

            var currentWindowHandle = WrappedDriver.CurrentWindowHandle;
            var windowHandles       = WrappedDriver.WindowHandles;
            var newWindowHandle     = default(string);

            AddNewAssociatedProductElement.Click();

            // Wait for the new window to appear.
            WrappedDriver
            .Wait(TimeSpan.FromSeconds(5))
            .Until(d => newWindowHandle = d.WindowHandles
                                          .Except(windowHandles)
                                          .FirstOrDefault());

            // Switch to new window.
            WrappedDriver.SwitchTo().Window(newWindowHandle);

            var productNameEl = new InputElement(
                WrappedDriver.FindElement(
                    productNameSelector));

            var searchElement = WrappedDriver.FindElement(searchSelector);

            var productsGrid = pageObjectFactory.PrepareComponent(
                new KGridComponent <AssociatedProductsVariantsComponent>(
                    new BaseKendoConfiguration(),
                    By.CssSelector("#products-grid"),
                    pageObjectFactory,
                    WrappedDriver,
                    this));

            var saveElement = WrappedDriver.FindElement(saveSelector);

            productNameEl.SetValue(productName);
            searchElement.Click();

            // Wait until ajax request finishes.
            WrappedDriver
            .Wait(TimeSpan.FromSeconds(10))
            .Until(d => !productsGrid.IsBusy());

            // Select the first product that appears.
            var firstCheckbox = productsGrid
                                .GetCell(0, 0)
                                .FindElement(By.TagName("input"));

            var checkbox = new CheckboxElement(firstCheckbox);

            checkbox.Check(true);

            // Save.
            saveElement.Click();

            // Wait until the window handle no longer exists.
            WrappedDriver
            .Wait(TimeSpan.FromSeconds(10))
            .Until(d => !d.WindowHandles.Contains(newWindowHandle));

            // Switch back to the main window.
            WrappedDriver.SwitchTo().Window(currentWindowHandle);

            // Wait for the ajx request to finish.
            WrappedDriver
            .Wait(TimeSpan.FromSeconds(10))
            .UntilChain(d => AssociatedProductsGridComponent.IsBusy())
            .UntilChain(d => !AssociatedProductsGridComponent.IsBusy());

            return(this);
        }