public void TheDeliveryAdvancedSearchTest(string supplier, string products)
        {
            navigation.Replenishment.Click();
            navigation.Delivery.Click();
            Thread.Sleep(2000);

            DeliveryPageModel delivery = new DeliveryPageModel(driver);
            for (int i = 0; ; i++)
            {
                if (i >= 60) Assert.Fail("timeout");
                try
                {
                    if (delivery.DeliveryFrame.Displayed) break;
                }
                catch (Exception) { }
            }

            driver.SwitchTo().Frame(delivery.DeliveryFrame);
            Thread.Sleep(1000);
            delivery.CreateDelivery.Click();
            driver.SwitchTo().DefaultContent();

            NewDeliveryPageModel newDelivery = new NewDeliveryPageModel(driver);
            for (int i = 0; ; i++)
            {
                if (i >= 60) Assert.Fail("timeout");
                try
                {
                    if (newDelivery.NewDeliveryFrame.Displayed) break;
                }
                catch (Exception) { }
            }

            driver.SwitchTo().Frame(newDelivery.NewDeliveryFrame);

            Random rand = new Random();

            newDelivery.SupplierID.SendKeys(supplier);
            newDelivery.DispatchNumber.SendKeys(rand.Next(100000, 999999).ToString());
            newDelivery.DeliveryDate.SendKeys(DateTime.Today.ToString("dd/MM/yyyy"));
            newDelivery.SaveDelivery.Click();
            Thread.Sleep(1000);

            string[] productList = config[products].Split(',');

            AdvancedSearchPageModel advancedSearch = new AdvancedSearchPageModel(driver);
            foreach (string prod in productList)
            {
                newDelivery.AdvancedSearch.Click();
                for (int i = 0; ; i++)
                {
                    if (i >= 60) Assert.Fail("timeout");
                    try
                    {
                        if (advancedSearch.AdvancedSearchFrame.Displayed) break;
                    }
                    catch (Exception) { }
                    Thread.Sleep(1000);
                }
                driver.SwitchTo().Frame(advancedSearch.AdvancedSearchFrame);
                advancedSearch.ItemCode.SendKeys(prod);

                advancedSearch.SearchButton.Click();
                for (int i = 0; ; i++)
                {
                    if (i >= 60) Assert.Fail("timeout");
                    try
                    {
                        if (advancedSearch.SelectAll.Enabled) break;
                    }
                    catch (Exception) { }
                    Thread.Sleep(1000);
                }
                advancedSearch.SelectAll.Click();
                Thread.Sleep(500);
                driver.SwitchTo().DefaultContent();
                driver.SwitchTo().Frame(newDelivery.NewDeliveryFrame);
                navigation.ConfirmPopup.Click();
                driver.SwitchTo().Frame(advancedSearch.AdvancedSearchFrame);
                Thread.Sleep(500);
                shared.WaitForElementNotAppear(driver, driver.FindElement(By.ClassName("blockUI")));
                advancedSearch.OKButton.Click();

                driver.SwitchTo().DefaultContent();
                driver.SwitchTo().Frame(newDelivery.NewDeliveryFrame);
                Thread.Sleep(500);
            }

            newDelivery.SubmitDelivery.Click();

            driver.SwitchTo().DefaultContent();

            for (int i = 0; ; i++)
            {
                if (i >= 60) Assert.Fail("timeout");
                try
                {
                    if (delivery.DeliveryFrame.Displayed) break;
                }
                catch (Exception) { }
            }

            Logout();
        }
        public void TheManualOrderingAdvancedSearchTest(string supp, string productList)
        {
            navigation.Replenishment.Click();
            navigation.Order.Click();

            NewManualOrderingPageModel newManualOrder = new NewManualOrderingPageModel(driver);
            for (int second = 0; ; second++)
            {
                if (second >= 60) Assert.Fail("timeout");
                try
                {
                    if (newManualOrder.NewOrderFrame.Displayed) break;
                }
                catch (Exception)
                {
                }
                Thread.Sleep(1000);
            }

            driver.SwitchTo().Frame(newManualOrder.NewOrderFrame);

            newManualOrder.AddOrder.Click();
            new Actions(driver).MoveToElement(newManualOrder.ManualOrder, 5, 5).Build().Perform();
            newManualOrder.ManualOrder.Click();
            Thread.Sleep(1000);

            ManualOrderingPageModel manualOrder = new ManualOrderingPageModel(driver);
            driver.SwitchTo().DefaultContent();
            driver.SwitchTo().Frame(manualOrder.OrderFrame);
            new SelectElement(manualOrder.SupplierID).SelectByText(supp);
            manualOrder.SaveOrder.Click();

            for (int second = 0; ; second++)
            {
                if (second >= 60) Assert.Fail("timeout");
                try
                {
                    if (manualOrder.QuickAddText.Displayed) break;
                }
                catch (Exception)
                {
                }
                Thread.Sleep(1000);
            }

            string[] products = config[productList].Split(',');

            AdvancedSearchPageModel advancedSearch = new AdvancedSearchPageModel(driver);
            foreach (string prod in products)
            {
                manualOrder.AdvancedSearch.Click();
                for(int i = 0; ; i++)
                {
                    if (i >= 60) Assert.Fail("timeout");
                    try
                    {
                        if (advancedSearch.AdvancedSearchFrame.Displayed) break;
                    }
                    catch (Exception) { }
                    Thread.Sleep(1000);
                }
                driver.SwitchTo().Frame(advancedSearch.AdvancedSearchFrame);
                advancedSearch.ItemCode.SendKeys(prod);

                advancedSearch.SearchButton.Click();
                for (int i = 0; ; i++)
                {
                    if (i >= 60) Assert.Fail("timeout");
                    try
                    {
                        if (advancedSearch.SelectAll.Enabled) break;
                    }
                    catch (Exception) { }
                    Thread.Sleep(1000);
                }
                advancedSearch.SelectAll.Click();
                Thread.Sleep(500);
                driver.SwitchTo().DefaultContent();
                driver.SwitchTo().Frame(manualOrder.OrderFrame);
                navigation.ConfirmPopup.Click();
                driver.SwitchTo().Frame(advancedSearch.AdvancedSearchFrame);
                Thread.Sleep(500);
                advancedSearch.OKButton.Click();
                driver.SwitchTo().DefaultContent();
                driver.SwitchTo().Frame(manualOrder.OrderFrame);
                Thread.Sleep(500);
            }

            //manualOrder.SelectAllProducts.Click();
            //manualOrder.AddToBasket.Click();
            //Thread.Sleep(500);
            //new SelectElement(manualOrder.BasketDropdown).SelectByText("Default Basket");
            //manualOrder.AddBasket.Click();

            string handle = driver.CurrentWindowHandle;

            manualOrder.SendOrder.Click();

            driver.SwitchTo().DefaultContent();
            for (int second = 0; ; second++)
            {
                if (second >= 60) Assert.Fail("timeout");
                try
                {
                    if (driver.WindowHandles.Count > 1) break;
                }
                catch (Exception) { }
                Thread.Sleep(1000);
            }
            driver.SwitchTo().Window(driver.WindowHandles.Last());

            SendOrderWindow sendOrder = new SendOrderWindow(driver);

            for (int second = 0; ; second++)
            {
                if (second >= 60) Assert.Fail("timeout");
                try
                {
                    if (sendOrder.SubmitOrder.Displayed) break;
                }
                catch (Exception)
                { }
                Thread.Sleep(1000);
            }

            driver.Manage().Window.Maximize();

            Thread.Sleep(2000);

            sendOrder.SubmitOrder.Click();

            for (int second = 0; ; second++)
            {
                if (second >= 60) Assert.Fail("timeout");
                try
                {
                    if ("Order Submitted" == driver.Title) break;
                }
                catch (Exception)
                { }
                Thread.Sleep(1000);
            }

            driver.Close();

            driver.SwitchTo().Window(driver.WindowHandles.First());
            driver.SwitchTo().Frame(manualOrder.OrderFrame);
            Thread.Sleep(1000);

            navigation.ConfirmPopup.Click();
            driver.SwitchTo().DefaultContent();

            Logout();
        }
        public void TheAdvancedSearchStockAdjustmentTest(string comment, string products)
        {
            navigation.Replenishment.Click();
            navigation.StockAdjustment.Click();
            Thread.Sleep(2000);

            StockAdjustmentPageModel stockAdjust = new StockAdjustmentPageModel(driver);
            for (int i = 0; ; i++)
            {
                if (i >= 60) Assert.Fail("timeout");
                try
                {
                    if (stockAdjust.StockAdjustFrame.Displayed) break;
                }
                catch (Exception) { }
                Thread.Sleep(1000);
            }

            driver.SwitchTo().Frame(stockAdjust.StockAdjustFrame);
            stockAdjust.NewStockAdjust.Click();
            driver.SwitchTo().DefaultContent();
            NewStockAdjustmentPageModel newSA = new NewStockAdjustmentPageModel(driver);
            for (int i = 0; ; i++)
            {
                if (i >= 60) Assert.Fail("timeout");
                try
                {
                    if (newSA.NewStockAdjustFrame.Displayed) break;
                }
                catch (Exception) { }
                Thread.Sleep(1000);
            }
            driver.SwitchTo().Frame(newSA.NewStockAdjustFrame);
            new SelectElement(newSA.NewStockAdjustReason).SelectByText("Damaged");
            newSA.NewStockAdjustComments.SendKeys("Automated " + comment);

            Thread.Sleep(2000);
            string[] productList = config[products].Split(',');
            AdvancedSearchPageModel advancedSearch = new AdvancedSearchPageModel(driver);
            Random rand = new Random();
            foreach (string prod in productList)
            {
                newSA.NewStockAdjustAdvancedSearch.Click();
                for (int i = 0; ; i++)
                {
                    if (i >= 60) Assert.Fail("timeout");
                    try
                    {
                        if (advancedSearch.AdvancedSearchFrame.Displayed) break;
                    }
                    catch (Exception) { }
                    Thread.Sleep(1000);
                }
                driver.SwitchTo().Frame(advancedSearch.AdvancedSearchFrame);
                advancedSearch.ItemCode.SendKeys(prod);

                advancedSearch.SearchButton.Click();
                for (int i = 0; ; i++)
                {
                    if (i >= 60) Assert.Fail("timeout");
                    try
                    {
                        if (advancedSearch.SelectAll.Enabled) break;
                    }
                    catch (Exception) { }
                    Thread.Sleep(1000);
                }

                new Actions(driver).DoubleClick(newSA.AdvancedSearchAdjustQuantityActivate).Build().Perform();
                newSA.AdvancedSearchAdjustQuantity.SendKeys(rand.Next(1, 11).ToString());
                newSA.AdvancedSearchAdjustQuantity.SendKeys(Keys.Enter);
                Thread.Sleep(1000);
                //shared.WaitForElementNotAppear(driver, driver.FindElement(By.ClassName("blockUI")));
                advancedSearch.OKButton.Click();
                driver.SwitchTo().DefaultContent();
                driver.SwitchTo().Frame(newSA.NewStockAdjustFrame);
                Thread.Sleep(2000);
            }

            newSA.SaveStockAdjust.Click();
            driver.SwitchTo().DefaultContent();

            for (int i = 0; ; i++)
            {
                if (i >= 60) Assert.Fail("timeout");
                try
                {
                    if (stockAdjust.StockAdjustFrame.Displayed) break;
                }
                catch (Exception) { }
                Thread.Sleep(1000);
            }
            Logout();
        }