public void ActionsDragAndDrop(WebElement source, WebElement target, ILogger log)
        {
            var eSource = Find(source, log);
            var eTarget = Find(target, log);

            try
            {
                log?.INFO($"Actions drag from {source.Name} to {target.Name}");
                new Actions(_container.Value.Driver).MoveToElement(eSource).ClickAndHold(eSource).MoveToElement(eTarget).Release(eTarget).Build().Perform();
                log?.INFO("Actions drag and drop completed");
            }
            catch (Exception ex)
            {
                log?.ERROR($"Error occurred during actions drag and drop: from {source.Name} to {target.Name}");
                throw new CommandAbortException($"Error occurred during actions drag and drop: from {source.Name} to {target.Name}", ex);
            }
        }
Exemple #2
0
 public IWebElement Find(WebElement element, ILogger log)
 {
     log?.DEBUG($"Start searching element: {element.Name}");
     log?.TRACE($"{element}");
     try
     {
         _sw.Value.Reset();
         var el = _container.Value._driver.FindElement(element.Locator.Get());
         _sw.Value.Stop();
         log?.DEBUG($"Element: {element.Name} has been found. Time: {_sw.Value.ElapsedMilliseconds} ms");
         return el;
     }
     catch (Exception ex)
     {
         log?.ERROR("Couldn't find element");
         throw new CommandAbortException("Couldn't find element", ex);
     }
 }
        public void ActionsDoubleClick(WebElement element, ILogger log)
        {
            var el = Find(element, log);

            WaitUntilElementIsVisible(el, log);
            WaitUntilElementIsEnabled(el, log);

            try
            {
                log?.INFO($"Actions double click on element: {element.Name}");
                new Actions(_container.Value.Driver).DoubleClick(el).Build().Perform();
                log?.INFO("Actions double click completed");
            }
            catch (Exception ex)
            {
                log?.ERROR($"Error occurred during actions double-clicking on element: {element.Name}");
                throw new CommandAbortException($"Error occurred actions during-clicking on element: {element.Name}", ex);
            }
        }
        public void ActionsMoveTo(WebElement element, ILogger log)
        {
            var el = Find(element, log);

            WaitUntilElementIsVisible(el, log);
            WaitUntilElementIsEnabled(el, log);

            try
            {
                log?.INFO($"Move to element: {element.Name}");
                new Actions(_container.Value.Driver).MoveToElement(el).Build().Perform();
                log?.INFO("Move to completed");
            }
            catch (Exception ex)
            {
                log?.ERROR($"Error occurred moving to element: {element.Name}");
                throw new CommandAbortException($"Error occurred moving to element: {element.Name}", ex);
            }
        }
Exemple #5
0
        public void Click(WebElement element, ILogger log)
        {
            var el = Find(element, log);

            WaitUntilElementIsVisible(el, log);
            WaitUntilElementIsEnabled(el, log);

            try
            {
                log?.INFO($"Click on element: {element.Name}");
                el.Click();
                log?.INFO("Click completed");
            }
            catch (Exception ex)
            {
                log?.ERROR($"Error occurred during clicking on element: {element.Name}");
                throw new CommandAbortException($"Error occurred during clicking on element: {element.Name}", ex);
            }
        }
Exemple #6
0
        public void JSExecutor(string jsScript, WebElement element, ILogger log)
        {
            var el = Find(element, log);

            WaitUntilElementIsVisible(el, log);
            WaitUntilElementIsEnabled(el, log);

            try
            {
                log?.INFO($"Execute javascript: {jsScript}");
                _container.Value.JavaScriptExecutor.ExecuteScript(jsScript, el);
                log?.INFO("Javascript executing completed");
            }
            catch (Exception ex)
            {
                log?.ERROR($"Error occurred during execution: {jsScript}");
                throw new CommandAbortException($"Error occurred during javascript execution:\n{jsScript}\nFor element: {element}", ex);
            }
        }
        public void ActionsSendKeys(WebElement element, string value, ILogger log)
        {
            var el = Find(element, log);

            WaitUntilElementIsVisible(el, log);
            WaitUntilElementIsEnabled(el, log);

            try
            {
                log?.INFO($"Actions send keys to element: {element.Name}");
                new Actions(_container.Value.Driver).SendKeys(el, value).Build().Perform();
                log?.INFO("Actions send keys completed");
            }
            catch (Exception ex)
            {
                log?.ERROR($"Error occurred during actions keys sending to element: {element.Name}");
                throw new CommandAbortException($"Error occurred actions keys sending to element: {element.Name}", ex);
            }
        }
Exemple #8
0
 public void JSHide(WebElement webElement, ILogger log)
 {
     JSExecutor("arguments[0].style.display = none;", webElement, log);
 }
Exemple #9
0
 public void JSDoubleClick(WebElement webElement, ILogger log)
 {
     string jsScript = "var evObj = document.createEvent('MouseEvents');evObj.initMouseEvent(\"dblclick\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);arguments[0].dispatchEvent(evObj);";
     JSExecutor(jsScript, webElement, log);
 }
Exemple #10
0
 public void JSShow(WebElement webElement, ILogger log)
 {
     JSExecutor("arguments[0].style.display = block;",  webElement, log);
 }
Exemple #11
0
 public void JSScrollTo(WebElement webElement, ILogger log)
 {
     var elem = Find(webElement, log);
     JSExecutor($"window.scrollTo({elem.Location.X}, {elem.Location.Y})", log);
 }
