private static object CreateProxyObject(Type memberType, IElementLocator locator, IEnumerable <By> bys, bool cache) { object result = null; if (memberType == typeof(IList <IWebElement>)) { using (List <Type> .Enumerator enumerator = CustomPageObjectMemberDecorator.InterfacesToBeProxied.GetEnumerator()) { while (enumerator.MoveNext()) { Type current = enumerator.Current; Type type = typeof(IList <>).MakeGenericType(new Type[] { current }); if (type.Equals(memberType)) { result = WebElementListProxy.CreateProxy(memberType, locator, bys, cache); break; } } return(result); } } if (!(memberType == typeof(IWebElement))) { throw new ArgumentException("Type of member '" + memberType.Name + "' is not IWebElement or IList<IWebElement>"); } result = WebElementProxy.CreateProxy(CustomPageObjectMemberDecorator.InterfaceProxyType, locator, bys, cache); return(result); }
public void LinqToArrayShouldRetrieveElementsOnce() { var elements = new WebElementListProxy(new DefaultElementLocator(driverMock.Object), new[] { by }, false); var texts = elements.ToArray(); driverMock.Verify(_ => _.FindElements(by), Times.Once); }
public void LinqWhereShouldRetrieveElementsOnce() { var elements = new WebElementListProxy(new DefaultElementLocator(driverMock.Object), new[] { by }, false); var texts = elements.Where(e => e.Text == "a").ToList(); driverMock.Verify(_ => _.FindElements(by), Times.Once); }
public bool CreateObject(Type memberType, IElementLocator locator, IEnumerable <By> bys, bool cache, [NotNullWhen(true)] out object?createdObject) { createdObject = null; if (memberType == typeof(IList <IWebElement>)) { createdObject = new WebElementListProxy(locator, bys, cache); return(true); } return(false); }
private object DecorateObject(MemberInfo member, IElementLocator locator) { FieldInfo field = member as FieldInfo; PropertyInfo property = member as PropertyInfo; if (field == null && (property == null || !property.CanWrite)) { return(null); } Type targetType = GetTargetType(member); IList <By> bys = CreateLocatorList(member); if (bys.Any()) { bool cache = DefaultPageObjectMemberDecoratorProxy.ShouldCacheLookup(member); object result; if (typeof(WebElement).IsAssignableFrom(targetType)) { var proxyElement = new WebElementProxy(typeof(IWebElement), locator, bys, cache); var args = new object[] { proxyElement, this._driver }; result = Activator.CreateInstance(targetType, args); } else if (typeof(IWebElement).IsAssignableFrom(targetType)) { result = new WebElementProxy(typeof(IWebElement), locator, bys, cache).GetTransparentProxy(); } else if (typeof(IList <WebElement>).IsAssignableFrom(targetType)) { throw new NotImplementedException(); //var proxyElements = new ProxyListElement(locator, bys, cache); //var args = new object[] { proxyElements, this._driver }; //result = Activator.CreateInstance(targetType, args); } else if (targetType == typeof(IList <IWebElement>)) { result = new WebElementListProxy(typeof(IList <IWebElement>), locator, bys, cache).GetTransparentProxy(); } else { throw new Exception($"Undefined type of element: '{targetType?.FullName}'"); } return(result); } return(null); }
private static object CreateProxyObject(Type memberType, string name, IElementLocator locator, IEnumerable <By> bys, string containerId, IReporter reporter) { object proxyObject = null; if (memberType == typeof(IWebElement)) { proxyObject = WebElementProxy.CreateProxy(InterfaceProxyType, locator, bys, name, containerId, reporter); } else if (memberType == typeof(IList <IWebElement>)) { proxyObject = WebElementListProxy.CreateProxy(memberType, locator, bys, name, containerId, reporter); } else { throw new ArgumentException("Type of member '" + memberType.Name + "' is not IWebElement or IList<IWebElement>."); } return(proxyObject); }