public void DoesntCache( Mock <IWebElement> webElementMock, Mock <IElementLocator> elementLocatorMock, ICollection <By> bys) { elementLocatorMock.Setup(x => x.LocateElements(bys)) .Returns(new[] { webElementMock.Object }); var proxy = WebElementEnumerableProxy.Create(elementLocatorMock.Object, bys); proxy.Count(); proxy.Count(); elementLocatorMock.Verify(x => x.LocateElements(bys), Times.Exactly(2)); }
public void IsLazy( Mock <IWebElement> webElementMock, Mock <IElementLocator> elementLocatorMock, ICollection <By> bys) { elementLocatorMock.Setup(x => x.LocateElements(bys)) .Returns(new[] { webElementMock.Object }); var proxy = WebElementEnumerableProxy.Create(elementLocatorMock.Object, bys); elementLocatorMock.Verify(x => x.LocateElements(bys), Times.Never()); proxy.Count(); elementLocatorMock.Verify(x => x.LocateElements(bys), Times.Once()); }
/// <summary> /// Locates an element or list of elements for a Page Object member. /// </summary> /// <param name="typeToDecorate">The <see cref="Type"/> of the member to decorate</param> /// <param name="bys">The <see cref="By"> bys</see> provided to decorate the member with</param> /// <param name="elementLocator">The <see cref="IElementLocator"/> elementLocator to locate elements.</param> /// <returns>The Page Object's member value</returns> public object Decorate(Type typeToDecorate, IEnumerable <By> bys, IElementLocator elementLocator) { if (typeof(IWebElement).IsAssignableFrom(typeToDecorate)) { return(DecorateWebElement(elementLocator, bys)); } if (typeof(IWrapsElement).IsAssignableFrom(typeToDecorate)) { return(DecorateWrappedWebElement(typeToDecorate, elementLocator, bys)); } if (typeToDecorate.IsGenericType) { var genericTypeDefinition = typeToDecorate.GetGenericTypeDefinition(); var genericTypeArgument = typeToDecorate.GenericTypeArguments.Single(); if (typeof(IEnumerable <>).IsAssignableFrom(genericTypeDefinition)) { if (typeof(IWebElement).IsAssignableFrom(genericTypeArgument)) { return(WebElementEnumerableProxy.Create(elementLocator, bys)); } if (typeof(IWrapsElement).IsAssignableFrom(genericTypeArgument)) { var method = typeof(ProxyPageObjectMemberDecorator).GetMethod(nameof(DecorateEnumerableWrappedElement), new[] { typeof(IElementLocator), typeof(IEnumerable <By>) }); method = method.MakeGenericMethod(genericTypeArgument); var element = method.Invoke(this, new object[] { elementLocator, bys }); return(element); } } } throw new DecorationException($"Unable to decorate {typeToDecorate.Name}, it is unsupported"); }
public IEnumerable <T> DecorateEnumerableWrappedElement <T>(IElementLocator elementLocator, IEnumerable <By> bys) { return(WebElementEnumerableProxy.Create(elementLocator, bys) .Select(webElement => (T)CreateAndPopulateWrapsElement(typeof(T), webElement))); }