Exemplo n.º 1
0
        public void Execute(IDictionary<string, object> variables, Dictionary<string, ObjectInfo> library, string[] parameters)
        {
            Console.WriteLine("ClickElementN.Execute");

            var browser = (IWebDriver)variables["BrowserInstance"];
            if (browser != null)
            {
                ObjectInfo objInfo = null;
                switch (parameters[0])
                {
                    case "library":
                        {
                            objInfo = library[parameters[1]];

                            break;
                        }
                    default:
                        {
                            objInfo = new ObjectInfo() { Name = "", Type = parameters[0], Value = parameters[1] };
                            break;
                        }
                }

                if (objInfo != null)
                {

                    int elIndex = Int32.Parse(parameters[2]);
                    IWebElement el = KeywordUtility.FindElementByIndex(browser, objInfo, elIndex);
                    if (el != null)
                    {
                        if (el.TagName == "button")
                        {
                            el.SendKeys(Keys.Enter);
                        }
                        else
                        {
                            el.Click();
                        }
                    }
                    else
                    {
                        throw new TestingException("Element not found!");
                    }
                }
            }
            else
            {
                throw new TestingException("Browser Instance not found!");
            }
        }
Exemplo n.º 2
0
        public void ExecuteWithFunc(IDictionary<string, object> variables, Dictionary<string, ObjectInfo> library,
            string[] parameters, Action<IWebElement, IWebDriver, string[]> handleElement)
        {
            var browser = (IWebDriver)variables["BrowserInstance"];
            if (browser != null)
            {

                ObjectInfo objInfo = null;
                switch (parameters[0])
                {
                    case "library":
                        {
                            objInfo = library[parameters[1]];

                            break;
                        }
                    default:
                        {
                            objInfo = new ObjectInfo()
                            {
                                Name = "",
                                Type = parameters[0],
                                Value = parameters[1],
                                Extra = parameters.Length > 2 ? parameters[2] : string.Empty
                            };
                            break;
                        }
                }

                if (objInfo != null)
                {

                    IWebElement el = KeywordUtility.FindElement(this, browser, objInfo);

                    if (el != null)
                    {
                        handleElement(el, browser, parameters);
                    }
                    else
                    {
                        throw new TestingException("Element not found!");
                    }
                }
            }
            else
            {
                throw new TestingException("Browser Instance not found!");
            }
        }
Exemplo n.º 3
0
        public static IWebElement FindElementByIndex(IWebDriver browser, ObjectInfo objInfo, int index)
        {
            var getby = GetBy(objInfo);

            IWebElement el = _wait.Until(d =>
            {
                var elements = browser.FindElements(getby);

                if (elements.Count > 0)
                {
                    return elements[index];
                }
                return null;
            });
            return el;
        }
Exemplo n.º 4
0
        public static IWebElement FindElement(Keyword keyword, IWebDriver driver, ObjectInfo objInfo)
        {
            _browser = driver;

            _wait = new WebDriverWait(_browser, TimeSpan.FromSeconds(WaitSeconds));

            _browser.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(WaitSeconds));

            var el = GetByLabel(keyword, objInfo);

            if (el == null)
            {
                var getby = GetBy(objInfo);

                el = _wait.Until(ExpectedConditions.ElementIsVisible(getby));
            }

            return el;
        }
Exemplo n.º 5
0
        public static void ReadConfiguration(Dictionary<string, ObjectInfo> library, string libraryFile)
        {
            XSSFWorkbook xssfwb;
            using (FileStream file = new FileStream(libraryFile, FileMode.Open, FileAccess.Read))
            {
                xssfwb = new XSSFWorkbook(file);
            }

            ISheet sheet = xssfwb.GetSheetAt(0); //get the first sheet
            for (int row = 1; row <= sheet.LastRowNum; row++)
            {
                if (sheet.GetRow(row) != null) //null is when the row only contains empty cells
                {
                    var name = sheet.GetRow(row).GetCell(0).ToString();
                    var value = new ObjectInfo()
                    {
                        Name = name,
                        Type = sheet.GetRow(row).GetCell(1).ToString(),
                        Value = sheet.GetRow(row).GetCell(2).ToString()
                    };
                    library.Add(name, value);
                }
            }
        }
