public static HtmlElement CreateHtmlElementInstance(Type elementType) { if (typeof(HtmlElement).IsAssignableFrom(elementType)) { return(HtmlElementUtils.newInstance <HtmlElement>(elementType)); } throw new HtmlElementsException(string.Format("Type '{0}' isn't a derivative type of 'HtmlElement'", elementType)); }
public static TypifiedElement CreateTypifiedElementInstance(Type elementType, IWebElement elementToWrap) { if (typeof(TypifiedElement).IsAssignableFrom(elementType)) { return(HtmlElementUtils.newInstance <TypifiedElement>(elementType, elementToWrap)); } throw new HtmlElementsException(string.Format("Type '{0}' isn't a derivative type of 'TypifiedElement'", elementType)); }
private bool IsDecoratableField(FieldInfo field) { // TODO Protecting wrapped element from initialization basing on its name is unsafe. Think of a better way. if (HtmlElementUtils.IsWebElement(field) && field.Name != "wrappedElement") { return(true); } return(HtmlElementUtils.IsWebElementList(field) || HtmlElementUtils.IsHtmlElement(field) || HtmlElementUtils.IsHtmlElementList(field) || HtmlElementUtils.IsTypifiedElement(field) || HtmlElementUtils.IsTypifiedElementList(field)); }
/// <summary> /// Builds the by. /// </summary> /// <returns>The value.</returns> public override By BuildBy() { if (HtmlElementUtils.IsHtmlElement(Property) || HtmlElementUtils.IsHtmlElementList(Property)) { var type = HtmlElementUtils.IsHtmlElementList(Property) ? HtmlElementUtils.GetGenericParameterType(Property) : Property.PropertyType; return(BuildByFromHtmlElementAttributes(type)); } return(base.BuildBy()); }
/// <summary> /// Populates the specified instance. /// </summary> /// <param name="instance">The instance.</param> /// <param name="driver">The driver.</param> public static void Populate(object instance, IWebDriver driver) { if (HtmlElementUtils.IsHtmlElement(instance)) { var htmlElement = (HtmlElement)instance; PopulateHtmlElement(htmlElement, driver); } else { PopulatePageObject(instance, driver); } }
public override By BuildBy() { if (HtmlElementUtils.IsHtmlElement(Field) || HtmlElementUtils.IsHtmlElementList(Field)) { Type type = HtmlElementUtils.IsHtmlElementList(Field) ? HtmlElementUtils.GetGenericParameterType(Field) : Field.FieldType; return(BuildByFromHtmlElementAttributes(type)); } else { return(base.BuildBy()); } }
public override object Decorate(FieldInfo field) { //if (!IsDecoratableField(field)) //{ // return null; //} IElementLocator locator = factory.CreateLocator(field); if (locator == null) { return(null); } String elementName = HtmlElementUtils.GetElementName(field); //if (HtmlElementUtils.IsTypifiedElement(field)) //{ Type typifiedElementType = field.FieldType; return(DecorateTypifiedElement(typifiedElementType, locator, elementName)); //} if (HtmlElementUtils.IsHtmlElement(field)) { Type htmlElementType = field.FieldType; return(DecorateHtmlElement(htmlElementType, locator, elementName)); } else if (HtmlElementUtils.IsWebElement(field)) { return(DecorateWebElement(locator, elementName)); } //else if (HtmlElementUtils.IsTypifiedElementList(field)) //{ // Type typifiedElementType = HtmlElementUtils.GetGenericParameterType(field); // return DecorateTypifiedElementList(field.FieldType, typifiedElementType, locator, elementName); //} else if (HtmlElementUtils.IsHtmlElementList(field)) { Type htmlElementType = HtmlElementUtils.GetGenericParameterType(field); return(DecorateHtmlElementList(field.FieldType, htmlElementType, locator, elementName)); } else if (HtmlElementUtils.IsWebElementList(field)) { return(DecorateWebElementList(locator, elementName)); } return(null); }
/// <summary> /// Pointing input field to a file. /// Use file URI scheme or absolute path for separate files: file://host/path; eg. file://localhost/c:/WINDOWS/clock.avi /// Use Spring.Net notation for embedded resources: assembly://<AssemblyName>/<NameSpace>/<ResourceName>; eg. assembly://HtmlElements-DotNet/Yandex.HtmlElements/TestResource.txt /// For embedded resources the resource will be unpacked to a temp dir. /// </summary> /// <param name="fileName"></param> public void SetFileToUpload(string fileName) { // Proxy can't be used to check the element class, so find real WebElement IWebElement fileInputElement = GetNotProxiedInputElement(); // Set local file detector in case of remote driver usage if (HtmlElementUtils.IsOnRemoteWebDriver(fileInputElement)) { SetLocalFileDetector((RemoteWebElement)fileInputElement); } string filePath = GetFilePath(fileName); fileInputElement.SendKeys(filePath); }
private string GetFilePath(string path) { Uri fileUri = null; try { fileUri = new Uri(path); if (fileUri.Scheme == AssemblyScheme) { return(HtmlElementUtils.ExtractResource(fileUri)); } } catch { } return(GetPathForSystemFile(path)); }
/// <summary> /// Decorates the specified property info. /// </summary> /// <param name="propertyInfo">The property info.</param> /// <returns>The value.</returns> public override object Decorate(PropertyInfo propertyInfo) { if (!IsDecoratableProperty(propertyInfo)) { return(null); } var locator = Factory.CreateLocator(propertyInfo); if (locator == null) { return(null); } var elementName = HtmlElementUtils.GetElementName(propertyInfo); if (HtmlElementUtils.IsTypifiedElement(propertyInfo)) { var typifiedElementType = propertyInfo.PropertyType; return(DecorateTypifiedElement(typifiedElementType, locator, elementName)); } if (HtmlElementUtils.IsHtmlElement(propertyInfo)) { var htmlElementType = propertyInfo.PropertyType; return(DecorateHtmlElement(htmlElementType, locator, elementName)); } if (HtmlElementUtils.IsWebElement(propertyInfo)) { return(DecorateWebElement(locator, elementName)); } if (HtmlElementUtils.IsTypifiedElementList(propertyInfo)) { var typifiedElementType = HtmlElementUtils.GetGenericParameterType(propertyInfo); return(DecorateTypifiedElementList(propertyInfo.PropertyType, typifiedElementType, locator, elementName)); } if (HtmlElementUtils.IsHtmlElementList(propertyInfo)) { var htmlElementType = HtmlElementUtils.GetGenericParameterType(propertyInfo); return(DecorateHtmlElementList(propertyInfo.PropertyType, htmlElementType, locator, elementName)); } if (HtmlElementUtils.IsWebElementList(propertyInfo)) { return(DecorateWebElementList(locator, elementName)); } return(null); }
public static T Create <T>(IWebDriver driver) { object result; Type type = typeof(T); if (HtmlElementUtils.IsHtmlElement(type)) { result = HtmlElementFactory.CreateHtmlElementInstance(type); PopulateHtmlElement((HtmlElement)result, new HtmlElementLocatorFactory(driver)); } else { result = (T)HtmlElementFactory.CreatePageObjectInstance(type, driver); PopulatePageObject(result, new HtmlElementLocatorFactory(driver)); } return((T)result); }
private IList <T> ToTypifiedElements <T>() where T : TypifiedElement { IList <T> typifiedElements = new List <T>(); IList <IWebElement> elements = WrappedElements; Type typifiedElementType = typeof(T); int elementNumber = 0; foreach (IWebElement element in elements) { T typifiedElement = (T)Convert.ChangeType(HtmlElementUtils.newInstance <TypifiedElement>(typifiedElementType, element), typifiedElementType); string typifiedElementName = string.Format("{0} {1}", name, elementNumber); typifiedElement.Name = typifiedElementName; typifiedElements.Add(typifiedElement); elementNumber++; } return(typifiedElements); }
/// <summary> /// Populates the HTML element. /// </summary> /// <param name="htmlElement">The HTML element.</param> /// <param name="locatorFactory">The locator factory.</param> private static void PopulateHtmlElement(HtmlElement htmlElement, CustomElementLocatorFactory locatorFactory) { var htmlElementType = htmlElement.GetType(); // Create locator that will handle Block annotation var locator = locatorFactory.CreateLocator(htmlElementType); // The next line from Java code located here till I find a solution to replace ClassLoader // ClassLoader htmlElementClassLoader = htmlElement.getClass().getClassLoader(); // Initialize block with IWebElement proxy and set its name var elementName = HtmlElementUtils.GetElementName(htmlElementType); var elementToWrap = HtmlElementFactory.CreateNamedProxyForWebElement(locator, elementName); htmlElement.WrappedElement = elementToWrap; htmlElement.Name = elementName; // Initialize elements of the block PageFactory.InitElements(new HtmlElementDecorator(elementToWrap), htmlElement); }
/// <summary> /// Creates the page object instance. /// </summary> /// <param name="type">The type.</param> /// <param name="driver">The driver.</param> /// <returns>The value.</returns> public static object CreatePageObjectInstance(Type type, IWebDriver driver) { return(HtmlElementUtils.NewInstance <object>(type, driver)); }