示例#1
0
        public virtual TPage GetPageValues(int seconds = 5)
        {
            try
            {
                if (SeleniumUtil.WaitElement(_driver, GetBySelector(_selector.GetFields[0]), seconds).Displayed)
                {
                    PageValues = new List <string>();
                    for (int i = 0; i < _selector.GetFields.Length; i++)
                    {
                        var element   = _driver.FindElement(GetBySelector(_selector.GetFields[i]));
                        var textValue = (_driver as IJavaScriptExecutor).ExecuteScript($"return arguments[0].value", element) as string;

                        if (textValue is null)
                        {
                            textValue = _driver.FindElement(GetBySelector(_selector.GetFields[i])).Text;
                        }

                        PageValues.Add(textValue);
                    }
                }
            }
            catch (System.Exception)
            {
                throw;
            }
            return(ChangeType(this, typeof(TPage)) as TPage);
        }
示例#2
0
        public virtual TPage GetPageValues <TModel>(int propertyShift = 0) where TModel : new()
        {
            var properties = typeof(TModel).GetProperties();

            if (properties.Length < _selector.GetFields.Length)
            {
                throw new SelectorException($"The number of properties ({properties.Length}) in the model '{typeof(TModel).Name}' must be greater than or equal to the number of 'GetFields' selectors: {_selector.GetFields.Length}");
            }

            try
            {
                if (SeleniumUtil.WaitElement(_driver, GetBySelector(_selector.GetFields[0])).Displayed)
                {
                    PageValues = new TModel();

                    for (int i = 0; i < _selector.GetFields.Length; i++)
                    {
                        var element   = _driver.FindElement(GetBySelector(_selector.GetFields[i]));
                        var textValue = (_driver as IJavaScriptExecutor).ExecuteScript($"return arguments[0].value", element) as string;

                        if (textValue is null)
                        {
                            textValue = _driver.FindElement(GetBySelector(_selector.GetFields[i])).Text;
                        }

                        properties[i + propertyShift].SetValue(PageValues, textValue);
                    }
                }
            }
            catch (System.Exception)
            {
                throw;
            }
            return(ChangeType(this, typeof(TPage)) as TPage);
        }
示例#3
0
 public virtual bool HasTableResults(int seconds = 5)
 {
     try
     {
         if (SeleniumUtil.WaitElement(_driver, GetBySelector(_selector.Table), seconds).Displayed)
         {
             return(_driver.FindElements(GetBySelector(_selector.Table)).Any());
         }
     }
     catch (System.Exception)
     {
         return(false);
     }
     return(false);
 }
示例#4
0
        public virtual TPage WaitLoad(int seconds = 2)
        {
            if (string.IsNullOrEmpty(_selector.LoadElement))
            {
                throw new SelectorException("The selector for 'LoadElement' property hasn't been configured.");
            }
            try
            {
                while (SeleniumUtil.WaitElement(_driver, GetBySelector(_selector.LoadElement), 1).Displayed)
                {
                    System.Threading.Thread.Sleep(1000 * seconds);
                }
            } catch {}

            return(ChangeType(this, typeof(TPage)) as TPage);
        }
示例#5
0
        public virtual TPage PerformClick(int buttonIndex, int seconds = 5)
        {
            if (buttonIndex >= _selector.PageButtons.Length)
            {
                throw new SelectorException($"The button index ({buttonIndex}) is greater than the number of 'PageButtons' selectors: {_selector.PageButtons.Length}.");
            }

            if (SeleniumUtil.WaitElement(_driver, GetBySelector(_selector.PageButtons[buttonIndex]), seconds).Displayed)
            {
                var element = _driver.FindElement(GetBySelector(_selector.PageButtons[buttonIndex]));

                try{ element.Click(); }
                catch { (_driver as IJavaScriptExecutor).ExecuteScript($@"arguments[0].click()", element); }

                System.Threading.Thread.Sleep(500);
            }
            return(ChangeType(this, typeof(TPage)) as TPage);
        }
示例#6
0
        public virtual TPage SetPageValues(string value, int selectorIndex)
        {
            try
            {
                if (selectorIndex > _selector.SetFields.Length)
                {
                    throw new SelectorException($"The informed selector index ({selectorIndex}) must be less than or equal to the number of 'SetFields' selectors count: {_selector.SetFields.Length}");
                }

                if (SeleniumUtil.WaitElement(_driver, GetBySelector(_selector.SetFields[selectorIndex])).Displayed)
                {
                    HandleInputType(_selector.SetFields[selectorIndex], value);
                }
            }
            catch (System.Exception)
            {
                throw;
            }
            return(ChangeType(this, typeof(TPage)) as TPage);
        }
示例#7
0
        public virtual TPage SetPageValues(int selectOption, int selectorIndex)
        {
            try
            {
                if (selectorIndex > _selector.SetFields.Length)
                {
                    throw new SelectorException($"The informed selector index ({selectorIndex}) must be less than or equal to the number of 'SetFields' selectors count: {_selector.SetFields.Length}");
                }

                if (SeleniumUtil.WaitElement(_driver, GetBySelector(_selector.SetFields[selectorIndex])).Displayed)
                {
                    var element = _driver.FindElement(GetBySelector(_selector.SetFields[selectorIndex]));
                    (_driver as IJavaScriptExecutor).ExecuteScript($@"arguments[0].selectedIndex={selectOption}", element);
                }
            }
            catch (System.Exception)
            {
                throw;
            }
            return(ChangeType(this, typeof(TPage)) as TPage);
        }
示例#8
0
        public virtual TPage SetPageValues(params string[] pageValues)
        {
            try
            {
                if (pageValues.Length > _selector.SetFields.Length)
                {
                    throw new SelectorException($"The entry values ({pageValues.Length}) must be less than or equal to the number of 'SetFields' selectors count: {_selector.SetFields.Length}");
                }

                if (SeleniumUtil.WaitElement(_driver, GetBySelector(_selector.SetFields[0])).Displayed)
                {
                    for (int i = 0; i < pageValues.Length; i++)
                    {
                        HandleInputType(_selector.SetFields[i], pageValues[i]);
                    }
                }
            }
            catch (System.Exception)
            {
                throw;
            }
            return(ChangeType(this, typeof(TPage)) as TPage);
        }
示例#9
0
        public virtual TPage GetTableInstances(params string[] tableValues)
        {
            if (tableValues is null || tableValues.All(el => string.IsNullOrEmpty(el)))
            {
                throw new ArgumentException("Can't perform the action due to the lack of entry values.");
            }

            if (tableValues.Length > _selector.TableFields.Length)
            {
                throw new SelectorException($"The number of entry values ({tableValues.Length}) doesn't match the length of 'TableFields' selectors: {_selector.TableFields.Length}.");
            }

            if (SeleniumUtil.WaitElement(_driver, GetBySelector(_selector.Table)).Displayed)
            {
                var table = _driver.FindElements(GetBySelector(_selector.Table));
                TableInstances = new List <IWebElement>();

                foreach (var element in table)
                {
                    var assertCount = 0;
                    for (int i = 0; i < tableValues.Length; i++)
                    {
                        if (element.FindElement(GetBySelector(_selector.TableFields[i])).Text.Equals(tableValues[i]))
                        {
                            assertCount++;
                        }
                    }

                    if (assertCount == tableValues.Length)
                    {
                        TableInstances.Add(element);
                    }
                }
            }
            return(ChangeType(this, typeof(TPage)) as TPage);
        }