private bool ProductCreation(long num)
        {
            ProductDto aProduct = new ProductDto();

            aProduct = gen.GenerateProduct(num, numberOfProductToGenerate);

            var s = _container.Resolve <IProductService>();
            var p = s.AddProduct(aProduct, null);

            ProcessProductImages(p.Id);

            var i = _container.Resolve <IIndexingProductService>();

            i.IndexSingleProduct(p.Id);

            return(true);
        }
示例#2
0
        public void FillProductForm()
        {
            Debug.WriteLine(string.Concat("launching Firefox and go to url:", url));
            driver.Navigate().GoToUrl(url);

            if (NumberOfImageToGet > 0)
            {
                Debug.WriteLine(string.Concat("Test automation will get ", NumberOfImageToGet, " per product..."));
                for (int i = 1; i < NumberOfImageToGet + 1; i++)
                {
                    Debug.WriteLine("Generating a product...");
                    ProductDto aProduct = new ProductDto();
                    aProduct = gen.GenerateProduct(i, NumberOfImageToGet);

                    Debug.WriteLine(string.Concat("Get image ", i.ToString(), "/", NumberOfImageToGet.ToString(), " for product : ", aProduct.Name));

                    driver.FindElementById("lst-ib").SendKeys(aProduct.Name);
                    driver.Keyboard.SendKeys(Keys.Return);

                    ///XPath   //*[@id=\"rg_s\"]/div[1]/a/img
                    driver.FindElementByXPath("//*[@id=\"rg_s\"]/div[1]/a/img").Click();

                    //display image
                    //driver.FindElementByXPath("//*[@id=\"irc_cc\"]/div[3]/div[3]/div/div[2]/table[1]/tbody/tr/td[2]/a/span").Click();
                    //string imageData = driver.FindElementByXPath("/html/body/img").GetAttribute("src");
                    //Debug.WriteLine(string.Concat("-------------->", imageData));

                    //get source image from display image
                    string imageData = driver.FindElementByXPath("//*[@id=\"irc_cc\"]/div[3]/div[3]/div/div[2]/table[1]/tbody/tr/td[2]/a").GetAttribute("data-href");
                    Debug.WriteLine(string.Concat("-------------->", imageData));
                }
            }
            else
            {
                Debug.WriteLine(string.Concat("product = ", NumberOfImageToGet, " no images get"));
            }
        }
