public void StringToElementTypeTest() { string s = string.Empty; // TODO: Initialize to an appropriate value DAL.ElementType expected = new DAL.ElementType(); // TODO: Initialize to an appropriate value DAL.ElementType actual; actual = DAL.StringToElementType(s); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
/// <summary> /// called when double shift-key press is detected /// </summary> /// <param name="currentElement"></param> private void analyzeElement(HtmlElement currentElement) { string tag = "", type = ""; elementNameTextBox.Text = ""; selectedElementListView.Items.Clear(); List <DAL.RecognitionProperty> props = new List <DAL.RecognitionProperty>(); WatiN.Core.Native.InternetExplorer.IEElement element = new WatiN.Core.Native.InternetExplorer.IEElement(currentElement.DomElement); mshtml.IHTMLDOMNode nd = (mshtml.IHTMLDOMNode)element.AsHtmlElement; mshtml.IHTMLAttributeCollection attribs = (mshtml.IHTMLAttributeCollection)nd.attributes; if ((currentElement.TagName != null) && (currentElement.TagName.Length > 0)) { props.Add(new DAL.RecognitionProperty("Tag", currentElement.TagName, 20)); ListViewItem item = selectedElementListView.Items.Add("Tag"); item.SubItems.Add(currentElement.TagName); item.SubItems.Add("20").Tag = 20; tag = currentElement.TagName; } if ((currentElement.OuterText != null) && (currentElement.OuterText.Length > 0)) { props.Add(new DAL.RecognitionProperty("OuterText", currentElement.OuterText, 20)); ListViewItem item = selectedElementListView.Items.Add("OuterText"); item.SubItems.Add(currentElement.OuterText); item.SubItems.Add("20").Tag = 20; } // add containing frame property if (currentElement.Document.Window.WindowFrameElement != null) { props.Add(new DAL.RecognitionProperty("FrameContainer", currentElement.Document.Window.WindowFrameElement.Name, 20)); ListViewItem xitem = selectedElementListView.Items.Add("FrameContainer"); xitem.SubItems.Add(currentElement.Document.Window.WindowFrameElement.Name); xitem.SubItems.Add("20").Tag = 20; } if ((currentElement.InnerText != null) && (currentElement.InnerText.Length > 0)) { props.Add(new DAL.RecognitionProperty("InnerText", currentElement.InnerText, 20)); ListViewItem item = selectedElementListView.Items.Add("InnerText"); item.SubItems.Add(currentElement.InnerText); item.SubItems.Add("20").Tag = 20; } foreach (mshtml.IHTMLDOMAttribute2 att in attribs) { if (((mshtml.IHTMLDOMAttribute)att).specified) { props.Add(new DAL.RecognitionProperty(att.name, att.value, 10)); ListViewItem item = selectedElementListView.Items.Add(att.name); item.SubItems.Add(att.value); if (string.Compare(att.name, "name", true) == 0) { item.SubItems.Add("50").Tag = 50; } else if (string.Compare(att.name, "id", true) == 0) { item.SubItems.Add("100").Tag = 100; } else if (string.Compare(att.name, "href", true) == 0) { item.SubItems.Add("45").Tag = 45; } else { item.SubItems.Add("10").Tag = 10; } if (string.Compare(att.name, "type", true) == 0) { type = att.value; } } } /** * if element has no id/name * 1. determined position in parent children by counting the depth of nextSibling loop * 2. push count to stack * 3. then check if parent have id attribute: if true then push id to stack else if parent=null stop else repeat 1-3 * 4. serialize stack content and create a fake attribute: indirectPath => [stack contents] with the format * <id:<id>|<name:<name>> <children indexes seperated by space> */ if ((currentElement.Name == "") && (currentElement.Id == null)) { //int position = -1; StringBuilder stack = new StringBuilder(); var elm = currentElement; do { if (elm.Parent != null) { for (var i = 0; i < elm.Parent.Children.Count; i++) { if (elm.Parent.Children[i].Equals(elm)) { stack.Insert(0, i.ToString() + " "); break; } } elm = elm.Parent; } else { break; } } while ((elm != null) && (elm.Id == null) && (elm.Name == "")); if ((elm != null) && (elm.Id != null)) { stack.Insert(0, "id:" + elm.Id + " "); } else if ((elm != null) && (elm.Name != "")) { stack.Insert(0, "name:" + elm.Name + " "); } //MessageBox.Show(stack.ToString().TrimEnd(' ')); if (stack[0] > '9') { props.Add(new DAL.RecognitionProperty("indirectPath", stack.ToString().TrimEnd(' '), 80)); ListViewItem item = selectedElementListView.Items.Add("indirectPath"); item.SubItems.Add(stack.ToString().TrimEnd(' ')); item.SubItems.Add("80").Tag = 80; } } if (string.Compare(tag, "input", true) == 0) { this.currentElementType = type == "" ? DAL.ElementType.TEXT : DAL.StringToElementType(type); } else if (string.Compare(tag, "textarea", true) == 0) { this.currentElementType = DAL.ElementType.AREA; } else if (string.Compare(tag, "select", true) == 0) { this.currentElementType = DAL.ElementType.SELECT; } else { this.currentElementType = DAL.ElementType.NONE; } }