public object Decorate(MemberInfo member, IElementLocator locator) { FieldInfo field = member as FieldInfo; PropertyInfo property = member as PropertyInfo; Type targetType = null; targetType = field?.FieldType; bool hasPropertySet = false; if (property != null) { hasPropertySet = property.CanWrite; targetType = property?.PropertyType; } if (field == null & (property == null || !hasPropertySet)) { return(null); } if (field != null && (field.IsStatic || field.IsInitOnly)) { return(null); } Type aSingleElementType = GetTypeOfASingleElement(targetType, member); Type aListOfElementsType = null; if (GenericsUtility.MatchGenerics(typeof(IList <>), ListOfAvailableElementTypes, targetType)) { aListOfElementsType = targetType; } if (aSingleElementType == null & aListOfElementsType == null) { return(null); } ISearchContext context = locator.SearchContext; IEnumerable <By> bys = ByFactory.CreateBys(context, member); ProxyGenerator generator = new ProxyGenerator(); TimeOutDuration span = GetTimeWaitingForElements(member); bool shouldCache = (Attribute.GetCustomAttribute(member, typeof(CacheLookupAttribute), true) != null); if (aSingleElementType != null) { return(generator.CreateInterfaceProxyWithoutTarget(aSingleElementType, new Type[] { typeof(IWrapsDriver), typeof(IWrapsElement) }, ProxyGenerationOptions.Default, new ElementInterceptor(bys, locator, span, shouldCache))); } return(generator.CreateInterfaceProxyWithoutTarget(aListOfElementsType, ProxyGenerationOptions.Default, new ElementListInterceptor(bys, locator, span, shouldCache))); }
private static Type GetTypeOfASingleElement(Type targetType, MemberInfo member) { if (typeof(IWebElement).Equals(targetType)) { return(targetType); } else if (GenericsUtility.MatchGenerics(typeof(IMobileElement <>), ListOfAvailableElementTypes, targetType)) { return(targetType); } return(null); }
private static string GetPlatform(ISearchContext context) { IWebDriver driver = WebDriverUnpackUtility.UnpackWebdriver(context); if (driver == null) { return(null); } Type driverType = driver.GetType(); if (GenericsUtility.MatchGenerics(typeof(AndroidDriver <>), AppiumPageObjectMemberDecorator.ListOfAvailableElementTypes, driverType)) { return(MobilePlatform.Android); } if (GenericsUtility.MatchGenerics(typeof(IOSDriver <>), AppiumPageObjectMemberDecorator.ListOfAvailableElementTypes, driverType)) { return(MobilePlatform.IOS); } if (GenericsUtility.MatchGenerics(typeof(WindowsDriver <>), AppiumPageObjectMemberDecorator.ListOfAvailableElementTypes, driverType)) { return(MobilePlatform.Windows); } if (typeof(IHasCapabilities).IsAssignableFrom(driverType)) { IHasCapabilities hasCapabilities = (IHasCapabilities)driver; object platform = hasCapabilities.Capabilities.GetCapability(MobileCapabilityType.PlatformName); if (platform == null || string.IsNullOrEmpty(Convert.ToString(platform))) { platform = hasCapabilities.Capabilities.GetCapability(CapabilityType.Platform); } string convertedPlatform = Convert.ToString(platform); if (platform != null && !string.IsNullOrEmpty(convertedPlatform)) { return(convertedPlatform); } } return(null); }