Exemplo n.º 6
0
        public void Execute(IDictionary<string, object> variables, Dictionary<string, ObjectInfo> library, string[] parameters)
        {
            Console.WriteLine("DragAndDrop.Execute");

            var browser = (IWebDriver)variables["BrowserInstance"];
            if (browser != null)
            {
                ObjectInfo objInfo = null;
                ObjectInfo objInfo2 = null;
                IWebElement el = null;
                IWebElement el2 = null;

                //Find Element #1
                switch (parameters[0])
                {
                    case "library":
                    {
                        objInfo = library[parameters[1]];

                        break;
                    }
                    default:
                    {
                        objInfo = new ObjectInfo() {Name = "", Type = parameters[0], Value = parameters[1]};
                        break;
                    }
                }

                if (objInfo != null)
                {
                    switch (objInfo.Type)
                    {
                        case "id":
                            el = browser.FindElement(By.Id(objInfo.Value));
                            break;
                        case "xpath":
                            el = browser.FindElement(By.XPath(objInfo.Value));
                            break;
                        case "name":
                            el = browser.FindElement(By.Name(objInfo.Value));
                            break;
                        case "cssselector":
                            el = browser.FindElement(By.CssSelector(objInfo.Value));
                            break;
                        case "classname":
                            el = browser.FindElement(By.ClassName(objInfo.Value));
                            break;
                        case "linktext":
                            el = browser.FindElement(By.LinkText(objInfo.Value));
                            break;
                        case "partiallinktext":
                            el = browser.FindElement(By.PartialLinkText(objInfo.Value));
                            break;
                    }

                    if (el == null) throw new TestingException("Element #1 not found!");
                }
                else throw new TestingException("Element #1 invalid parameters!");

                //find Element #2
                switch (parameters[2])
                {
                    case "library":
                        {
                            objInfo2 = library[parameters[3]];

                            break;
                        }
                    default:
                        {
                            objInfo2 = new ObjectInfo() { Name = "", Type = parameters[2], Value = parameters[3] };
                            break;
                        }
                }

                if (objInfo2 != null)
                {
                    switch (objInfo2.Type)
                    {
                        case "id":
                            el2 = browser.FindElement(By.Id(objInfo2.Value));
                            break;
                        case "xpath":
                            el2 = browser.FindElement(By.XPath(objInfo2.Value));
                            break;
                        case "name":
                            el2 = browser.FindElement(By.Name(objInfo2.Value));
                            break;
                        case "cssselector":
                            el2 = browser.FindElement(By.CssSelector(objInfo2.Value));
                            break;
                        case "classname":
                            el2 = browser.FindElement(By.ClassName(objInfo2.Value));
                            break;
                        case "linktext":
                            el2 = browser.FindElement(By.LinkText(objInfo2.Value));
                            break;
                        case "partiallinktext":
                            el2 = browser.FindElement(By.PartialLinkText(objInfo2.Value));
                            break;
                    }

                    if (el2 == null) throw new TestingException("Element #2 not found!");
                }
                else throw new TestingException("Element #2 invalid parameters!");

                //dragdrop(browser, el, el2);
                var touch = new TouchActions(browser);
                touch.Down(el.Location.X + 5, el.Location.Y + 5).MoveToElement(el2).Release().Build().Perform();
                //Actions myMouse = new Actions(browser);
                //myMouse.MoveToElement(el, 5, 5).ClickAndHold().MoveToElement(el2, 5, 5).Release().Build().Perform();
                ////myMouse.DragAndDrop(el, el2);
            }
            else
            {
                throw new TestingException("Browser Instance not found!");
            }
        }
Exemplo n.º 7
0
        private static IWebElement GetByLabel(Keyword keyword, ObjectInfo objInfo)
        {
            IWebElement el = null;
            switch (objInfo.Type.ToLower())
            {

                case "bycontext":                   //ByContext
                    switch (keyword.GetType().Name)
                    {
                        case "SendKeys":
                            el = FindTargetByContext(objInfo.Value, TextboxSelector);
                            break;
                        case "SendKeysInEditor":
                            //el = FindEditorByContext(objInfo.Value);
                            el = FindTargetByContext(objInfo.Value, "iframe");
                            break;
                        case "ClickExtCheckbox":
                            el = FindTargetByContext(objInfo.Value, ExtJsCheckboxSelector);
                            break;
                        case "SelectExtJSCombo":
                            el = FindTargetByContext(objInfo.Value, TextboxSelector);
                            break;
                        default:
                            el = FindTargetByContext(objInfo.Value, ClickableSelector, objInfo.Extra);

                            break;
                    }
                    break;
                case "byinnertext":                 //ByInnerText
                    el = FindClickableByInnerText(objInfo.Value, objInfo.Extra);
                    break;

            }
            return el;
        }
Exemplo n.º 8
0
        private static OpenQA.Selenium.By GetBy(ObjectInfo objInfo)
        {
            OpenQA.Selenium.By by = null;
            switch (objInfo.Type.ToLower())
            {
                case "id":
                    @by = By.Id(objInfo.Value);
                    break;
                case "xpath":
                    @by = By.XPath(objInfo.Value);
                    break;
                case "name":
                    @by = By.Name(objInfo.Value);
                    break;
                case "cssselector":
                    @by = By.CssSelector(objInfo.Value);
                    break;
                case "classname":
                    @by = By.ClassName(objInfo.Value);
                    break;
                case "linktext":
                    @by = By.LinkText(objInfo.Value);
                    break;
                case "partiallinktext":
                    @by = By.PartialLinkText(objInfo.Value);
                    break;

            }
            return @by;
        }