Esempio n. 1
0
        public virtual IList <T> FindElements <T>(By locator, string name = null, ElementSupplier <T> supplier = null, ElementsCount expectedCount = ElementsCount.Any, ElementState state = ElementState.Displayed) where T : IElement
        {
            var elementSupplier = ResolveSupplier(supplier);

            switch (expectedCount)
            {
            case ElementsCount.Zero:
                ConditionalWait.WaitForTrue(() => !ElementFinder.FindElements(locator, state, TimeSpan.Zero, name).Any(),
                                            message: LocalizationManager.GetLocalizedMessage("loc.elements.with.name.found.but.should.not", name, locator.ToString(), state.ToString()));
                break;

            case ElementsCount.MoreThenZero:
                ConditionalWait.WaitForTrue(() => ElementFinder.FindElements(locator, state, TimeSpan.Zero, name).Any(),
                                            message: LocalizationManager.GetLocalizedMessage("loc.no.elements.with.name.found.by.locator", name, locator.ToString()));
                break;

            case ElementsCount.Any:
                ConditionalWait.WaitFor(() => ElementFinder.FindElements(locator, state, TimeSpan.Zero, name) != null);
                break;

            default:
                throw new ArgumentOutOfRangeException($"No such expected value: {expectedCount}");
            }

            var             webElements = ElementFinder.FindElements(locator, state, TimeSpan.Zero, name);
            IEnumerable <T> elements    = webElements.Select((webElement, index) =>
            {
                var elementIndex = index + 1;
                var elementName  = $"{name ?? "element"} {elementIndex}";
                return(elementSupplier(GenerateXpathLocator(locator, webElement, elementIndex), elementName, state));
            });

            return(elements.ToList());
        }
