Esempio n. 1
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);
            }
        }