Example #1
0
 private void DeselectDropdownItem(IWebDriver driver, WebAutomationStep automationStep)
 {
     if (!string.IsNullOrEmpty(automationStep.FindByValue))
     {
         var element = FindElement(driver, automationStep.FindElementBy, automationStep.FindByValue);
         if (element != null)
         {
             var select = new SelectElement(element);
             if (!string.IsNullOrEmpty(automationStep.InputValue))
             {
                 if (automationStep.HasMultipleValue)
                 {
                     var array = automationStep.InputValue.Split(automationStep.InputValueSeperator);
                     if (array.Length > 0)
                     {
                         foreach (var item in array)
                         {
                             select.DeselectByText(item.Trim());
                         }
                     }
                 }
                 else
                 {
                     select.DeselectByText(automationStep.InputValue);
                 }
             }
         }
     }
 }
Example #2
0
 private void NavigateToUrl(IWebDriver driver, WebAutomationStep automationStep)
 {
     if (!string.IsNullOrEmpty(automationStep.InputValue))
     {
         driver.Navigate().GoToUrl(automationStep.InputValue);
     }
 }
Example #3
0
 private void ClickElement(IWebDriver driver, WebAutomationStep automationStep)
 {
     if (!string.IsNullOrEmpty(automationStep.FindByValue))
     {
         var element = FindElement(driver, automationStep.FindElementBy, automationStep.FindByValue);
         if (element != null)
         {
             element.Click();
         }
     }
 }
Example #4
0
 private void GetValue(IWebDriver driver, WebAutomationStep automationStep)
 {
     if (!string.IsNullOrEmpty(automationStep.FindByValue))
     {
         var element = FindElement(driver, automationStep.FindElementBy, automationStep.FindByValue);
         if (element != null)
         {
             automationStep.OutputValue = element.Text;
         }
     }
 }
Example #5
0
 private void InputText(IWebDriver driver, WebAutomationStep automationStep)
 {
     if (!string.IsNullOrEmpty(automationStep.FindByValue))
     {
         var element = FindElement(driver, automationStep.FindElementBy, automationStep.FindByValue);
         if (element != null)
         {
             element.SendKeys(automationStep.InputValue);
         }
     }
 }
Example #6
0
        private void DownloadImage(IWebDriver driver, WebAutomationStep automationStep)
        {
            if (!string.IsNullOrEmpty(automationStep.FindByValue))
            {
                var element = FindElement(driver, automationStep.FindElementBy, automationStep.FindByValue);
                if (element != null)
                {
                    string imageSrc = element.GetAttribute("src");

                    WebClient client = new WebClient();
                    client.DownloadFile(imageSrc, automationStep.StepNo + ".jpeg");
                }
            }
        }
Example #7
0
        private void DragDrop(IWebDriver driver, WebAutomationStep automationStep)
        {
            if (!string.IsNullOrEmpty(automationStep.FindByValue) && !string.IsNullOrEmpty(automationStep.FindTargetByValue))
            {
                var source = FindElement(driver, automationStep.FindElementBy, automationStep.FindByValue);
                var target = FindElement(driver, automationStep.FindTargetElementBy, automationStep.FindTargetByValue);

                if (source != null && target != null)
                {
                    var builder = new Actions(driver);
                    var action  = builder.DragAndDrop(source, target);
                    action.Perform();
                }
            }
        }
Example #8
0
        public void Run(IWebDriver driver, WebAutomationStep automationStep)
        {
            if (driver != null && automationStep != null)
            {
                if (automationStep.Steps != null && automationStep.Steps.Any())
                {
                }
                else
                {
                    switch (automationStep.StepType)
                    {
                    case AutomationStepType.ClickElement:
                        ClickElement(driver, automationStep); break;

                    case AutomationStepType.DragElement:
                        DragDrop(driver, automationStep); break;

                    case AutomationStepType.ExecuteCustomFunction: break;

                    case AutomationStepType.InputText:
                        InputText(driver, automationStep); break;

                    case AutomationStepType.NavigateToUrl:
                        NavigateToUrl(driver, automationStep); break;

                    case AutomationStepType.RightClick: break;

                    case AutomationStepType.SearchElement: break;

                    case AutomationStepType.SelectDropdownItem:
                        SelectDropdownItem(driver, automationStep); break;

                    case AutomationStepType.DeselectDropDownItem:
                        DeselectDropdownItem(driver, automationStep); break;

                    case AutomationStepType.DownloadImage:
                        DownloadImage(driver, automationStep); break;

                    case AutomationStepType.GetValue:
                        GetValue(driver, automationStep); break;

                    default: break;
                    }
                }
            }
        }
Example #9
0
        static void Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver("F:\\Softwares\\chromedriver_win32");

            WebAutomationStep step1 = new WebAutomationStep()
            {
                AllowParallelThreads = false,
                StepNo     = 1,
                StepType   = Library.Models.Enums.AutomationStepType.NavigateToUrl,
                InputValue = "http://www.google.com"
            };


            var helper = new TestAutomationHelper();

            helper.Run(driver, step1);

            WebAutomationStep step2 = new WebAutomationStep()
            {
                AllowParallelThreads = false,
                StepNo        = 2,
                StepType      = Library.Models.Enums.AutomationStepType.InputText,
                InputValue    = "game of thrones",
                FindElementBy = Library.Models.Enums.AutomationFindElementBy.ByXPath,
                FindByValue   = ".//*[@name='q']"
            };

            helper.Run(driver, step2);

            WebAutomationStep step3 = new WebAutomationStep()
            {
                AllowParallelThreads = false,
                StepNo        = 2,
                StepType      = Library.Models.Enums.AutomationStepType.ClickElement,
                FindElementBy = Library.Models.Enums.AutomationFindElementBy.ByXPath,
                FindByValue   = ".//*[@aria-label='Google Search']"
            };

            helper.Run(driver, step3);
        }