示例#3
0
        public void FillProductForm()
        {
            for (int productNb = 1; productNb < numberOfProductToGenerate + 1; productNb++)
            {
                ProductDto aProduct = new ProductDto();
                aProduct = gen.GenerateProduct(productNb, numberOfProductToGenerate);


                /// product name
                driver.FindElement(By.Id("product-name")).Click();
                driver.FindElement(By.Id("product-name")).SendKeys(aProduct.Name);

                /// product one line description
                driver.FindElement(By.Id("product-one_line_description")).SendKeys(aProduct.ShortDescription);

                /// product price
                driver.FindElement(By.Id("product-price")).SendKeys(aProduct.Price.ToString());

                /// Need to split the address in order to be sure that the correct one will be entered (instead of sendkeys at once is too fast: //driver.FindElement(By.Id("product-one_line_address")).SendKeys("12 Rue Saint-Bernard, 75011 Paris, France");)
                address = aProduct.AdressOneLine;
                if (setAddressFillMode.Equals(pAddressFillModeAtOnce))
                {
                    driver.FindElement(By.Id("product-one_line_address")).SendKeys(address);
                }
                else if (setAddressFillMode.Equals(pAddressFillModeWord))
                {
                    splittedAddressWord = address.Split(' ');
                    foreach (var item in splittedAddressWord)
                    {
                        driver.FindElement(By.Id("product-one_line_address")).SendKeys(item + " ");
                        if (pLongFillThreadSleepDuration > 0)
                        {
                            Thread.Sleep(pLongFillThreadSleepDuration);
                        }
                    }
                }
                else if (setAddressFillMode.Equals(pAddressFillModeChar))
                {
                    splittedAddressChar = address.ToCharArray();
                    for (int z = 0; z < splittedAddressChar.Length; z++)
                    {
                        driver.FindElement(By.Id("product-one_line_address")).SendKeys(splittedAddressChar.GetValue(z).ToString());
                        if (pLongFillThreadSleepDuration > 0)
                        {
                            Thread.Sleep(pLongFillThreadSleepDuration);
                        }
                    }
                }


                /// validate selection of address
                //driver.Keyboard.SendKeys(Keys.ArrowDown);
                //driver.Keyboard.SendKeys(Keys.Return);
                driver.Keyboard.SendKeys(Keys.Tab);

                /// Select the category after searching the correct category in the tree deph, need to tab 3 times to be in the corresponding checkbox
                driver.FindElement(By.Id("product-category")).SendKeys(gen.GetCurrentGeneratedCategoryName());
                driver.Keyboard.SendKeys(Keys.Tab);
                driver.Keyboard.SendKeys(Keys.Tab);
                driver.Keyboard.SendKeys(Keys.Tab);
                driver.Keyboard.SendKeys(Keys.Space);             /// Select the corresponding category

                /// Need to send a TAB key as we don't select the generated input, from the tree to the caracteristics field
                /// //driver.FindElement(By.Id("product-caracteristics")).Click(); //8
                driver.Keyboard.SendKeys(Keys.Tab);
                foreach (ProductAttributeDto att in aProduct.ProductAttributes)
                {
                    driver.Keyboard.SendKeys(att.Type);     /// Attribute-type (charactestic name)
                    driver.Keyboard.SendKeys(Keys.Tab);     /// Validate attribute-type
                    ///TODO: remove the replace
                    driver.Keyboard.SendKeys(att.Item);     /// Attribute-item (characteristic value)
                    driver.Keyboard.SendKeys(Keys.Return);  /// Validate attribute-item
                }

                /// Send two TABS from the empty attributes type > attributes item > textarea
                /// /// Need to split the product long description in order to avoid crash of Firefox (instead of sendkeys at once is too fast: //driver.Keyboard.SendKeys(productLongDesc);;)
                //driver.Keyboard.SendKeys(Keys.Tab);
                //driver.Keyboard.SendKeys(Keys.Tab);
                driver.FindElement(By.Id("recaptcha_response_field")).Click(); /// goes back from captcha
                //Thread.Sleep(3);
                driver.Keyboard.PressKey(Keys.LeftShift);
                driver.Keyboard.SendKeys(Keys.Tab);
                driver.Keyboard.SendKeys(Keys.Tab);
                driver.Keyboard.ReleaseKey(Keys.LeftShift);

                Thread.Sleep(100);

                // manage the long description
                productLongDesc = aProduct.Description;
                if (setLongDescFillMode.Equals(pLongDescGenerateShortOne))
                {
                    driver.Keyboard.SendKeys("longDesc! " + aProduct.Name + " " + productNb); // We don't use the generated long description in the product because Firefox crashes... even if we split like the address...
                    driver.Keyboard.SendKeys(Keys.Return);
                    driver.Keyboard.SendKeys("Done!");
                }
                else if (setLongDescFillMode.Equals(pLongDescFillModeWord))
                {
                    splittedProductLongDescWord = productLongDesc.Split(' ');
                    foreach (var item in splittedProductLongDescWord)
                    {
                        driver.Keyboard.SendKeys(item + " ");
                        if (pLongFillThreadSleepDuration > 0)
                        {
                            Thread.Sleep(pLongFillThreadSleepDuration);
                        }
                    }
                }
                else if (setLongDescFillMode.Equals(pLongDescFillModeChar))
                {
                    splittedProductLongDescChar = productLongDesc.ToCharArray();
                    for (int z = 0; z < splittedProductLongDescChar.Length; z++)
                    {
                        driver.Keyboard.SendKeys(splittedProductLongDescChar.GetValue(z).ToString());
                        if (pLongFillThreadSleepDuration > 0)
                        {
                            Thread.Sleep(pLongFillThreadSleepDuration);
                        }
                    }
                }
                else if (setLongDescFillMode.Equals(pLongDescGenerateShortOne))
                {
                    driver.Keyboard.SendKeys(productLongDesc);
                }

                // manage images
                driver.FindElement(By.Id("uploadImageButton")).SendKeys(@"D:\Mercurius.Images\UITestImages\voiture-1.jpg");
                driver.FindElement(By.Id("uploadImageButton")).SendKeys(@"D:\Mercurius.Images\UITestImages\voiture-2.jpg");

                /// validation
                driver.FindElement(By.Id("product-publish")).Click();


                /// reinitialize the form by force refresh the page
                Thread.Sleep(1500);
                driver.Keyboard.PressKey(Keys.LeftControl);
                driver.Keyboard.SendKeys(Keys.F5);
                driver.Keyboard.ReleaseKey(Keys.LeftControl);
            }
        }