Esempio n. 2
0
 /// <summary>
 /// Resolves element supplier or return itself if it is not null.
 /// </summary>
 /// <typeparam name="T">type of target element.</typeparam>
 /// <param name="supplier">target element supplier.</param>
 /// <param name="customSearchContextSupplier">Custom search context supplier to perform relative search for element.</param>
 /// <returns>non-null element supplier</returns>
 protected virtual ElementSupplier <T> ResolveSupplier <T>(ElementSupplier <T> supplier, Func <ISearchContext> customSearchContextSupplier)
     where T : CoreElement
 {
     if (supplier != null)
     {
         return(supplier);
     }
     else
     {
         var type        = typeof(T);
         var elementType = type.IsInterface ? ElementTypesMap[type] : type;
         var elementCntr = elementType.GetConstructor(
             BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.CreateInstance | BindingFlags.Instance,
             null,
             new[] { typeof(By), typeof(string), typeof(Func <ISearchContext>), typeof(Func <WindowsDriver <WindowsElement> >), typeof(ElementState) },
             null);
         if (elementCntr == null)
         {
             return(base.ResolveSupplier(supplier));
         }
         return((locator, name, state) => (T)elementCntr.Invoke(new object[] { locator, name, customSearchContextSupplier, driverSessionSupplier, state }));
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Resolves element supplier or return itself if it is not null
 /// </summary>
 /// <typeparam name="T">type of target element</typeparam>
 /// <param name="supplier">target element supplier</param>
 /// <returns>non-null element supplier</returns>
 protected virtual ElementSupplier <T> ResolveSupplier <T>(ElementSupplier <T> supplier) where T : IElement
 {
     if (supplier != null)
     {
         return(supplier);
     }
     else
     {
         var type        = typeof(T);
         var elementType = type.IsInterface ? ElementTypesMap[type] : type;
         var elementCntr = elementType.GetConstructor(
             BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.CreateInstance | BindingFlags.Instance,
             null,
             new[] { typeof(By), typeof(string), typeof(ElementState) },
             null);
         if (elementCntr == null)
         {
             throw new InvalidOperationException($"cannot resolve constructor with required arguments for type {type.FullName}." +
                                                 Environment.NewLine +
                                                 $"Either provide a non-null {nameof(ElementSupplier<T>)}, or extend {nameof(ElementFactory)} with {nameof(ElementTypesMap)} for required type");
         }
         return((locator, name, state) => (T)elementCntr.Invoke(new object[] { locator, name, state }));
     }
 }
Esempio n. 4
0
 protected virtual IList <T> FindElements <T>(By locator, string name = null, ElementSupplier <T> supplier = null, ElementsCount expectedCount = ElementsCount.Any, ElementState state = ElementState.Displayed) where T : IElement
 {
     return(ElementFactory.FindElements(locator, name, supplier, expectedCount, state));
 }
Esempio n. 5
0
 protected override ElementSupplier <T> ResolveSupplier <T>(ElementSupplier <T> supplier)
 {
     return(ResolveSupplier(supplier, searchContextSupplier));
 }
Esempio n. 6
0
        public override T FindChildElement <T>(CoreElement parentElement, By childLocator, string name = null, ElementSupplier <T> supplier = null, ElementState state = ElementState.Displayed)
        {
            var elementSupplier = ResolveSupplier(supplier, () => parentElement.GetElement());

            return(elementSupplier(childLocator, name ?? $"Child element of {parentElement.Name}", state));
        }
Esempio n. 7
0
 public virtual T GetCustomElement <T>(ElementSupplier <T> elementSupplier, By locator, string name, ElementState state = ElementState.Displayed) where T : IElement
 {
     return(elementSupplier(locator, name, state));
 }
Esempio n. 8
0
 public virtual IList <T> FindChildElements <T>(IElement parentElement, By childLocator, string name = null, ElementSupplier <T> supplier = null, ElementsCount expectedCount = ElementsCount.Any, ElementState state = ElementState.Displayed) where T : IElement
 {
     return(FindElements(GenerateAbsoluteChildLocator(parentElement.Locator, childLocator), name ?? $"Child element of {parentElement.Name}", supplier, expectedCount, state));
 }
Esempio n. 9
0
        public virtual T FindChildElement <T>(IElement parentElement, By childLocator, string name = null, ElementSupplier <T> supplier = null, ElementState state = ElementState.Displayed) where T : IElement
        {
            var elementSupplier = ResolveSupplier(supplier);

            return(elementSupplier(GenerateAbsoluteChildLocator(parentElement.Locator, childLocator), name ?? $"Child element of {parentElement.Name}", state));
        }
 public IList <T> FindChildElements <T>(By childLocator, string name = null, ElementSupplier <T> supplier = null, ElementsCount expectedCount = ElementsCount.Any, ElementState state = ElementState.Displayed) where T : IElement
 {
     return(Factory.FindChildElements(this, childLocator, name, supplier, expectedCount, state));
 }
 public T FindChildElement <T>(By childLocator, string name = null, ElementSupplier <T> supplier = null, ElementState state = ElementState.Displayed) where T : IElement
 {
     return(Factory.FindChildElement(this, childLocator, name, supplier, state));
 }
Esempio n. 12
0
 protected override IList <T> FindElements <T>(By locator, string name     = null, ElementSupplier <T> supplier    = null,
                                               ElementsCount expectedCount = ElementsCount.Any, ElementState state = ElementState.Displayed)
 {
     return(ParentElement.FindChildElements(locator, name, supplier, expectedCount, state));
 }
 /// <summary>
 /// Finds element relative to current form.
 /// </summary>
 /// <typeparam name="T">Type of the target element.</typeparam>
 /// <param name="childLocator">Locator of the element relative to current form.</param>
 /// <param name="childName">Name of the element.</param>
 /// <param name="supplier">Delegate that defines constructor of element in case of custom element.</param>
 /// <param name="elementState">Element existance state</param>
 /// <returns>Instance of element.</returns>
 protected virtual new T FindChildElement <T>(By childLocator, string childName, ElementSupplier <T> supplier = null, ElementState elementState = ElementState.Displayed)
     where T : IElement
 {
     return(RelativeElementFactory.FindChildElement(this, childLocator, GetChildElementName(childName), supplier, elementState));
 }