Exemple #12
0
        public IWebElement Find(WebElement element, ILogger log)
        {
            log?.DEBUG($"Start searching element: {element.Name}");
            log?.TRACE($"{element}");
            try
            {
                _sw.Value.Start();

                var isDefaultContent = true;
                IWebElement targetElement = null;
                var parentStack = new Stack<WebElement>();

                for (var currentElement = element.ParentElement; currentElement != null; currentElement = currentElement.ParentElement)
                {
                    parentStack.Push(currentElement);
                }

                while (parentStack.Count != 0)
                {
                    var workElement = parentStack.Pop();

                    var frameElement = workElement as FrameWebElement;

                    if (frameElement != null)
                    {
                        SwitchToFrame(frameElement, log);
                        isDefaultContent = false;
                    }
                }

                if (element.Locator.IsRelative)
                {
                    for (var currentElement = element.ParentElement; currentElement != null && !(currentElement.Locator?.IsRelative ?? false); currentElement = currentElement.ParentElement)
                    {
                        var frameElement = currentElement as FrameWebElement;
                        if (frameElement == null)
                            parentStack.Push(currentElement);
                    }
                    if (parentStack.Count != 0)
                    {
                        var currentParent = parentStack.Pop();

                        log?.TRACE($"Start searching parent element: {currentParent.Name}");
                        log?.TRACE($"{currentParent}");
                        targetElement = _container.Value.Driver.FindElement(currentParent.Locator.Get());
                        log?.TRACE($"Parent element: {currentParent.Name} has been found");

                        while (parentStack.Count != 0)
                        {
                            currentParent = parentStack.Pop();
                            log?.TRACE($"Start searching target parent element: {currentParent.Name}");
                            log?.TRACE($"{currentParent}");
                            targetElement = targetElement.FindElement(currentParent.Locator.Get());
                            log?.TRACE($"Target parent element: {currentParent.Name} has been found");
                        }

                        log?.TRACE($"Start searching target element: {currentParent.Name}");
                        log?.TRACE($"{element}");
                        targetElement = targetElement.FindElement(element.Locator.Get());
                        log?.TRACE($"Target element: {element.Name} has been found");
                    }
                    else
                    {
                        log?.TRACE($"Start searching target parent element: {element.Name}");
                        log?.TRACE($"{element}");
                        targetElement = _container.Value.Driver.FindElement(element.Locator.Get());
                        log?.TRACE($"Target parent element: {element.Name} has been found");
                    }
                }
                else
                {
                    log?.TRACE($"Start searching target element: {element.Name}");
                    log?.TRACE($"{element}");
                    targetElement = _container.Value.Driver.FindElement(element.Locator.Get());
                    log?.TRACE($"Target element: {element.Name} has been found");
                }
                if (!isDefaultContent) SwitchToDefaultContent(log);

                _sw.Value.Stop();
                log?.INFO("Click completed");
                log?.TRACE($"Element: {element.Name} has been found. Time: {_sw.Value.ElapsedMilliseconds} ms");

                return targetElement;
            }
            catch (Exception ex)
            {
                log?.ERROR("Couldn't find element");
                throw new CommandAbortException($"Couldn't find element: {element.Name}", ex);
            }
        }
Exemple #13
0
        public void RightClick(WebElement element, ILogger log)
        {
            var el = Find(element, log);

            WaitUntilElementIsVisible(el, log);
            WaitUntilElementIsEnabled(el, log);

            try
            {
                log?.INFO($"Right click on element: {element.Name}");
                new Actions(_container.Value._driver).MoveToElement(el).ContextClick().Build().Perform();
                log?.INFO("Right click completed");
            }
            catch (Exception ex)
            {
                log?.ERROR($"Error occurred during right-clicking on element: {element.Name}");
                throw new CommandAbortException($"Error occurred during right-clicking on element: {element.Name}", ex);
            }
        }
Exemple #14
0
 public void JSExecutor(string jsScript, WebElement webElement)
 {
     try
     {
         _javaScriptExecutor.ExecuteScript(jsScript, webElement);
     }
     catch (Exception e)
     {
         string.Format("Error occurred during execution javascript:\n%s\nError message: %s", jsScript, e.Message);
         throw;
     }
 }
Exemple #15
0
 public void JSScrollTo(WebElement webElement)
 {
     JSExecutor($"window.scrollTo({webElement.Location.X}, {webElement.Location.Y})");
 }
Exemple #16
0
 public void JSHide(WebElement webElement)
 {
     JSExecutor("arguments[0].style.display = none;", webElement);
 }
Exemple #17
0
 public void JSMouseOver(WebElement webElement)
 {
     string jsScript = "var evObj = document.createEvent('MouseEvents');evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);arguments[0].dispatchEvent(evObj);";
     JSExecutor(jsScript, webElement);
 }
Exemple #18
0
 public void JSScrollIntoView(WebElement webElement, ILogger log)
 {
     JSExecutor($"arguments[0].scrollIntoView(true);", webElement, log);
 }
Exemple #19
0
        public void SendKeys(WebElement element, string value, ILogger log)
        {
            var el = Find(element, log);

            WaitUntilElementIsVisible(el, log);
            WaitUntilElementIsEnabled(el, log);

            try
            {
                log?.INFO($"Send keys '{value}' to element: {element.Name}");
                el.Click();
                el.Clear();
                el.SendKeys(value);
                log?.INFO($"Send keys '{value}' completed");
            }
            catch (Exception ex)
            {
                log?.ERROR($"Error occurred during keys '{value}' sending to element: {element.Name}");
                throw new CommandAbortException($"Error occurred keys '{value}' sending to element: {element.Name}", ex);
            }
        }