Exemple #1
0
        /// <summary>
        /// Obtiene la cantidad de productos
        /// </summary>
        /// <param name="quantity">La cantidad</param>
        /// <returns><see cref="Article"/></returns>
        public ResultsSearch GetProducts(int quantity)
        {
            Thread.Sleep(TimeSpan.FromSeconds(5));
            HtmlControl body = new HtmlControl(UIResultsPage.Body);

            body.SearchProperties[HtmlControl.PropertyNames.Id] = "ListViewInner";
            UITestControl               ulElement            = body.FindMatchingControls().FirstOrDefault();
            UITestControlCollection     listProductsChildren = ulElement.GetChildren();
            IEnumerable <UITestControl> CollectionProducts   = listProductsChildren.Take(quantity);

            // Obtiene el nombre y precio de cada uno de los productos y lo asigna al listado
            int aux = 0;

            foreach (HtmlControl product in CollectionProducts)
            {
                aux += 1;
                string msg = string.Format("Información del producto {0}", aux);
                Console.WriteLine(msg);
                Article article = new Article();

                // Nombre del producto
                HtmlControl productElement = product;
                productElement.SearchProperties[HtmlControl.PropertyNames.TagName] = "h3";
                productElement.SearchProperties[HtmlControl.PropertyNames.Class]   = "lvtitle";
                productElement.FindMatchingControls();
                string name = string.Format("    Nombre: {0}", productElement.InnerText);
                Console.WriteLine(name);

                // Precio del producto
                product.SearchProperties[HtmlControl.PropertyNames.TagName] = "li";
                product.SearchProperties[HtmlControl.PropertyNames.Class]   = "lvprice prc";
                product.FindMatchingControls();
                string price = string.Format("    Precio: {0}", product.InnerText);
                Console.WriteLine(price);
            }

            return(new ResultsSearch());
        }