public void ShouldLimitPropertiesAccess( ElementAttributeAccessModifier scope, string expectedId, string expectedText, string expectedClr) { UiDispatch.Invoke( () => { var element = CreateTestElement(); var winiumElement = new WiniumElement(element); var auotmationId = GetElementAttributeCommand.GetPropertyCascade( winiumElement, "AutomationProperties.AutomationId", scope); var text = GetElementAttributeCommand.GetPropertyCascade(winiumElement, "Text", scope); var clr = GetElementAttributeCommand.GetPropertyCascade(winiumElement, "ClrProperty", scope); Assert.AreEqual(expectedId, auotmationId); Assert.AreEqual(expectedText, text); Assert.AreEqual(expectedClr, clr); }).Wait(); }
internal static object GetPropertyCascade( WiniumElement element, string key, ElementAttributeAccessModifier options) { object propertyObject; if (element.TryGetAutomationProperty(key, out propertyObject)) { return(propertyObject); } if (options == ElementAttributeAccessModifier.AutomationProperties) { return(null); } if (element.TryGetDependencyProperty(key, out propertyObject)) { return(propertyObject); } if (options == ElementAttributeAccessModifier.DependencyProperties) { return(null); } if (element.TryGetProperty(key, out propertyObject)) { return(propertyObject); } return(null); }
public string RegisterElement(WiniumElement element) { var registeredKey = this.registredElements.FirstOrDefault(x => x.Value.Equals(element)).Key; if (registeredKey == null) { registeredKey = GenerateGuid(element); this.registredElements.Add(registeredKey, element); } return(registeredKey); }
internal static void WriteElementToXml(XmlWriter writer, WiniumElement element) { if (element == null) { return; } var className = element.ClassName; var tagName = XmlConvert.EncodeNmToken(className); writer.WriteStartElement(tagName); var rect = element.GetRect(); var attributes = new Dictionary <string, string> { { "name", element.AutomationName }, { "id", element.AutomationId }, { "class_name", className }, { "xname", element.XName }, { "visible", element.IsUserVisible().ToString().ToLowerInvariant() }, { "value", element.GetText() }, { "x", rect.X.ToString(CultureInfo.InvariantCulture) }, { "y", rect.Y.ToString(CultureInfo.InvariantCulture) }, { "width", rect.Width.ToString(CultureInfo.InvariantCulture) }, { "height", rect.Height.ToString(CultureInfo.InvariantCulture) }, { "clickable_point", element.GetCoordinatesInView() .ToString(CultureInfo.InvariantCulture) } }; foreach (var attribute in attributes) { writer.WriteAttributeString(attribute.Key, attribute.Value); } foreach (var child in element.Find(TreeScope.Children, x => true)) { WriteElementToXml(writer, child); } writer.WriteEndElement(); }
public void ShouldEncodeTagName() { UiDispatch.Invoke( () => { var winiumElement = new WiniumElement(new TestControl()); var sb = new StringBuilder(); using (var writer = XmlWriter.Create(sb)) { PageSourceCommand.WriteElementToXml(writer, winiumElement); } var doc = new XmlDocument(); doc.LoadXml(sb.ToString()); var element = doc.DocumentElement; Assert.AreEqual(XmlConvert.EncodeLocalName(winiumElement.ClassName), element.LocalName); Assert.AreEqual(winiumElement.ClassName, element.GetAttribute("class_name")); }).Wait(); }
private static string GenerateGuid(WiniumElement element) { Interlocked.Increment(ref safeInstanceCount); return(element.GetHashCode() + "-" + safeInstanceCount.ToString(string.Empty, CultureInfo.InvariantCulture)); }
protected override string DoImpl() { var x = new WiniumElement(AutomationElement.RootElement); return(x.AsXml().ToString()); }
protected override string DoImpl() { var x = new WiniumElement(AutomationElement.RootElement); return x.AsXml().ToString(); }